3 # Copyright 2007 Foundations Bible College.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use Test::More tests => 27;
28 use_ok('C4::Labels::Profile');
31 my $expected_profile = {
33 printer_name => 'Circulation Desk',
35 paper_bin => 'bypass',
45 diag "Testing Profile->new() method.";
46 ok(my $profile = C4::Labels::Profile->new(printer_name => 'Circulation Desk',paper_bin => 'bypass')) || diag"Profile->new() FAILED.";
47 is_deeply($profile, $expected_profile) || diag "New profile object FAILED to verify.";
49 diag "Testing Profile->get_attr() method.";
50 foreach my $key (keys %{$expected_profile}) {
51 ok($expected_profile->{$key} eq $profile->get_attr($key)) || diag "Profile->get_attr() FAILED on attribute $key.";
54 diag "Testing Profile->set_attr() method.";
56 printer_name => 'Cataloging Desk',
58 paper_bin => 'tray 1',
67 foreach my $key (keys %{$new_attr}) {
68 $err = $profile->set_attr($key, $new_attr->{$key});
69 ok(($new_attr->{$key} eq $profile->get_attr($key)) && ($err lt 1)) || diag "Profile->set_attr() FAILED on attribute $key.";
72 diag "Testing Profile->save() method with a new object.";
74 my $sav_results = $profile->save();
75 ok($sav_results ne -1) || diag "Profile->save() FAILED.";
78 if ($sav_results ne -1) {
79 diag "Testing Profile->retrieve() method.";
80 $new_attr->{'profile_id'} = $sav_results;
81 ok($saved_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results)) || diag "Profile->retrieve() FAILED.";
82 is_deeply($saved_profile, $new_attr) || diag "Retrieved profile object FAILED to verify.";
85 diag "Testing Profile->save() method with an updated object.";
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)) || diag "Profile->save() FAILED.";
91 my $updated_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results);
92 is_deeply($updated_profile, $saved_profile) || diag "Updated layout object FAILED to verify.";
94 diag "Testing Profile->delete() method.";
96 my $del_results = $updated_profile->delete();
97 ok($del_results ne -1) || diag "Profile->delete() FAILED.";