Bug 11023: Automatic item modification by age (Was Toggle "new" status")
[koha.git] / t / db_dependent / Labels / t_Profile.t
1 #!/usr/bin/perl
2 #
3 # Copyright 2007 Foundations Bible College.
4 #
5 # This file is part of Koha.
6 #       
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Test::More tests => 27;
23 use C4::Context;
24
25 BEGIN {
26     use_ok('C4::Labels::Profile');
27 }
28
29 my $expected_profile = {
30         creator         => 'Labels',
31         printer_name    => 'Circulation Desk',
32         template_id     => '',
33         paper_bin       => 'bypass',
34         offset_horz     => 0,
35         offset_vert     => 0,
36         creep_horz      => 0,
37         creep_vert      => 0,
38         units           => 'POINT',
39 };
40
41 my $err = 0;
42
43 # Testing Profile->new()
44 ok(my $profile = C4::Labels::Profile->new(printer_name => 'Circulation Desk',paper_bin => 'bypass'), "Profile->new() success");
45 is_deeply($profile, $expected_profile, "New profile object verify success");
46
47 # Testing Profile->get_attr()
48 foreach my $key (keys %{$expected_profile}) {
49     ok($expected_profile->{$key} eq $profile->get_attr($key),
50         "Profile->get_attr() success on attribute $key");
51 }
52
53 # Testing Profile->set_attr()
54 my $new_attr = {
55     printer_name    => 'Cataloging Desk',
56     template_id     => '1',
57     paper_bin       => 'tray 1',
58     offset_horz     => 0.3,
59     offset_vert     => 0.85,
60     creep_horz      => 0.156,
61     creep_vert      => 0.67,
62     units           => 'INCH',
63     creator         => 'Labels',
64 };
65
66 foreach my $key (keys %{$new_attr}) {
67     $err = $profile->set_attr($key, $new_attr->{$key});
68     ok(($new_attr->{$key} eq $profile->get_attr($key)) && ($err lt 1),
69         "Profile->set_attr() success on attribute $key");
70 }
71
72 # Testing Profile->save()with a new object
73 my $sav_results = $profile->save();
74 ok($sav_results ne -1, "Profile->save() success");
75
76 my $saved_profile;
77 if ($sav_results ne -1) {
78     # Testing Profile->retrieve()
79     $new_attr->{'profile_id'} = $sav_results;
80     ok($saved_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results),
81        "Profile->retrieve() success");
82     is_deeply($saved_profile, $new_attr, "Retrieved profile object verify success");
83 }
84
85 # Testing Profile->save() with an updated object
86
87 $err = 0; # Reset error code
88 $err = $saved_profile->set_attr(units => 'CM');
89 my $upd_results = $saved_profile->save();
90 ok(($upd_results ne -1) && ($err lt 1), "Profile->save() success");
91 my $updated_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results);
92 is_deeply($updated_profile, $saved_profile, "Updated layout object verify success");
93
94 # Testing Profile->delete()
95 my $del_results = $updated_profile->delete();
96 ok($del_results ne -1, "Profile->delete() success");
97
98 1;