Lines 17-28
Link Here
|
17 |
# You should have received a copy of the GNU General Public License |
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>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
19 |
|
20 |
use strict; |
20 |
use Modern::Perl; |
21 |
use warnings; |
|
|
22 |
|
21 |
|
23 |
use Test::More tests => 54; |
22 |
use Test::More tests => 54; |
24 |
use C4::Context; |
23 |
use C4::Context; |
25 |
use Data::Dumper; |
|
|
26 |
|
24 |
|
27 |
BEGIN { |
25 |
BEGIN { |
28 |
use_ok('C4::Labels::Template'); |
26 |
use_ok('C4::Labels::Template'); |
Lines 51-66
my $expect_template = {
Link Here
|
51 |
|
49 |
|
52 |
my $template; |
50 |
my $template; |
53 |
|
51 |
|
54 |
diag "Testing Template->new() method."; |
52 |
# Testing Template->new() |
55 |
ok($template = C4::Labels::Template->new(page_width => 8.5,cols => 3)) || diag "Template->new() FAILED."; |
53 |
ok($template = C4::Labels::Template->new(page_width => 8.5,cols => 3), |
56 |
is_deeply($template, $expect_template) || diag "New template object FAILED to verify."; |
54 |
"Template->new() success."); |
|
|
55 |
is_deeply($template, $expect_template, "New template object verify success"); |
57 |
|
56 |
|
58 |
diag "Testing Template->get_attr() method."; |
57 |
# Testing Template->get_attr() |
59 |
foreach my $key (keys %{$expect_template}) { |
58 |
foreach my $key (keys %{$expect_template}) { |
60 |
ok($expect_template->{$key} eq $template->get_attr($key)) || diag "Template->get_attr() FAILED on attribute $key."; |
59 |
ok($expect_template->{$key} eq $template->get_attr($key), |
|
|
60 |
"Template->get_attr() success on attribute $key"); |
61 |
} |
61 |
} |
62 |
|
62 |
|
63 |
diag "Testing Template->set_attr() method."; |
63 |
# Testing Template->set_attr() |
64 |
my $new_attr = { |
64 |
my $new_attr = { |
65 |
creator => 'Labels', |
65 |
creator => 'Labels', |
66 |
profile_id => 0, |
66 |
profile_id => 0, |
Lines 85-116
my $new_attr = {
Link Here
|
85 |
foreach my $key (keys %{$new_attr}) { |
85 |
foreach my $key (keys %{$new_attr}) { |
86 |
next if ($key eq 'template_stat'); |
86 |
next if ($key eq 'template_stat'); |
87 |
$template->set_attr($key, $new_attr->{$key}); |
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."; |
88 |
ok($new_attr->{$key} eq $template->get_attr($key), |
|
|
89 |
"Template->set_attr() success on attribute $key"); |
89 |
} |
90 |
} |
90 |
|
91 |
|
91 |
diag "Testing Template->save() method with a new object."; |
92 |
# Testing Template->save() with a new object |
92 |
|
|
|
93 |
my $sav_results = $template->save(); |
93 |
my $sav_results = $template->save(); |
94 |
ok($sav_results ne -1) || diag "Template->save() FAILED."; |
94 |
ok($sav_results ne -1, "Template->save() success"); |
95 |
|
95 |
|
96 |
my $saved_template; |
96 |
my $saved_template; |
97 |
if ($sav_results ne -1) { |
97 |
if ($sav_results ne -1) { |
98 |
diag "Testing Template->retrieve() method."; |
98 |
# Testing Template->retrieve() |
99 |
$new_attr->{'template_id'} = $sav_results; |
99 |
$new_attr->{'template_id'} = $sav_results; |
100 |
ok($saved_template = C4::Labels::Template->retrieve(template_id => $sav_results)) || diag "Template->retrieve() FAILED."; |
100 |
ok($saved_template = C4::Labels::Template->retrieve(template_id => $sav_results), |
101 |
is_deeply($saved_template, $new_attr) || diag "Retrieved template object FAILED to verify."; |
101 |
"Template->retrieve() success"); |
|
|
102 |
is_deeply($saved_template, $new_attr, |
103 |
"Retrieved template object verify success"); |
102 |
} |
104 |
} |
103 |
|
105 |
|
104 |
diag "Testing Template->save method with an updated object."; |
106 |
# Testing Template->save with an updated object |
105 |
|
|
|
106 |
$saved_template->set_attr(template_desc => 'A test template'); |
107 |
$saved_template->set_attr(template_desc => 'A test template'); |
107 |
my $upd_results = $saved_template->save(); |
108 |
my $upd_results = $saved_template->save(); |
108 |
ok($upd_results ne -1) || diag "Template->save() FAILED."; |
109 |
ok($upd_results ne -1, "Template->save() success"); |
109 |
my $updated_template = C4::Labels::Template->retrieve(template_id => $sav_results); |
110 |
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."; |
111 |
is_deeply($updated_template, $saved_template, "Updated template object verify success"); |
111 |
|
|
|
112 |
diag "Testing Template->retrieve() convert points option."; |
113 |
|
112 |
|
|
|
113 |
# Testing Template->retrieve() convert points option |
114 |
my $conv_template = C4::Labels::Template->retrieve(template_id => $sav_results, convert => 1); |
114 |
my $conv_template = C4::Labels::Template->retrieve(template_id => $sav_results, convert => 1); |
115 |
my $expect_conv = { |
115 |
my $expect_conv = { |
116 |
page_width => 612, |
116 |
page_width => 612, |
Lines 126-135
my $expect_conv = {
Link Here
|
126 |
}; |
126 |
}; |
127 |
|
127 |
|
128 |
foreach my $key (keys %{$expect_conv}) { |
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) . "."; |
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) . "."); |
130 |
} |
132 |
} |
131 |
|
133 |
|
132 |
diag "Testing Template->delete() method."; |
134 |
# Testing Template->delete() |
133 |
|
|
|
134 |
my $del_results = $updated_template->delete(); |
135 |
my $del_results = $updated_template->delete(); |
135 |
ok($del_results ne -1) || diag "Template->delete() FAILED."; |
136 |
ok($del_results ne -1, "Template->delete() success"); |
|
|
137 |
|
138 |
1; |
136 |
- |
|
|