3 # This file is part of Koha.
5 # Copyright 2020 Koha Development team
6 # Copyright (C) 2017 Mark Tompsett
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Test::More tests => 6;
24 use t::lib::TestBuilder;
33 use C4::Labels::Layout;
37 use_ok('C4::Labels::Label');
39 my $database = Koha::Database->new();
40 my $schema = $database->schema();
41 $schema->storage->txn_begin();
44 my ( $llx, $lly ) = ( 0, 0 );
45 my $frameworkcode = q{};
48 my $builder = t::lib::TestBuilder->new;
51 my $branch_1 = $builder->build( { source => 'Branch' } )->{branchcode};
54 my $category_1 = $builder->build( { source => 'Category' } )->{categorycode};
57 my $itemtype = $builder->build( { source => 'Itemtype', value => { notforloan => 0 } } )->{itemtype};
59 t::lib::Mocks::mock_userenv( { branchcode => $branch_1 } );
61 my $bibnum = $builder->build_sample_biblio( { frameworkcode => $frameworkcode } )->biblionumber;
63 # Create a helper item instance for testing
64 my $item = $builder->build_sample_item(
68 biblionumber => $bibnum,
70 copynumber => "copynum"
73 my $itemnumber = $item->itemnumber;
75 # Modify item; setting barcode.
76 my $testbarcode = '97531';
77 $item->barcode($testbarcode)->store;
79 my $layout = C4::Labels::Layout->new( layout_name => 'TEST' );
81 my $dummy_template_values = {
84 template_code => 'Avery 5160 | 1 x 2-5/8',
85 template_desc => '3 columns, 10 rows of labels',
90 top_text_margin => 0.139,
91 left_text_margin => 0.0417,
100 barcode_width => 0.8,
101 barcode_height => 0.01
105 batch_id => $batch_id,
106 item_number => $item->itemnumber,
109 width => $dummy_template_values->{'label_width'},
110 height => $dummy_template_values->{'label_height'},
111 top_text_margin => $dummy_template_values->{'top_text_margin'},
112 left_text_margin => $dummy_template_values->{'left_text_margin'},
113 barcode_type => $layout->get_attr('barcode_type'),
114 printing_type => 'BIB',
115 guidebox => $layout->get_attr('guidebox'),
116 oblique_title => $layout->get_attr('oblique_title'),
117 font => $layout->get_attr('font'),
118 font_size => $layout->get_attr('font_size'),
119 callnum_split => $layout->get_attr('callnum_split'),
120 justify => $layout->get_attr('text_justify'),
121 text_wrap_cols => $layout->get_text_wrap_cols(
122 label_width => $dummy_template_values->{'label_width'},
123 left_text_margin => $dummy_template_values->{'left_text_margin'}
125 scale_width => $dummy_template_values->{barcode_width},
126 scale_height => $dummy_template_values->{barcode_height},
129 my $format_string = '100a 245a';
130 my $barcode_width = $label_info->{scale_width} * $label_info->{width};
131 my $barcode_height = $label_info->{scale_height} * $label_info->{height};
132 my $label = C4::Labels::Label->new( %$label_info, format_string => $format_string );
133 my $label_text = $label->create_label();
134 ok( defined $label_text, 'Label Text Value defined.' );
135 my $label_csv_data = $label->csv_data();
138 [ sprintf( "%s %s", $item->biblio->author, $item->biblio->title ) ]
141 $format_string = '100a 245a,enumchron copynumber';
142 $label = C4::Labels::Label->new( %$label_info, format_string => $format_string );
143 $label_csv_data = $label->csv_data();
147 sprintf( "%s %s", $item->biblio->author, $item->biblio->title ),
148 sprintf( "%s %s", $item->enumchron, $item->copynumber )
151 is( $barcode_width, '2.104', );
152 is( $barcode_height, '0.01', );
154 $schema->storage->txn_rollback();