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
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.
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.
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>.
22 use Test
::More tests
=> 54;
26 use_ok
('C4::Labels::Template');
29 my $expect_template = {
32 template_code
=> 'DEFAULT TEMPLATE',
33 template_desc
=> 'Default description',
39 left_text_margin
=> 0,
52 # Testing Template->new()
53 ok
($template = C4
::Labels
::Template
->new(page_width
=> 8.5,cols
=> 3),
54 "Template->new() success.");
55 is_deeply
($template, $expect_template, "New template object verify success");
57 # Testing Template->get_attr()
58 foreach my $key (keys %{$expect_template}) {
59 ok
($expect_template->{$key} eq $template->get_attr($key),
60 "Template->get_attr() success on attribute $key");
63 # Testing Template->set_attr()
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),
89 "Template->set_attr() success on attribute $key");
92 # Testing Template->save() with a new object
93 my $sav_results = $template->save();
94 ok
($sav_results ne -1, "Template->save() success");
97 if ($sav_results ne -1) {
98 # Testing Template->retrieve()
99 $new_attr->{'template_id'} = $sav_results;
100 ok
($saved_template = C4
::Labels
::Template
->retrieve(template_id
=> $sav_results),
101 "Template->retrieve() success");
102 is_deeply
($saved_template, $new_attr,
103 "Retrieved template object verify success");
106 # Testing Template->save with an updated object
107 $saved_template->set_attr(template_desc
=> 'A test template');
108 my $upd_results = $saved_template->save();
109 ok
($upd_results ne -1, "Template->save() success");
110 my $updated_template = C4
::Labels
::Template
->retrieve(template_id
=> $sav_results);
111 is_deeply
($updated_template, $saved_template, "Updated template object verify success");
113 # 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),
130 "Template->retrieve() convert points option success ($expect_conv->{$key})")
131 || diag
("Expected " . $expect_conv->{$key} . " but got " . $conv_template->get_attr($key) . ".");
134 # Testing Template->delete()
135 my $del_results = $updated_template->delete();
136 ok
($del_results ne -1, "Template->delete() success");