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 => 54;
28 use_ok('C4::Labels::Template');
31 my $expect_template = {
34 template_code => 'DEFAULT TEMPLATE',
35 template_desc => 'Default description',
41 left_text_margin => 0,
54 diag "Testing Template->new() method.";
55 ok($template = C4::Labels::Template->new(page_width => 8.5,cols => 3)) || diag "Template->new() FAILED.";
56 is_deeply($template, $expect_template) || diag "New template object FAILED to verify.";
58 diag "Testing Template->get_attr() method.";
59 foreach my $key (keys %{$expect_template}) {
60 ok($expect_template->{$key} eq $template->get_attr($key)) || diag "Template->get_attr() FAILED on attribute $key.";
63 diag "Testing Template->set_attr() method.";
67 template_code => 'Avery 5160 | 1 x 2-5/8',
68 template_desc => '3 columns, 10 rows of labels',
73 top_text_margin => 0.139,
74 left_text_margin => 0.0417,
85 foreach my $key (keys %{$new_attr}) {
86 next if ($key eq 'template_stat');
87 $template->set_attr($key, $new_attr->{$key});
88 ok($new_attr->{$key} eq $template->get_attr($key)) || diag "Template->set_attr() FAILED on attribute $key.";
91 diag "Testing Template->save() method with a new object.";
93 my $sav_results = $template->save();
94 ok($sav_results ne -1) || diag "Template->save() FAILED.";
97 if ($sav_results ne -1) {
98 diag "Testing Template->retrieve() method.";
99 $new_attr->{'template_id'} = $sav_results;
100 ok($saved_template = C4::Labels::Template->retrieve(template_id => $sav_results)) || diag "Template->retrieve() FAILED.";
101 is_deeply($saved_template, $new_attr) || diag "Retrieved template object FAILED to verify.";
104 diag "Testing Template->save method with an updated object.";
106 $saved_template->set_attr(template_desc => 'A test template');
107 my $upd_results = $saved_template->save();
108 ok($upd_results ne -1) || diag "Template->save() FAILED.";
109 my $updated_template = C4::Labels::Template->retrieve(template_id => $sav_results);
110 is_deeply($updated_template, $saved_template) || diag "Updated template object FAILED to verify.";
112 diag "Testing Template->retrieve() convert points option.";
114 my $conv_template = C4::Labels::Template->retrieve(template_id => $sav_results, convert => 1);
118 label_width => 189.36,
120 top_text_margin => 10.008,
121 left_text_margin => 3.0024,
123 left_margin => 16.56,
128 foreach my $key (keys %{$expect_conv}) {
129 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) . ".";
132 diag "Testing Template->delete() method.";
134 my $del_results = $updated_template->delete();
135 ok($del_results ne -1) || diag "Template->delete() FAILED.";