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 => 52;
28 use_ok('C4::Labels::Template');
31 my $expect_template = {
33 template_code => 'DEFAULT TEMPLATE',
34 template_desc => 'Default description',
40 left_text_margin => 0,
53 diag "Testing Template->new() method.";
54 ok($template = C4::Labels::Template->new(page_width => 8.5,cols => 3)) || diag "Template->new() FAILED. Check syslog for details.";
55 is_deeply($template, $expect_template) || diag "New template object FAILED to verify.";
57 diag "Testing Template->get_attr() method.";
58 foreach my $key (keys %{$expect_template}) {
59 ok($expect_template->{$key} eq $template->get_attr($key)) || diag "Template->get_attr() FAILED on attribute $key.";
62 diag "Testing Template->set_attr() method.";
65 template_code => 'Avery 5160 | 1 x 2-5/8',
66 template_desc => '3 columns, 10 rows of labels',
71 top_text_margin => 0.139,
72 left_text_margin => 0.0417,
83 foreach my $key (keys %{$new_attr}) {
84 next if ($key eq 'template_stat');
85 $template->set_attr($key, $new_attr->{$key});
86 ok($new_attr->{$key} eq $template->get_attr($key)) || diag "Template->set_attr() FAILED on attribute $key.";
89 diag "Testing Template->save() method with a new object.";
91 my $sav_results = $template->save();
92 ok($sav_results ne -1) || diag "Template->save() FAILED. See syslog for details.";
95 if ($sav_results ne -1) {
96 diag "Testing Template->retrieve() method.";
97 $new_attr->{'template_id'} = $sav_results;
98 ok($saved_template = C4::Labels::Template->retrieve(template_id => $sav_results)) || diag "Template->retrieve() FAILED. Check syslog for details.";
99 is_deeply($saved_template, $new_attr) || diag "Retrieved template object FAILED to verify.";
102 diag "Testing Template->save method with an updated object.";
104 $saved_template->set_attr(template_desc => 'A test template');
105 my $upd_results = $saved_template->save();
106 ok($upd_results ne -1) || diag "Template->save() FAILED. See syslog for details.";
107 my $updated_template = C4::Labels::Template->retrieve(template_id => $sav_results);
108 is_deeply($updated_template, $saved_template) || diag "Updated template object FAILED to verify.";
110 diag "Testing Template->retrieve() convert points option.";
112 my $conv_template = C4::Labels::Template->retrieve(template_id => $sav_results, convert => 1);
116 label_width => 189.36,
118 top_text_margin => 10.008,
119 left_text_margin => 3.0024,
121 left_margin => 16.56,
126 foreach my $key (keys %{$expect_conv}) {
127 ok($expect_conv->{$key} eq $conv_template->get_attr($key)) || diag "Template->retrieve() convert points option FAILED. Expected " . $expect_conv->{$key} . " but got " . $conv_template->get_attr($key) . ".";
130 diag "Testing Template->delete() method.";
132 my $del_results = $updated_template->delete();
133 ok($del_results ne -1) || diag "Template->delete() FAILED. See syslog for details.";