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
=> 38;
26 use_ok
('C4::Labels::Layout');
29 my $default_layout = {
34 barcode_type
=> 'CODE39',
35 printing_type
=> 'BAR',
36 layout_name
=> 'TEST',
43 format_string
=> 'title, author, isbn, issn, itemtype, barcode, itemcallnumber',
48 # Testing Layout->new()
49 ok
($layout = C4
::Labels
::Layout
->new(layout_name
=> 'TEST'), "Layout->new() success");
50 is_deeply
($layout, $default_layout, "New layout object is the expected");
52 # Testing Layout->get_attr()
53 foreach my $key (keys %{$default_layout}) {
54 ok
($default_layout->{$key} eq $layout->get_attr($key),
55 "Layout->get_attr() success on attribute $key.");
58 # Testing Layout->set_attr()
64 barcode_type
=> 'CODE39',
65 printing_type
=> 'BIBBAR',
66 layout_name
=> 'TEST',
73 format_string
=> 'callnumber, title, author, barcode',
76 foreach my $key (keys %{$new_attr}) {
77 $layout->set_attr($key => $new_attr->{$key});
78 ok
($new_attr->{$key} eq $layout->get_attr($key),
79 "Layout->set_attr() success on attribute $key.");
83 # Testing Layout->save() method with a new object
84 my $sav_results = $layout->save();
85 ok
($sav_results ne -1, "Layout->save() success");
88 if ($sav_results ne -1) {
89 # Testing Layout->retrieve()
90 $new_attr->{'layout_id'} = $sav_results;
91 ok
($saved_layout = C4
::Labels
::Layout
->retrieve(layout_id
=> $sav_results),
92 "Layout->retrieve() success");
93 is_deeply
($saved_layout, $new_attr,
94 "Retrieved layout object is the expected");
97 # Testing Layout->save() method with an updated object
98 $saved_layout->set_attr(font
=> 'C');
99 my $upd_results = $saved_layout->save();
100 ok
($upd_results ne -1, "Layout->save() success");
101 my $updated_layout = C4
::Labels
::Layout
->retrieve(layout_id
=> $sav_results);
102 is_deeply
($updated_layout, $saved_layout, "Updated layout object is the expected");
104 # Testing Layout->get_text_wrap_cols()
105 is
($updated_layout->get_text_wrap_cols(label_width
=> 180, left_text_margin
=> 18), 21,
106 "Layout->get_text_wrap_cols()");
108 # Testing Layout->delete()
109 my $del_results = $updated_layout->delete();
110 ok
( ! defined($del_results) , "Layout->delete() success");