Bug 24146: Add test cases
[koha.git] / t / db_dependent / Labels / t_Layout.t
blob54be026ba703b0808d57a78e34eb1e0bf327dbe3
1 #!/usr/bin/perl
3 # Copyright 2007 Foundations Bible College.
5 # This file is part of Koha.
6 #
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>.
20 use Modern::Perl;
22 use Test::More tests => 38;
23 use C4::Context;
25 BEGIN {
26 use_ok('C4::Labels::Layout');
29 my $default_layout = {
30 creator => 'Labels',
31 layout_xml => '',
32 units => 'POINT',
33 start_label => 1,
34 barcode_type => 'CODE39',
35 printing_type => 'BAR',
36 layout_name => 'TEST',
37 guidebox => 0,
38 oblique_title => 1,
39 font => 'TR',
40 font_size => 3,
41 callnum_split => 0,
42 text_justify => 'L',
43 format_string => 'title, author, isbn, issn, itemtype, barcode, itemcallnumber',
46 my $layout;
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()
59 my $new_attr = {
60 creator => 'Labels',
61 layout_xml => '',
62 units => 'POINT',
63 start_label => 1,
64 barcode_type => 'CODE39',
65 printing_type => 'BIBBAR',
66 layout_name => 'TEST',
67 guidebox => 1,
68 oblique_title => 0,
69 font => 'TR',
70 font_size => 10,
71 callnum_split => 1,
72 text_justify => 'L',
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");
87 my $saved_layout;
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");