replace syslog with warns
[koha.git] / t / db_dependent / Labels / t_Layout.t
1 #!/usr/bin/perl
2 #
3 # Copyright 2007 Foundations Bible College.
4 #
5 # This file is part of Koha.
6 #       
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
10 # version.
11 #
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.
15 #
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
19
20 use strict;
21 use warnings;
22
23 use Test::More tests => 28;
24 use C4::Context;
25 use Data::Dumper;
26
27 BEGIN {
28     use_ok('C4::Labels::Layout');
29 }
30
31 my $default_layout = {
32         barcode_type    =>      'CODE39',
33         printing_type   =>      'BAR',
34         layout_name     =>      'TEST',
35         guidebox        =>      0,
36         font            =>      'TR',
37         font_size       =>      3,
38         callnum_split   =>      0,
39         text_justify    =>      'L',
40         format_string   =>      'title, author, isbn, issn, itemtype, barcode, callnumber',
41     };
42
43 my $layout;
44
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.";
48
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.";
52 }
53
54 diag "Testing Layout->set_attr() method.";
55 my $new_attr = {
56         barcode_type    =>      'CODE39',
57         printing_type   =>      'BIBBAR',
58         layout_name     =>      'TEST',
59         guidebox        =>      1,
60         font            =>      'TR',
61         font_size       =>      10,
62         callnum_split   =>      1,
63         text_justify    =>      'L',
64         format_string   =>      'callnumber, title, author, barcode',
65     };
66
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.";
70 }
71
72 diag "Testing Layout->save() method with a new object.";
73
74 my $sav_results = $layout->save();
75 ok($sav_results ne -1) || diag "Layout->save() FAILED";
76
77 my $saved_layout;
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.";
83 }
84
85 diag "Testing Layout->save() method with an updated object.";
86
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.";
92
93 diag "Testing Layout->get_text_wrap_cols() method.";
94
95 ok($updated_layout->get_text_wrap_cols(label_width => 180, left_text_margin => 18) eq 21) || diag "Layout->get_text_wrap_cols() FAILED.";
96
97 diag "Testing Layout->delete() method.";
98
99 my $del_results = $updated_layout->delete();
100 ok($del_results eq 0) || diag "Layout->delete() FAILED";