Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Copyright (C) 2017 Mark Tompsett |
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. |
11 |
# |
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. |
16 |
# |
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>. |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 3; |
23 |
use t::lib::TestBuilder; |
24 |
|
25 |
use MARC::Record; |
26 |
use MARC::Field; |
27 |
use Data::Dumper; |
28 |
|
29 |
use C4::Biblio; |
30 |
use C4::Items; |
31 |
use C4::Labels::Layout; |
32 |
|
33 |
use Koha::Database; |
34 |
|
35 |
use_ok('C4::Labels::Label'); |
36 |
|
37 |
my $database = Koha::Database->new(); |
38 |
my $schema = $database->schema(); |
39 |
$schema->storage->txn_begin(); |
40 |
|
41 |
my $batch_id; |
42 |
my ( $llx, $lly ) = ( 0, 0 ); |
43 |
my $frameworkcode = q{}; |
44 |
|
45 |
## Setup Test |
46 |
my $builder = t::lib::TestBuilder->new; |
47 |
|
48 |
# Add branch |
49 |
my $branch_1 = $builder->build( { source => 'Branch' } )->{branchcode}; |
50 |
|
51 |
# Add categories |
52 |
my $category_1 = $builder->build( { source => 'Category' } )->{categorycode}; |
53 |
|
54 |
# Add an item type |
55 |
my $itemtype = |
56 |
$builder->build( { source => 'Itemtype', value => { notforloan => undef } } ) |
57 |
->{itemtype}; |
58 |
|
59 |
C4::Context->set_userenv( undef, undef, undef, undef, undef, undef, $branch_1 ); |
60 |
|
61 |
# Create a helper biblio |
62 |
my $bib = MARC::Record->new(); |
63 |
my $title = 'Silence in the library'; |
64 |
if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { |
65 |
$bib->append_fields( |
66 |
MARC::Field->new( '600', q{}, '1', a => 'Moffat, Steven' ), |
67 |
MARC::Field->new( '200', q{}, q{}, a => $title ), |
68 |
); |
69 |
} |
70 |
else { |
71 |
$bib->append_fields( |
72 |
MARC::Field->new( '100', q{}, q{}, a => 'Moffat, Steven' ), |
73 |
MARC::Field->new( '245', q{}, q{}, a => $title ), |
74 |
); |
75 |
} |
76 |
my ($bibnum) = AddBiblio( $bib, $frameworkcode ); |
77 |
|
78 |
# Create a helper item instance for testing |
79 |
my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem( |
80 |
{ |
81 |
homebranch => $branch_1, |
82 |
holdingbranch => $branch_1, |
83 |
itype => $itemtype |
84 |
}, |
85 |
$bibnum |
86 |
); |
87 |
|
88 |
# Modify item; setting barcode. |
89 |
my $testbarcode = '97531'; |
90 |
ModItem( { barcode => $testbarcode }, $bibnum, $itemnumber ); |
91 |
|
92 |
my $layout = C4::Labels::Layout->new( layout_name => 'TEST' ); |
93 |
|
94 |
my $dummy_template_values = { |
95 |
creator => 'Labels', |
96 |
profile_id => 0, |
97 |
template_code => 'Avery 5160 | 1 x 2-5/8', |
98 |
template_desc => '3 columns, 10 rows of labels', |
99 |
page_width => 8.5, |
100 |
page_height => 11, |
101 |
label_width => 2.63, |
102 |
label_height => 1, |
103 |
top_text_margin => 0.139, |
104 |
left_text_margin => 0.0417, |
105 |
top_margin => 0.35, |
106 |
left_margin => 0.23, |
107 |
cols => 3, |
108 |
rows => 10, |
109 |
col_gap => 0.13, |
110 |
row_gap => 0, |
111 |
units => 'INCH', |
112 |
template_stat => 1, |
113 |
}; |
114 |
|
115 |
my $label = C4::Labels::Label->new( |
116 |
batch_id => $batch_id, |
117 |
item_number => $itemnumber, |
118 |
llx => $llx, |
119 |
lly => $lly, |
120 |
width => $dummy_template_values->{'label_width'}, |
121 |
height => $dummy_template_values->{'label_height'}, |
122 |
top_text_margin => $dummy_template_values->{'top_text_margin'}, |
123 |
left_text_margin => $dummy_template_values->{'left_text_margin'}, |
124 |
barcode_type => $layout->get_attr('barcode_type'), |
125 |
printing_type => 'BIB', |
126 |
guidebox => $layout->get_attr('guidebox'), |
127 |
oblique_title => $layout->get_attr('oblique_title'), |
128 |
font => $layout->get_attr('font'), |
129 |
font_size => $layout->get_attr('font_size'), |
130 |
callnum_split => $layout->get_attr('callnum_split'), |
131 |
justify => $layout->get_attr('text_justify'), |
132 |
format_string => $layout->get_attr('format_string'), |
133 |
text_wrap_cols => $layout->get_text_wrap_cols( |
134 |
label_width => $dummy_template_values->{'label_width'}, |
135 |
left_text_margin => $dummy_template_values->{'left_text_margin'} |
136 |
), |
137 |
); |
138 |
|
139 |
my $label_text = $label->create_label(); |
140 |
ok( defined $label_text, 'Label Text Value defined.' ); |
141 |
|
142 |
my $label_csv_data = $label->csv_data(); |
143 |
ok( defined $label_csv_data, 'Label CSV Data defined' ); |
144 |
|
145 |
$schema->storage->txn_rollback(); |
146 |
|
147 |
1; |