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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 use Test::More tests => 28;
28 use_ok('C4::Labels::Layout');
31 my $default_layout = {
32 barcode_type => 'CODE39',
33 printing_type => 'BAR',
34 layout_name => 'TEST',
40 format_string => 'title, author, isbn, issn, itemtype, barcode, callnumber',
45 diag "Testing Layout->new() method.";
46 ok($layout = C4::Labels::Layout->new(layout_name => 'TEST')) || diag "Layout->new() FAILED";
47 is_deeply($layout, $default_layout) || diag "New layout object FAILED to verify.";
49 diag "Testing Layout->get_attr() method.";
50 foreach my $key (keys %{$default_layout}) {
51 ok($default_layout->{$key} eq $layout->get_attr($key)) || diag "Layout->get_attr() FAILED on attribute $key.";
54 diag "Testing Layout->set_attr() method.";
56 barcode_type => 'CODE39',
57 printing_type => 'BIBBAR',
58 layout_name => 'TEST',
64 format_string => 'callnumber, title, author, barcode',
67 foreach my $key (keys %{$new_attr}) {
68 $layout->set_attr($key => $new_attr->{$key});
69 ok($new_attr->{$key} eq $layout->get_attr($key)) || diag "Layout->set_attr() FAILED on attribute $key.";
72 diag "Testing Layout->save() method with a new object.";
74 my $sav_results = $layout->save();
75 ok($sav_results ne -1) || diag "Layout->save() FAILED";
78 if ($sav_results ne -1) {
79 diag "Testing Layout->retrieve() method.";
80 $new_attr->{'layout_id'} = $sav_results;
81 ok($saved_layout = C4::Labels::Layout->retrieve(layout_id => $sav_results)) || diag "Layout->retrieve() FAILED";
82 is_deeply($saved_layout, $new_attr) || diag "Retrieved layout object FAILED to verify.";
85 diag "Testing Layout->save() method with an updated object.";
87 $saved_layout->set_attr(font => 'C');
88 my $upd_results = $saved_layout->save();
89 ok($upd_results ne -1) || diag "Layout->save() FAILED";
90 my $updated_layout = C4::Labels::Layout->retrieve(layout_id => $sav_results);
91 is_deeply($updated_layout, $saved_layout) || diag "Updated layout object FAILED to verify.";
93 diag "Testing Layout->get_text_wrap_cols() method.";
95 ok($updated_layout->get_text_wrap_cols(label_width => 180, left_text_margin => 18) eq 21) || diag "Layout->get_text_wrap_cols() FAILED.";
97 diag "Testing Layout->delete() method.";
99 my $del_results = $updated_layout->delete();
100 ok($del_results eq 0) || diag "Layout->delete() FAILED";