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 => 36;
28 use_ok('C4::Labels::Layout');
31 my $default_layout = {
36 barcode_type => 'CODE39',
37 printing_type => 'BAR',
38 layout_name => 'TEST',
44 format_string => 'title, author, isbn, issn, itemtype, barcode, itemcallnumber',
49 diag "Testing Layout->new() method.";
50 ok($layout = C4::Labels::Layout->new(layout_name => 'TEST')) || diag "Layout->new() FAILED";
51 is_deeply($layout, $default_layout) || diag "New layout object FAILED to verify.";
53 diag "Testing Layout->get_attr() method.";
54 foreach my $key (keys %{$default_layout}) {
55 ok($default_layout->{$key} eq $layout->get_attr($key)) || diag "Layout->get_attr() FAILED on attribute $key.";
58 diag "Testing Layout->set_attr() method.";
64 barcode_type => 'CODE39',
65 printing_type => 'BIBBAR',
66 layout_name => 'TEST',
72 format_string => 'callnumber, title, author, barcode',
75 foreach my $key (keys %{$new_attr}) {
76 $layout->set_attr($key => $new_attr->{$key});
77 ok($new_attr->{$key} eq $layout->get_attr($key)) || diag "Layout->set_attr() FAILED on attribute $key.";
80 diag "Testing Layout->save() method with a new object.";
82 my $sav_results = $layout->save();
83 ok($sav_results ne -1) || diag "Layout->save() FAILED";
86 if ($sav_results ne -1) {
87 diag "Testing Layout->retrieve() method.";
88 $new_attr->{'layout_id'} = $sav_results;
89 ok($saved_layout = C4::Labels::Layout->retrieve(layout_id => $sav_results)) || diag "Layout->retrieve() FAILED";
90 is_deeply($saved_layout, $new_attr) || diag "Retrieved layout object FAILED to verify.";
93 diag "Testing Layout->save() method with an updated object.";
95 $saved_layout->set_attr(font => 'C');
96 my $upd_results = $saved_layout->save();
97 ok($upd_results ne -1) || diag "Layout->save() FAILED";
98 my $updated_layout = C4::Labels::Layout->retrieve(layout_id => $sav_results);
99 is_deeply($updated_layout, $saved_layout) || diag "Updated layout object FAILED to verify.";
101 diag "Testing Layout->get_text_wrap_cols() method.";
103 ok($updated_layout->get_text_wrap_cols(label_width => 180, left_text_margin => 18) eq 21) || diag "Layout->get_text_wrap_cols() FAILED.";
105 diag "Testing Layout->delete() method.";
107 my $del_results = $updated_layout->delete();
108 ok($del_results ne -1) || diag "Layout->delete() FAILED";