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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 use Test::More tests => 25;
28 use_ok('C4::Labels::Profile');
31 my $expected_profile = {
32 printer_name => 'Circulation Desk',
34 paper_bin => 'bypass',
44 diag "Testing Profile->new() method.";
45 ok(my $profile = C4::Labels::Profile->new(printer_name => 'Circulation Desk',paper_bin => 'bypass')) || diag"Profile->new() FAILED.";
46 is_deeply($profile, $expected_profile) || diag "New profile object FAILED to verify.";
48 diag "Testing Profile->get_attr() method.";
49 foreach my $key (keys %{$expected_profile}) {
50 ok($expected_profile->{$key} eq $profile->get_attr($key)) || diag "Profile->get_attr() FAILED on attribute $key.";
53 diag "Testing Profile->set_attr() method.";
55 printer_name => 'Cataloging Desk',
57 paper_bin => 'tray 1',
65 foreach my $key (keys %{$new_attr}) {
66 $err = $profile->set_attr($key, $new_attr->{$key});
67 ok(($new_attr->{$key} eq $profile->get_attr($key)) && ($err lt 1)) || diag "Profile->set_attr() FAILED on attribute $key.";
70 diag "Testing Profile->save() method with a new object.";
72 my $sav_results = $profile->save();
73 ok($sav_results ne -1) || diag "Profile->save() FAILED.";
76 if ($sav_results ne -1) {
77 diag "Testing Profile->retrieve() method.";
78 $new_attr->{'profile_id'} = $sav_results;
79 ok($saved_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results)) || diag "Profile->retrieve() FAILED.";
80 is_deeply($saved_profile, $new_attr) || diag "Retrieved profile object FAILED to verify.";
83 diag "Testing Profile->save() method with an updated object.";
85 $err = 0; # Reset error code
86 $err = $saved_profile->set_attr(units => 'CM');
87 my $upd_results = $saved_profile->save();
88 ok(($upd_results ne -1) && ($err lt 1)) || diag "Profile->save() FAILED.";
89 my $updated_profile = C4::Labels::Profile->retrieve(profile_id => $sav_results);
90 is_deeply($updated_profile, $saved_profile) || diag "Updated layout object FAILED to verify.";
92 diag "Testing Profile->delete() method.";
94 my $del_results = $updated_profile->delete();
95 ok($del_results ne -1) || diag "Profile->delete() FAILED.";