3 # Copyright 2015 BibLibre
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 3 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
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Test
::More tests
=> 647;
24 use t
::lib
::TestBuilder
;
29 use_ok
('C4::Creators::Lib');
31 use_ok
('C4::Context');
32 use_ok
('Koha::Patron');
33 use_ok
('MARC::Record');
37 'C4::Creators::Lib', qw(
48 get_text_justification_types
55 my $schema = Koha
::Database
->schema;
56 $schema->storage->txn_begin;
57 my $builder = t
::lib
::TestBuilder
->new;
59 my $dbh = C4
::Context
->dbh;
60 $dbh->do('DELETE FROM issues');
61 $dbh->do('DELETE FROM creator_templates');
62 $dbh->do('DELETE FROM creator_layouts');
63 $dbh->do('DELETE FROM creator_images');
64 $dbh->do('DELETE FROM creator_batches');
65 $dbh->do('DELETE FROM printers_profile');
66 $dbh->do('DELETE FROM borrowers');
67 $dbh->do('DELETE FROM items');
68 $dbh->do('DELETE FROM biblioitems');
70 ###########################################################
72 ###########################################################
74 my $library1 = $builder->build({
77 my $library2 = $builder->build({
80 my $library3 = $builder->build({
84 # ---------- Some Templates --------------------
86 INSERT INTO creator_templates
87 (profile_id , template_code, template_desc, page_width,
88 page_height , label_width , label_height , top_text_margin,
89 left_text_margin, top_margin , left_margin , cols,
90 `rows` , col_gap , row_gap , units,
92 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
93 my $insert_sth = $dbh->prepare($query);
94 $insert_sth->execute( 1, 'TEMPL1', 'Template 1', 100, 150, 10, 15, 2, 3, 1, 4, 9, 6, 0.1, 0.2, 'POINT', 'Labels' );
96 $insert_sth->execute( 2, 'TEMPL2', 'Template 2', 101, 151, 11, 16, 3, 4, 2, 5, 10, 7, 0.2, 0.3, 'POINT', 'Labels' );
98 SELECT template_id, template_code
99 FROM creator_templates
102 my ( $template_id1, $template_code1 ) = $dbh->selectrow_array( $query, {}, 1 );
104 # ---------- Some Layouts -----------------------
106 INSERT INTO creator_layouts
107 (barcode_type , start_label , printing_type, layout_name,
108 guidebox , font , font_size , units ,
109 callnum_split , text_justify, format_string, layout_xml ,
111 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)';
112 $insert_sth = $dbh->prepare($query);
113 $insert_sth->execute( 'COOP2OF5', 1, 'BAR1', 'NAME1', 1, 'TR', 11, 'POINT', 1, 'L', 'barcode', 'layout_xml1', 'Labels' );
115 $insert_sth->execute( 'EAN13', 2, 'BAR2', 'NAME2', 2, 'TR', 12, 'POINT', 2, 'L', 'barcode', 'layout_xml2', 'Labels' );
117 # ---------- Some Printers ---------------------
119 INSERT INTO printers_profile
120 (printer_name, template_id, paper_bin,
121 offset_horz , offset_vert, creep_horz,
122 creep_vert , units , creator)
123 VALUES (?,?,?,?,?,?,?,?,?)';
124 $insert_sth = $dbh->prepare($query);
125 $insert_sth->execute( 'Layout1 Name', 1234, 'Bypass', 0.1, 0.2, 0.3, 0.4, 'POINT', 'Labels' );
127 $insert_sth->execute( 'Layout2 Name', 1235, 'Bypass', 0.2, 0.3, 0.4, 0.5, 'POINT', 'Labels' );
129 # ---------- Some Images -----------------------
130 my $image1 = Graphics
::Magick
->new;
131 my $image2 = Graphics
::Magick
->new;
134 INSERT INTO creator_images
135 (imagefile, image_name)
137 $insert_sth = $dbh->prepare($query);
138 $insert_sth->execute( "$image1->ImageToBlob()", 'Image 1' );
139 $insert_sth->execute( "$image2->ImageToBlob()", 'Image 2' );
141 # ---------- Some biblios -----------------------
142 my $title1 = 'Title 1';
143 my $title2 = 'Title 2';
144 my $title3 = 'Title 3';
145 my $author1 = 'Author 1';
146 my $author2 = 'Author 2';
147 my $author3 = 'Author 3';
151 (title, author, datecreated)
152 VALUES (?,?, NOW())';
153 $insert_sth = $dbh->prepare($query);
154 $insert_sth->execute( $title1, $author1 );
155 $insert_sth->execute( $title2, undef );
156 $insert_sth->execute( $title3, $author3 );
162 my $biblionumber1 = $dbh->selectrow_array( $query, {}, $title1 );
163 my $biblionumber2 = $dbh->selectrow_array( $query, {}, $title2 );
164 my $biblionumber3 = $dbh->selectrow_array( $query, {}, $title3 );
166 # ---------- Some biblio items -------------------------
168 INSERT INTO biblioitems
169 (biblionumber, itemtype)
171 $insert_sth = $dbh->prepare($query);
172 $insert_sth->execute( $biblionumber1, 'Book' );
173 $insert_sth->execute( $biblionumber2, 'Music' );
174 $insert_sth->execute( $biblionumber3, 'Book' );
177 SELECT biblioitemnumber
179 WHERE biblionumber = ?';
180 my $biblioitemnumber1 = $dbh->selectrow_array( $query, {}, $biblionumber1 );
181 my $biblioitemnumber2 = $dbh->selectrow_array( $query, {}, $biblionumber2 );
182 my $biblioitemnumber3 = $dbh->selectrow_array( $query, {}, $biblionumber3 );
184 # ---------- Some items -------------------------
185 my $barcode1 = '111111';
186 my $barcode2 = '222222';
187 my $barcode3 = '333333';
191 (biblionumber, biblioitemnumber, barcode, itype)
193 $insert_sth = $dbh->prepare($query);
194 $insert_sth->execute( $biblionumber1, $biblioitemnumber1, $barcode1, 'Book' );
195 $insert_sth->execute( $biblionumber2, $biblioitemnumber2, $barcode2, 'Music' );
196 $insert_sth->execute( $biblionumber3, $biblioitemnumber3, $barcode3, 'Book' );
202 my $item_number1 = $dbh->selectrow_array( $query, {}, $barcode1 );
203 my $item_number2 = $dbh->selectrow_array( $query, {}, $barcode2 );
204 my $item_number3 = $dbh->selectrow_array( $query, {}, $barcode3 );
206 # ---------- Some borrowers ---------------------
207 my $surname1 = 'Borrower 1';
208 my $surname2 = 'Borrower 2';
209 my $surname3 = 'Borrower 3';
210 my $firstname1 = 'firstname 1';
211 my $firstname2 = 'firstname 2';
212 my $firstname3 = 'firstname 3';
213 my $cardnumber1 = '00001';
214 my $cardnumber2 = '00002';
215 my $cardnumber3 = '00003';
216 my $categorycode = Koha
::Database
->new()->schema()->resultset('Category')->first()->categorycode();
217 my $branchcode = Koha
::Database
->new()->schema()->resultset('Branch')->first()->branchcode();
220 INSERT INTO borrowers
221 (surname, firstname, cardnumber, branchcode, categorycode)
223 $insert_sth = $dbh->prepare($query);
224 $insert_sth->execute( $surname1, $firstname1, $cardnumber1, $branchcode, $categorycode );
225 $insert_sth->execute( $surname2, $firstname2, $cardnumber2, $branchcode, $categorycode );
226 $insert_sth->execute( $surname3, $firstname3, $cardnumber3, $branchcode, $categorycode );
229 SELECT borrowernumber
232 my $borrowernumber1 = $dbh->selectrow_array( $query, {}, $surname1 );
233 my $borrowernumber2 = $dbh->selectrow_array( $query, {}, $surname2 );
234 my $borrowernumber3 = $dbh->selectrow_array( $query, {}, $surname3 );
236 # ---------- Some batches -----------------------
238 INSERT INTO creator_batches
239 (batch_id , item_number, borrower_number,
240 timestamp, branch_code, creator)
241 VALUES (?,?,?,NOW(),?,?)';
242 $insert_sth = $dbh->prepare($query);
243 $insert_sth->execute( 11, $item_number1, $borrowernumber1, $library1->{branchcode
}, 'Labels' );
245 $insert_sth->execute( 12, $item_number2, $borrowernumber2, $library2->{branchcode
}, 'Labels' );
247 $insert_sth->execute( 12, $item_number3, $borrowernumber3, $library3->{branchcode
}, 'Labels' );
249 ###########################################################
251 ###########################################################
253 # ---------- Testing get_all_templates --------------------
254 # Mocking $sth->err and $sth->errstr
256 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
257 $dbi_st->mock( 'err', sub { return 1; } );
258 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
260 warning_is
{ $templates = get_all_templates
() } 'Database returned the following error: something went wrong',
261 'get_all_templates() raises warning if something went wrong with the sql request execution';
263 is
( $templates, -1, '$templates return -1' );
266 # Without params ----------------------
267 my $templates = get_all_templates
();
271 FROM creator_templates
273 my $count = $dbh->selectrow_array($query);
274 is
( $count, 2, 'There are 2 templates' );
275 is
( @
$templates, $count, 'There are 2 templates matching' );
276 isa_ok
( $templates, 'ARRAY', '$templates is an ARRAY' );
278 isa_ok
( $templates->[0], 'HASH', '$templates->[0] is a HASH' );
279 is
( $templates->[0]->{profile_id
}, 1, 'profile_id is good' );
280 is
( $templates->[0]->{template_code
}, 'TEMPL1', 'template_code is good' );
281 is
( $templates->[0]->{template_desc
}, 'Template 1', 'template_desc is good' );
282 is
( $templates->[0]->{page_width
}, 100, 'page_width is good' );
283 is
( $templates->[0]->{page_height
}, 150, 'page_height is good' );
284 is
( $templates->[0]->{label_width
}, 10, 'label_width is good' );
285 is
( $templates->[0]->{label_height
}, 15, 'label_height is good' );
286 is
( $templates->[0]->{top_text_margin
}, 2, 'top_text_margin is good' );
287 is
( $templates->[0]->{left_text_margin
}, 3, 'left_text_margin is good' );
288 is
( $templates->[0]->{top_margin
}, 1, 'top_margin is good' );
289 is
( $templates->[0]->{left_margin
}, 4, 'left_margin is good' );
290 is
( $templates->[0]->{cols
}, 9, 'cols is good' );
291 is
( $templates->[0]->{rows
}, 6, 'rows is good' );
292 is
( $templates->[0]->{col_gap
}, 0.1, 'col_gap is good' );
293 is
( $templates->[0]->{row_gap
}, 0.2, 'row_gap is good' );
294 is
( $templates->[0]->{units
}, 'POINT', 'units is good' );
295 is
( $templates->[0]->{creator
}, 'Labels', 'creator is good' );
297 isa_ok
( $templates->[1], 'HASH', '$templates->[1] is a HASH' );
298 is
( $templates->[1]->{profile_id
}, 2, 'profile_id is good' );
299 is
( $templates->[1]->{template_code
}, 'TEMPL2', 'template_code is good' );
300 is
( $templates->[1]->{template_desc
}, 'Template 2', 'template_desc is good' );
301 is
( $templates->[1]->{page_width
}, 101, 'page_width is good' );
302 is
( $templates->[1]->{page_height
}, 151, 'page_height is good' );
303 is
( $templates->[1]->{label_width
}, 11, 'label_width is good' );
304 is
( $templates->[1]->{label_height
}, 16, 'label_height is good' );
305 is
( $templates->[1]->{top_text_margin
}, 3, 'top_text_margin is good' );
306 is
( $templates->[1]->{left_text_margin
}, 4, 'left_text_margin is good' );
307 is
( $templates->[1]->{top_margin
}, 2, 'top_margin is good' );
308 is
( $templates->[1]->{left_margin
}, 5, 'left_margin is good' );
309 is
( $templates->[1]->{cols
}, 10, 'cols is good' );
310 is
( $templates->[1]->{rows
}, 7, 'rows is good' );
311 is
( $templates->[1]->{col_gap
}, 0.2, 'col_gap is good' );
312 is
( $templates->[1]->{row_gap
}, 0.3, 'row_gap is good' );
313 is
( $templates->[1]->{units
}, 'POINT', 'units is good' );
314 is
( $templates->[1]->{creator
}, 'Labels', 'creator is good' );
316 # With field_list params --------------
317 $templates = get_all_templates
( {fields
=> [qw(units cols rows)] } );
321 FROM creator_templates
323 $count = $dbh->selectrow_array($query);
324 is
( $count, 2, 'There are 2 templates' );
325 is
( @
$templates, $count, 'There are 2 templates matching' );
326 isa_ok
( $templates, 'ARRAY', '$templates is an ARRAY' );
328 isa_ok
( $templates->[0], 'HASH', '$templates->[0] is a HASH' );
329 isnt
( exists $templates->[0]->{profile_id
}, 1, 'profile_id is good' );
330 isnt
( exists $templates->[0]->{template_code
}, 'TEMPL1', 'template_code is good' );
331 isnt
( exists $templates->[0]->{template_desc
}, 'Template 1', 'template_desc is good' );
332 isnt
( exists $templates->[0]->{page_width
}, 100, 'page_width is good' );
333 isnt
( exists $templates->[0]->{page_height
}, 150, 'page_height is good' );
334 isnt
( exists $templates->[0]->{label_width
}, 10, 'label_width is good' );
335 isnt
( exists $templates->[0]->{label_height
}, 15, 'label_height is good' );
336 isnt
( exists $templates->[0]->{top_text_margin
}, 2, 'top_text_margin is good' );
337 isnt
( exists $templates->[0]->{left_text_margin
}, 3, 'left_text_margin is good' );
338 isnt
( exists $templates->[0]->{top_margin
}, 1, 'top_margin is good' );
339 isnt
( exists $templates->[0]->{left_margin
}, 4, 'left_margin is good' );
340 is
( $templates->[0]->{cols
}, 9, 'cols is good' );
341 is
( $templates->[0]->{rows
}, 6, 'rows is good' );
342 isnt
( exists $templates->[0]->{col_gap
}, 0.1, 'col_gap is good' );
343 isnt
( exists $templates->[0]->{row_gap
}, 0.2, 'row_gap is good' );
344 is
( $templates->[0]->{units
}, 'POINT', 'units is good' );
345 isnt
( exists $templates->[0]->{creator
}, 'Labels', 'creator is good' );
347 isa_ok
( $templates->[1], 'HASH', '$templates->[1] is a HASH' );
348 isnt
( exists $templates->[1]->{profile_id
}, 2, 'profile_id is good' );
349 isnt
( exists $templates->[1]->{template_code
}, 'TEMPL2', 'template_code is good' );
350 isnt
( exists $templates->[1]->{template_desc
}, 'Template 2', 'template_desc is good' );
351 isnt
( exists $templates->[1]->{page_width
}, 101, 'page_width is good' );
352 isnt
( exists $templates->[1]->{page_height
}, 151, 'page_height is good' );
353 isnt
( exists $templates->[1]->{label_width
}, 11, 'label_width is good' );
354 isnt
( exists $templates->[1]->{label_height
}, 16, 'label_height is good' );
355 isnt
( exists $templates->[1]->{top_text_margin
}, 3, 'top_text_margin is good' );
356 isnt
( exists $templates->[1]->{left_text_margin
}, 4, 'left_text_margin is good' );
357 isnt
( exists $templates->[1]->{top_margin
}, 2, 'top_margin is good' );
358 isnt
( exists $templates->[1]->{left_margin
}, 5, 'left_margin is good' );
359 is
( $templates->[1]->{cols
}, 10, 'cols is good' );
360 is
( $templates->[1]->{rows
}, 7, 'rows is good' );
361 isnt
( exists $templates->[1]->{col_gap
}, 0.2, 'col_gap is good' );
362 isnt
( exists $templates->[1]->{row_gap
}, 0.3, 'row_gap is good' );
363 is
( $templates->[1]->{units
}, 'POINT', 'units is good' );
364 isnt
( exists $templates->[1]->{creator
}, 'Labels', 'creator is good' );
366 # With filters params ------------------
367 $templates = get_all_templates
( { filters
=> { rows
=> 7} } );
371 FROM creator_templates
374 $count = $dbh->selectrow_array($query);
375 is
( $count, 1, 'There is 1 template matching' );
376 is
( @
$templates, $count, 'There is 1 template matching' );
377 isa_ok
( $templates, 'ARRAY', '$templates is an ARRAY' );
379 isa_ok
( $templates->[0], 'HASH', '$templates->[0] is a HASH' );
380 is
( $templates->[0]->{profile_id
}, 2, 'profile_id is good' );
381 is
( $templates->[0]->{template_code
}, 'TEMPL2', 'template_code is good' );
382 is
( $templates->[0]->{template_desc
}, 'Template 2', 'template_desc is good' );
383 is
( $templates->[0]->{page_width
}, 101, 'page_width is good' );
384 is
( $templates->[0]->{page_height
}, 151, 'page_height is good' );
385 is
( $templates->[0]->{label_width
}, 11, 'label_width is good' );
386 is
( $templates->[0]->{label_height
}, 16, 'label_height is good' );
387 is
( $templates->[0]->{top_text_margin
}, 3, 'top_text_margin is good' );
388 is
( $templates->[0]->{left_text_margin
}, 4, 'left_text_margin is good' );
389 is
( $templates->[0]->{top_margin
}, 2, 'top_margin is good' );
390 is
( $templates->[0]->{left_margin
}, 5, 'left_margin is good' );
391 is
( $templates->[0]->{cols
}, 10, 'cols is good' );
392 is
( $templates->[0]->{rows
}, 7, 'rows is good' );
393 is
( $templates->[0]->{col_gap
}, 0.2, 'col_gap is good' );
394 is
( $templates->[0]->{row_gap
}, 0.3, 'row_gap is good' );
395 is
( $templates->[0]->{units
}, 'POINT', 'units is good' );
396 is
( $templates->[0]->{creator
}, 'Labels', 'creator is good' );
398 $templates = get_all_templates
( { filters
=> { rows
=> [-42, 7]} } );
399 is
( @
$templates, $count, 'There is 1 template matching' );
400 # With orderby param ------------------
401 $templates = get_all_templates
( { orderby
=> '`rows` DESC' } );
405 FROM creator_templates
407 $count = $dbh->selectrow_array($query);
408 is
( $count, 2, 'There are 2 templates' );
409 is
( @
$templates, $count, 'There are 2 templates matching' );
410 isa_ok
( $templates, 'ARRAY', '$templates is an ARRAY' );
412 isa_ok
( $templates->[0], 'HASH', '$templates->[0] is a HASH' );
413 is
( $templates->[0]->{profile_id
}, 2, 'profile_id is good' );
414 is
( $templates->[0]->{template_code
}, 'TEMPL2', 'template_code is good' );
415 is
( $templates->[0]->{template_desc
}, 'Template 2', 'template_desc is good' );
416 is
( $templates->[0]->{page_width
}, 101, 'page_width is good' );
417 is
( $templates->[0]->{page_height
}, 151, 'page_height is good' );
418 is
( $templates->[0]->{label_width
}, 11, 'label_width is good' );
419 is
( $templates->[0]->{label_height
}, 16, 'label_height is good' );
420 is
( $templates->[0]->{top_text_margin
}, 3, 'top_text_margin is good' );
421 is
( $templates->[0]->{left_text_margin
}, 4, 'left_text_margin is good' );
422 is
( $templates->[0]->{top_margin
}, 2, 'top_margin is good' );
423 is
( $templates->[0]->{left_margin
}, 5, 'left_margin is good' );
424 is
( $templates->[0]->{cols
}, 10, 'cols is good' );
425 is
( $templates->[0]->{rows
}, 7, 'rows is good' );
426 is
( $templates->[0]->{col_gap
}, 0.2, 'col_gap is good' );
427 is
( $templates->[0]->{row_gap
}, 0.3, 'row_gap is good' );
428 is
( $templates->[0]->{units
}, 'POINT', 'units is good' );
429 is
( $templates->[0]->{creator
}, 'Labels', 'creator is good' );
431 isa_ok
( $templates->[1], 'HASH', '$templates->[1] is a HASH' );
432 is
( $templates->[1]->{profile_id
}, 1, 'profile_id is good' );
433 is
( $templates->[1]->{template_code
}, 'TEMPL1', 'template_code is good' );
434 is
( $templates->[1]->{template_desc
}, 'Template 1', 'template_desc is good' );
435 is
( $templates->[1]->{page_width
}, 100, 'page_width is good' );
436 is
( $templates->[1]->{page_height
}, 150, 'page_height is good' );
437 is
( $templates->[1]->{label_width
}, 10, 'label_width is good' );
438 is
( $templates->[1]->{label_height
}, 15, 'label_height is good' );
439 is
( $templates->[1]->{top_text_margin
}, 2, 'top_text_margin is good' );
440 is
( $templates->[1]->{left_text_margin
}, 3, 'left_text_margin is good' );
441 is
( $templates->[1]->{top_margin
}, 1, 'top_margin is good' );
442 is
( $templates->[1]->{left_margin
}, 4, 'left_margin is good' );
443 is
( $templates->[1]->{cols
}, 9, 'cols is good' );
444 is
( $templates->[1]->{rows
}, 6, 'rows is good' );
445 is
( $templates->[1]->{col_gap
}, 0.1, 'col_gap is good' );
446 is
( $templates->[1]->{row_gap
}, 0.2, 'row_gap is good' );
447 is
( $templates->[1]->{units
}, 'POINT', 'units is good' );
448 is
( $templates->[1]->{creator
}, 'Labels', 'creator is good' );
450 # ---------- Testing get_all_layouts ----------------------
451 # Mocking $sth->err and $sth->errstr
453 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
454 $dbi_st->mock( 'err', sub { return 1; } );
455 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
457 warning_is
{ $layouts = get_all_layouts
() } 'Database returned the following error: something went wrong',
458 'get_all_layouts() raises warning if something went wrong with the sql request execution';
460 is
( $layouts, -1, '$layouts return -1' );
463 # Without params ----------------------
464 my $layouts = get_all_layouts
();
470 $count = $dbh->selectrow_array($query);
471 is
( $count, 2, 'There are 2 layouts' );
472 is
( @
$layouts, $count, 'There are 2 layouts matching' );
473 isa_ok
( $layouts, 'ARRAY', '$layouts is an ARRAY' );
475 isa_ok
( $layouts->[0], 'HASH', '$layouts->[0] is a HASH' );
476 is
( $layouts->[0]->{barcode_type
}, 'COOP2OF5', 'barcode_type is good' );
477 is
( $layouts->[0]->{start_label
}, 1, 'start_label is good' );
478 is
( $layouts->[0]->{printing_type
}, 'BAR1', 'printing_type is good' );
479 is
( $layouts->[0]->{layout_name
}, 'NAME1', 'layout_name is good' );
480 is
( $layouts->[0]->{guidebox
}, 1, 'guidebox is good' );
481 is
( $layouts->[0]->{font
}, 'TR', 'font is good' );
482 is
( $layouts->[0]->{font_size
}, 11, 'font_size is good' );
483 is
( $layouts->[0]->{units
}, 'POINT', 'units is good' );
484 is
( $layouts->[0]->{callnum_split
}, 1, 'callnum_split is good' );
485 is
( $layouts->[0]->{text_justify
}, 'L', 'text_justify is good' );
486 is
( $layouts->[0]->{format_string
}, 'barcode', 'format_string is good' );
487 is
( $layouts->[0]->{layout_xml
}, 'layout_xml1', 'layout_xml is good' );
488 is
( $layouts->[0]->{creator
}, 'Labels', 'creator is good' );
490 isa_ok
( $layouts->[1], 'HASH', '$layouts->[1] is a HASH' );
491 is
( $layouts->[1]->{barcode_type
}, 'EAN13', 'barcode_type is good' );
492 is
( $layouts->[1]->{start_label
}, 2, 'start_label is good' );
493 is
( $layouts->[1]->{printing_type
}, 'BAR2', 'printing_type is good' );
494 is
( $layouts->[1]->{layout_name
}, 'NAME2', 'layout_name is good' );
495 is
( $layouts->[1]->{guidebox
}, 2, 'guidebox is good' );
496 is
( $layouts->[1]->{font
}, 'TR', 'font is good' );
497 is
( $layouts->[1]->{font_size
}, 12, 'font_size is good' );
498 is
( $layouts->[1]->{units
}, 'POINT', 'units is good' );
499 is
( $layouts->[1]->{callnum_split
}, 2, 'callnum_split is good' );
500 is
( $layouts->[1]->{text_justify
}, 'L', 'text_justify is good' );
501 is
( $layouts->[1]->{format_string
}, 'barcode', 'format_string is good' );
502 is
( $layouts->[1]->{layout_xml
}, 'layout_xml2', 'layout_xml is good' );
503 is
( $layouts->[1]->{creator
}, 'Labels', 'creator is good' );
505 # With field_list params --------------
506 $layouts = get_all_layouts
( { fields
=> [qw(barcode_type layout_name font)] });
512 $count = $dbh->selectrow_array($query);
513 is
( $count, 2, 'There are 2 layouts' );
514 is
( @
$layouts, $count, 'There are 2 layouts matching' );
515 isa_ok
( $layouts, 'ARRAY', '$layouts is an ARRAY' );
517 isa_ok
( $layouts->[0], 'HASH', '$layouts->[0] is a HASH' );
518 is
( $layouts->[0]->{barcode_type
}, 'COOP2OF5', 'barcode_type is good' );
519 isnt
( exists $layouts->[0]->{start_label
}, 1, 'start_label is good' );
520 isnt
( exists $layouts->[0]->{printing_type
}, 'BAR1', 'printing_type is good' );
521 is
( $layouts->[0]->{layout_name
}, 'NAME1', 'layout_name is good' );
522 isnt
( exists $layouts->[0]->{guidebox
}, 1, 'guidebox is good' );
523 is
( $layouts->[0]->{font
}, 'TR', 'font is good' );
524 isnt
( exists $layouts->[0]->{font_size
}, 11, 'font_size is good' );
525 isnt
( exists $layouts->[0]->{units
}, 'POINT', 'units is good' );
526 isnt
( exists $layouts->[0]->{callnum_split
}, 1, 'callnum_split is good' );
527 isnt
( exists $layouts->[0]->{text_justify
}, 'L', 'text_justify is good' );
528 isnt
( exists $layouts->[0]->{format_string
}, 'barcode', 'format_string is good' );
529 isnt
( exists $layouts->[0]->{layout_xml
}, 'layout_xml1', 'layout_xml is good' );
530 isnt
( exists $layouts->[0]->{creator
}, 'Labels', 'creator is good' );
532 isa_ok
( $layouts->[1], 'HASH', '$layouts->[1] is a HASH' );
533 is
( $layouts->[1]->{barcode_type
}, 'EAN13', 'barcode_type is good' );
534 isnt
( exists $layouts->[1]->{start_label
}, 2, 'start_label is good' );
535 isnt
( exists $layouts->[1]->{printing_type
}, 'BAR2', 'printing_type is good' );
536 is
( $layouts->[1]->{layout_name
}, 'NAME2', 'layout_name is good' );
537 isnt
( exists $layouts->[1]->{guidebox
}, 2, 'guidebox is good' );
538 is
( $layouts->[1]->{font
}, 'TR', 'font is good' );
539 isnt
( exists $layouts->[1]->{font_size
}, 12, 'font_size is good' );
540 isnt
( exists $layouts->[1]->{units
}, 'POINT', 'units is good' );
541 isnt
( exists $layouts->[1]->{callnum_split
}, 2, 'callnum_split is good' );
542 isnt
( exists $layouts->[1]->{text_justify
}, 'L', 'text_justify is good' );
543 isnt
( exists $layouts->[1]->{format_string
}, 'barcode', 'format_string is good' );
544 isnt
( exists $layouts->[1]->{layout_xml
}, 'layout_xml2', 'layout_xml is good' );
545 isnt
( exists $layouts->[1]->{creator
}, 'Labels', 'creator is good' );
547 # With filters params ------------------
548 $layouts = get_all_layouts
( { filters
=> { font_size
=> 12 } } );
555 $count = $dbh->selectrow_array($query);
556 is
( $count, 1, 'There is 1 layout matching' );
557 is
( @
$layouts, $count, 'There is 1 layout matching' );
558 isa_ok
( $layouts, 'ARRAY', '$layouts is an ARRAY' );
560 isa_ok
( $layouts->[0], 'HASH', '$layouts->[0] is a HASH' );
561 is
( $layouts->[0]->{barcode_type
}, 'EAN13', 'barcode_type is good' );
562 is
( $layouts->[0]->{start_label
}, 2, 'start_label is good' );
563 is
( $layouts->[0]->{printing_type
}, 'BAR2', 'printing_type is good' );
564 is
( $layouts->[0]->{layout_name
}, 'NAME2', 'layout_name is good' );
565 is
( $layouts->[0]->{guidebox
}, 2, 'guidebox is good' );
566 is
( $layouts->[0]->{font
}, 'TR', 'font is good' );
567 is
( $layouts->[0]->{font_size
}, 12, 'font_size is good' );
568 is
( $layouts->[0]->{units
}, 'POINT', 'units is good' );
569 is
( $layouts->[0]->{callnum_split
}, 2, 'callnum_split is good' );
570 is
( $layouts->[0]->{text_justify
}, 'L', 'text_justify is good' );
571 is
( $layouts->[0]->{format_string
}, 'barcode', 'format_string is good' );
572 is
( $layouts->[0]->{layout_xml
}, 'layout_xml2', 'layout_xml is good' );
573 is
( $layouts->[0]->{creator
}, 'Labels', 'creator is good' );
575 # With orderby param ------------------
576 $layouts = get_all_layouts
( { orderby
=> 'font_size DESC' } );
582 $count = $dbh->selectrow_array($query);
583 is
( $count, 2, 'There are layout matching' );
584 is
( @
$layouts, $count, 'There are 2 layouts matching' );
585 isa_ok
( $layouts, 'ARRAY', '$layouts is an ARRAY' );
587 isa_ok
( $layouts->[0], 'HASH', '$layouts->[0] is a HASH' );
588 is
( $layouts->[0]->{barcode_type
}, 'EAN13', 'barcode_type is good' );
589 is
( $layouts->[0]->{start_label
}, 2, 'start_label is good' );
590 is
( $layouts->[0]->{printing_type
}, 'BAR2', 'printing_type is good' );
591 is
( $layouts->[0]->{layout_name
}, 'NAME2', 'layout_name is good' );
592 is
( $layouts->[0]->{guidebox
}, 2, 'guidebox is good' );
593 is
( $layouts->[0]->{font
}, 'TR', 'font is good' );
594 is
( $layouts->[0]->{font_size
}, 12, 'font_size is good' );
595 is
( $layouts->[0]->{units
}, 'POINT', 'units is good' );
596 is
( $layouts->[0]->{callnum_split
}, 2, 'callnum_split is good' );
597 is
( $layouts->[0]->{text_justify
}, 'L', 'text_justify is good' );
598 is
( $layouts->[0]->{format_string
}, 'barcode', 'format_string is good' );
599 is
( $layouts->[0]->{layout_xml
}, 'layout_xml2', 'layout_xml is good' );
600 is
( $layouts->[0]->{creator
}, 'Labels', 'creator is good' );
602 isa_ok
( $layouts->[1], 'HASH', '$layouts->[1] is a HASH' );
603 is
( $layouts->[1]->{barcode_type
}, 'COOP2OF5', 'barcode_type is good' );
604 is
( $layouts->[1]->{start_label
}, 1, 'start_label is good' );
605 is
( $layouts->[1]->{printing_type
}, 'BAR1', 'printing_type is good' );
606 is
( $layouts->[1]->{layout_name
}, 'NAME1', 'layout_name is good' );
607 is
( $layouts->[1]->{guidebox
}, 1, 'guidebox is good' );
608 is
( $layouts->[1]->{font
}, 'TR', 'font is good' );
609 is
( $layouts->[1]->{font_size
}, 11, 'font_size is good' );
610 is
( $layouts->[1]->{units
}, 'POINT', 'units is good' );
611 is
( $layouts->[1]->{callnum_split
}, 1, 'callnum_split is good' );
612 is
( $layouts->[1]->{text_justify
}, 'L', 'text_justify is good' );
613 is
( $layouts->[1]->{format_string
}, 'barcode', 'format_string is good' );
614 is
( $layouts->[1]->{layout_xml
}, 'layout_xml1', 'layout_xml is good' );
615 is
( $layouts->[1]->{creator
}, 'Labels', 'creator is good' );
617 # ---------- Testing get_all_profiles ---------------------
618 # Mocking $sth->err and $sth->errstr
620 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
621 $dbi_st->mock( 'err', sub { return 1; } );
622 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
624 warning_is
{ $profiles = get_all_profiles
() } 'Database returned the following error: something went wrong',
625 'get_all_profiles() raises warning if something went wrong with the sql request execution';
627 is
( $profiles, -1, '$profiles return -1' );
630 # Without params ----------------------
631 my $profiles = get_all_profiles
();
635 FROM printers_profile
637 $count = $dbh->selectrow_array($query);
638 is
( $count, 2, 'There are 2 profiles' );
639 is
( @
$profiles, $count, 'There are 2 profiles matching' );
640 isa_ok
( $profiles, 'ARRAY', '$profiles is an ARRAY' );
642 isa_ok
( $profiles->[0], 'HASH', '$profiles->[0] is a HASH' );
643 is
( $profiles->[0]->{printer_name
}, 'Layout1 Name', 'printer_name is good' );
644 is
( $profiles->[0]->{template_id
}, 1234, 'template_id is good' );
645 is
( $profiles->[0]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
646 is
( $profiles->[0]->{offset_horz
}, 0.1, 'offset_horz is good' );
647 is
( $profiles->[0]->{offset_vert
}, 0.2, 'offset_vert is good' );
648 is
( $profiles->[0]->{creep_horz
}, 0.3, 'creep_horz is good' );
649 is
( $profiles->[0]->{creep_vert
}, 0.4, 'creep_vert is good' );
650 is
( $profiles->[0]->{units
}, 'POINT', 'units is good' );
651 is
( $profiles->[0]->{creator
}, 'Labels', 'creator is good' );
653 isa_ok
( $profiles->[1], 'HASH', '$profiles->[1] is a HASH' );
654 is
( $profiles->[1]->{printer_name
}, 'Layout2 Name', 'printer_name is good' );
655 is
( $profiles->[1]->{template_id
}, 1235, 'template_id is good' );
656 is
( $profiles->[1]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
657 is
( $profiles->[1]->{offset_horz
}, 0.2, 'offset_horz is good' );
658 is
( $profiles->[1]->{offset_vert
}, 0.3, 'offset_vert is good' );
659 is
( $profiles->[1]->{creep_horz
}, 0.4, 'creep_horz is good' );
660 is
( $profiles->[1]->{creep_vert
}, 0.5, 'creep_vert is good' );
661 is
( $profiles->[1]->{units
}, 'POINT', 'units is good' );
662 is
( $profiles->[1]->{creator
}, 'Labels', 'creator is good' );
664 # With field_list params --------------
665 $profiles = get_all_profiles
( { fields
=> [qw(printer_name template_id)] });
669 FROM printers_profile
671 $count = $dbh->selectrow_array($query);
672 is
( $count, 2, 'There are 2 profiles' );
673 is
( @
$profiles, $count, 'There are 2 profiles matching' );
674 isa_ok
( $profiles, 'ARRAY', '$profiles is an ARRAY' );
676 isa_ok
( $profiles->[0], 'HASH', '$profiles->[0] is a HASH' );
677 is
( $profiles->[0]->{printer_name
}, 'Layout1 Name', 'printer_name is good' );
678 is
( $profiles->[0]->{template_id
}, 1234, 'template_id is good' );
679 isnt
( exists $profiles->[0]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
680 isnt
( exists $profiles->[0]->{offset_horz
}, 0.1, 'offset_horz is good' );
681 isnt
( exists $profiles->[0]->{offset_vert
}, 0.2, 'offset_vert is good' );
682 isnt
( exists $profiles->[0]->{creep_horz
}, 0.3, 'creep_horz is good' );
683 isnt
( exists $profiles->[0]->{creep_vert
}, 0.4, 'creep_vert is good' );
684 isnt
( exists $profiles->[0]->{units
}, 'POINT', 'units is good' );
685 isnt
( exists $profiles->[0]->{creator
}, 'Labels', 'creator is good' );
687 isa_ok
( $profiles->[1], 'HASH', '$profiles->[1] is a HASH' );
688 is
( $profiles->[1]->{printer_name
}, 'Layout2 Name', 'printer_name is good' );
689 is
( $profiles->[1]->{template_id
}, 1235, 'template_id is good' );
690 isnt
( exists $profiles->[1]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
691 isnt
( exists $profiles->[1]->{offset_horz
}, 0.2, 'offset_horz is good' );
692 isnt
( exists $profiles->[1]->{offset_vert
}, 0.3, 'offset_vert is good' );
693 isnt
( exists $profiles->[1]->{creep_horz
}, 0.4, 'creep_horz is good' );
694 isnt
( exists $profiles->[1]->{creep_vert
}, 0.5, 'creep_vert is good' );
695 isnt
( exists $profiles->[1]->{units
}, 'POINT', 'units is good' );
696 isnt
( exists $profiles->[1]->{creator
}, 'Labels', 'creator is good' );
698 # With filters params ------------------
699 $profiles = get_all_profiles
( { filters
=> { template_id
=> 1235 } } );
703 FROM printers_profile
704 WHERE template_id = 1235
706 $count = $dbh->selectrow_array($query);
707 is
( $count, 1, 'There is 1 profile matching' );
708 is
( @
$profiles, $count, 'There is 1 profile matching' );
709 isa_ok
( $profiles, 'ARRAY', '$profiles is an ARRAY' );
711 isa_ok
( $profiles->[0], 'HASH', '$profiles->[0] is a HASH' );
712 is
( $profiles->[0]->{printer_name
}, 'Layout2 Name', 'printer_name is good' );
713 is
( $profiles->[0]->{template_id
}, 1235, 'template_id is good' );
714 isnt
( exists $profiles->[0]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
715 isnt
( exists $profiles->[0]->{offset_horz
}, 0.2, 'offset_horz is good' );
716 isnt
( exists $profiles->[0]->{offset_vert
}, 0.3, 'offset_vert is good' );
717 isnt
( exists $profiles->[0]->{creep_horz
}, 0.4, 'creep_horz is good' );
718 isnt
( exists $profiles->[0]->{creep_vert
}, 0.5, 'creep_vert is good' );
719 isnt
( exists $profiles->[0]->{units
}, 'POINT', 'units is good' );
720 isnt
( exists $profiles->[0]->{creator
}, 'Labels', 'creator is good' );
722 # ---------- Testing get_all_image_names ------------------
724 # Mocking $sth->err and $sth->errstr
726 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
727 $dbi_st->mock( 'err', sub { return 1; } );
728 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
730 warning_is
{ $images = get_all_image_names
() } 'Database returned the following error: something went wrong',
731 'get_all_image_names() raises warning if something went wrong with the sql request execution';
733 is
( $images, -1, '$images return -1' );
736 # Without params ----------------------
737 my $images = get_all_image_names
();
743 $count = $dbh->selectrow_array($query);
744 is
( $count, 2, 'There are 2 images' );
745 is
( @
$images, $count, 'There are 2 images matching' );
746 isa_ok
( $images, 'ARRAY', '$images is an ARRAY' );
748 isa_ok
( $images->[0], 'HASH', '$images->[0] is a HASH' );
749 is
( $images->[0]->{name
}, 'Image 1', 'name is good' );
750 is
( $images->[0]->{selected
}, 0, 'selected is good' );
751 is
( $images->[0]->{type
}, $images->[0]->{name
}, 'type is good' );
753 isa_ok
( $images->[1], 'HASH', '$images->[1] is a HASH' );
754 is
( $images->[1]->{name
}, 'Image 2', 'name is good' );
755 is
( $images->[1]->{selected
}, 0, 'selected is good' );
756 is
( $images->[1]->{type
}, $images->[1]->{name
}, 'type is good' );
758 # ---------- Testing get_batch_summary --------------------
760 # Mocking $sth->err and $sth->errstr
762 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
763 $dbi_st->mock( 'err', sub { return 1; } );
764 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
766 warning_is
{ $batches = get_batch_summary
() } 'Database returned the following error on attempted SELECT: something went wrong',
767 'get_batch_summary() raises warning if something went wrong with the sql request execution';
769 is
( $batches, -1, '$batches return -1' );
772 # Without creator params --------------
773 my $batches = get_batch_summary
( { filters
=> { creator
=> 'Labels' } } );
776 SELECT batch_id, count(batch_id)
781 my $sth = $dbh->prepare($query);
782 $sth->execute('Labels');
784 is
( $count, 2, 'There are 2 batches' );
785 is
( @
$batches, $count, 'There are 2 batches matching' );
786 isa_ok
( $batches, 'ARRAY', '$batches is an ARRAY' );
789 SELECT count(batch_id)
794 $count = $dbh->selectrow_array( $query, {}, 'Labels', 11 );
795 is
( $count, 1, 'There is 1 batch where batch_id = 11' );
797 isa_ok
( $batches->[0], 'HASH', '$batches->[0] is a HASH' );
798 is
( $batches->[0]->{batch_id
}, 11, 'batch_id is good' );
799 is
( $batches->[0]->{_item_count
}, $count, 'item_number is good for this batch_id' );
801 $count = $dbh->selectrow_array( $query, {}, 'Labels', 12 );
802 is
( $count, 2, 'There are 2 batches where batch_id = 12' );
804 isa_ok
( $batches->[1], 'HASH', '$batches->[1] is a HASH' );
805 is
( $batches->[1]->{batch_id
}, 12, 'batch_id is good' );
806 is
( $batches->[1]->{_item_count
}, $count, 'item_number is good for this batch_id' );
808 # Without filters -----
809 $batches = get_batch_summary
( { filters
=> { branch_code
=> $library1->{branchcode
}, creator
=> 'Labels' } } );
810 is
( @
$batches, 1, 'There is 1 batch matching' );
813 SELECT batch_id, count(batch_id)
819 my ( $id, $nb ) = $dbh->selectrow_array( $query, {}, 'Labels', $library1->{branchcode
} );
821 is
( $batches->[0]->{batch_id
}, $id, 'batch_id is good' );
822 is
( $batches->[0]->{_item_count
}, $nb, 'item_number is good for this batch_id' );
824 # ---------- Testing get_label_summary --------------------
825 # Mocking $sth->err and $sth->errstr
827 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
828 $dbi_st->mock( 'err', sub { return 1; } );
829 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
831 my @items = [ { item_number
=> $item_number1 } ];
833 warning_is
{ $labels = get_label_summary
( items
=> @items ) } 'Database returned the following error on attempted SELECT: something went wrong',
834 'get_label_summary() raises warning if something went wrong with the sql request execution';
836 is
( $labels, -1, '$labels return -1' );
839 # Without params ----------------------
840 my $labels = get_label_summary
();
842 isa_ok
( $labels, 'ARRAY', '$labels is an ARRAY' );
843 is
( @
$labels, 0, '$labels is empty' );
845 # With items param --------------------
847 SELECT biblionumber, title, author
849 WHERE biblionumber = ?
851 my ( $b_biblionumber1, $b_title1, $b_author1 ) = $dbh->selectrow_array( $query, {}, $biblionumber1 );
852 my ( $b_biblionumber2, $b_title2, $b_author2 ) = $dbh->selectrow_array( $query, {}, $biblionumber2 );
855 SELECT biblionumber, biblioitemnumber, itemtype
857 WHERE biblioitemnumber = ?
859 my ( $bi_biblionumber1, $bi_biblioitemnumber1, $bi_itemtype1 ) = $dbh->selectrow_array( $query, {}, $biblioitemnumber1 );
860 my ( $bi_biblionumber2, $bi_biblioitemnumber2, $bi_itemtype2 ) = $dbh->selectrow_array( $query, {}, $biblioitemnumber2 );
863 SELECT biblionumber, biblioitemnumber, itemnumber, barcode, itype
867 my ( $i_biblionumber1, $i_biblioitemnumber1, $i_itemnumber1, $i_barcode1, $i_itype1 ) = $dbh->selectrow_array( $query, {}, $item_number1 );
868 my ( $i_biblionumber2, $i_biblioitemnumber2, $i_itemnumber2, $i_barcode2, $i_itype2 ) = $dbh->selectrow_array( $query, {}, $item_number2 );
871 SELECT label_id, batch_id, item_number
873 WHERE item_number = ?
875 my ( $c_label_id1, $c_batch_id1, $c_item_number1 ) = $dbh->selectrow_array( $query, {}, $item_number1 );
876 my ( $c_label_id2, $c_batch_id2, $c_item_number2 ) = $dbh->selectrow_array( $query, {}, $item_number2 );
878 is
( $c_item_number1, $i_itemnumber1, 'CREATOR_BATCHES.item_number == ITEMS.itemnumber' );
879 is
( $i_biblioitemnumber1, $bi_biblioitemnumber1, 'ITEMS.biblioitemnumber == BIBLIOITEMS.biblioitemnumber' );
880 is
( $bi_biblionumber1, $b_biblionumber1, 'BIBLIOITEMS.biblionumber == BIBLIO.biblionumber' );
882 is
( $c_item_number2, $i_itemnumber2, 'CREATOR_BATCHES.item_number == ITEMS.itemnumber' );
883 is
( $i_biblioitemnumber2, $bi_biblioitemnumber2, 'ITEMS.biblioitemnumber == BIBLIOITEMS.biblioitemnumber' );
884 is
( $bi_biblionumber2, $b_biblionumber2, 'BIBLIOITEMS.biblionumber == BIBLIO.biblionumber' );
887 { item_number
=> $item_number1,
888 label_id
=> $c_label_id1,
891 $labels = get_label_summary
( items
=> @items, batch_id
=> $c_batch_id1 );
893 is
( @
$labels, 1, 'There is 1 label for $item_number1' );
894 isa_ok
( $labels, 'ARRAY', '$labels is an array' );
895 isa_ok
( $labels->[0], 'HASH', '$labels->[0] is an hash' );
897 my $record_author = $b_author1;
898 my $record_title = $b_title1;
899 $record_author =~ s/[^\.|\w]$//;
900 $record_title =~ s/\W*$//;
901 $record_title = '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' . $b_biblionumber1 . '"> ' . $b_title1 . '</a>';
902 my $summary1 = $record_title . " | " . ( $b_author1 ?
$b_author1 : 'N/A' );
903 my $itemtypes_pref = C4
::Context
->preference("item-level_itypes");
904 my $record_itemtype = $itemtypes_pref ?
$i_itype1 : $bi_itemtype1;
906 is
( $labels->[0]->{_label_number
}, 1, '_label_number is good' );
907 is
( $labels->[0]->{_summary
}, $summary1, '_summary is good' );
908 is
( $labels->[0]->{_item_type
}, $record_itemtype, '_item_type is good' );
909 is
( $labels->[0]->{_barcode
}, $i_barcode1, '_barcode is good' );
910 is
( $labels->[0]->{_item_number
}, $i_itemnumber1, '_item_number is good' );
911 is
( $labels->[0]->{_label_id
}, $c_label_id1, '_label_id is good' );
913 # record without author
915 { item_number
=> $item_number2,
916 label_id
=> $c_label_id2,
919 $labels = get_label_summary
( items
=> @items, batch_id
=> $c_batch_id2 );
921 is
( @
$labels, 1, 'There is 1 label for $item_number2' );
922 isa_ok
( $labels, 'ARRAY', '$labels is an array' );
923 isa_ok
( $labels->[0], 'HASH', '$labels->[0] is an hash' );
925 $record_author = $b_author2;
926 $record_title = $b_title2;
927 $record_author =~ s/[^\.|\w]$// if $b_author2;
928 $record_title =~ s/\W*$//;
929 $record_title = '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' . $b_biblionumber2 . '"> ' . $b_title2 . '</a>';
930 my $summary2 = $record_title . " | " . ( $b_author2 ?
$b_author2 : 'N/A' );
931 $itemtypes_pref = C4
::Context
->preference("item-level_itypes");
932 $record_itemtype = $itemtypes_pref ?
$i_itype2 : $bi_itemtype2;
934 is
( $labels->[0]->{_label_number
}, 1, '_label_number is good' );
935 is
( $labels->[0]->{_summary
}, $summary2, '_summary is good' );
936 is
( $labels->[0]->{_item_type
}, $record_itemtype, '_item_type is good' );
937 is
( $labels->[0]->{_barcode
}, $i_barcode2, '_barcode is good' );
938 is
( $labels->[0]->{_item_number
}, $i_itemnumber2, '_item_number is good' );
939 is
( $labels->[0]->{_label_id
}, $c_label_id2, '_label_id is good' );
941 #Mocking C4::Context->preference("item-level_itypes")
943 t
::lib
::Mocks
::mock_preference
( "item-level_itypes", 0 );
944 my $h = C4
::Context
->preference("item-level_itypes");
947 { item_number
=> $item_number1,
948 label_id
=> $c_label_id1,
951 $labels = get_label_summary
( items
=> @items, batch_id
=> $c_batch_id1 );
953 is
( @
$labels, 1, 'There is 1 label for $item_number1' );
954 isa_ok
( $labels, 'ARRAY', '$labels is an array' );
955 isa_ok
( $labels->[0], 'HASH', '$labels->[0] is an hash' );
957 my $record_author = $b_author1;
958 my $record_title = $b_title1;
959 $record_author =~ s/[^\.|\w]$//;
960 $record_title =~ s/\W*$//;
961 $record_title = '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' . $b_biblionumber1 . '"> ' . $b_title1 . '</a>';
962 my $summary1 = $record_title . " | " . ( $b_author1 ?
$b_author1 : 'N/A' );
963 my $itemtypes_pref = C4
::Context
->preference("item-level_itypes");
964 my $record_itemtype = $itemtypes_pref ?
$i_itype1 : $bi_itemtype1;
966 is
( $labels->[0]->{_label_number
}, 1, '_label_number is good' );
967 is
( $labels->[0]->{_summary
}, $summary1, '_summary is good' );
968 is
( $labels->[0]->{_item_type
}, $record_itemtype, '_item_type is good' );
969 is
( $labels->[0]->{_barcode
}, $i_barcode1, '_barcode is good' );
970 is
( $labels->[0]->{_item_number
}, $i_itemnumber1, '_item_number is good' );
971 is
( $labels->[0]->{_label_id
}, $c_label_id1, '_label_id is good' );
974 # ---------- Testing get_card_summary ---------------------
975 # Mocking $sth->err and $sth->errstr
977 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
978 $dbi_st->mock( 'err', sub { return 1; } );
979 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
981 my @items = [ { item_number
=> $item_number1 } ];
983 warning_is
{ $cards = get_card_summary
( items
=> @items ) } 'Database returned the following error on attempted SELECT: something went wrong',
984 'get_card_summary() raises warning if something went wrong with the sql request execution';
986 is
( $cards, -1, '$cards return -1' );
989 # Without params ----------------------
990 my $cards = get_card_summary
();
992 isa_ok
( $cards, 'ARRAY', '$cards is an ARRAY' );
993 is
( @
$cards, 0, '$cards is empty' );
995 # With items param --------------------
997 SELECT surname, firstname, cardnumber
999 WHERE borrowernumber = ?
1001 my ( $b_surname1, $b_firstname1, $b_cardnumber1 ) = $dbh->selectrow_array( $query, {}, $borrowernumber1 );
1004 { item_number
=> $item_number1,
1005 label_id
=> $c_label_id1,
1006 borrower_number
=> $borrowernumber1,
1009 $cards = get_card_summary
( items
=> @items );
1011 is
( @
$cards, 1, 'There is 1 card for $item_number1' );
1012 isa_ok
( $cards, 'ARRAY', '$cards is an array' );
1013 isa_ok
( $cards->[0], 'HASH', '$cards->[0] is an hash' );
1015 my $name1 = "$b_surname1, $b_firstname1";
1016 is
( $cards->[0]->{_card_number
}, 1, '_card_number is good' );
1017 is
( $cards->[0]->{_summary
}, $name1, '_summary is good' );
1018 is
( $cards->[0]->{borrowernumber
}, $borrowernumber1, 'borrowernumber is good' );
1019 is
( $cards->[0]->{_label_id
}, $c_label_id1, '_label_id is good' );
1021 # ---------- Testing get_barcode_types --------------------
1022 my $barcode_types = get_barcode_types
();
1024 is
( @
$barcode_types, 6, 'There are 6 barcodes types' );
1025 isa_ok
( $barcode_types, 'ARRAY', '$barcode_types is an ARRAY' );
1027 isa_ok
( $barcode_types->[0], 'HASH', '$barcode_types->[0] is a HASH' );
1028 is
( $barcode_types->[0]->{type
}, 'CODE39', 'type is good' );
1029 is
( $barcode_types->[0]->{name
}, 'Code 39', 'name is good' );
1030 is
( $barcode_types->[0]->{desc
}, 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern.', 'desc is good' );
1031 is
( $barcode_types->[0]->{selected
}, 0, 'selected is good' );
1033 isa_ok
( $barcode_types->[1], 'HASH', '$barcode_types->[1] is a HASH' );
1034 is
( $barcode_types->[1]->{type
}, 'CODE39MOD', 'type is good' );
1035 is
( $barcode_types->[1]->{name
}, 'Code 39 + Modulo43', 'name is good' );
1036 is
( $barcode_types->[1]->{desc
},
1037 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern. Encodes Mod 43 checksum.',
1040 is
( $barcode_types->[1]->{selected
}, 0, 'selected is good' );
1042 isa_ok
( $barcode_types->[2], 'HASH', '$barcode_types->[2] is a HASH' );
1043 is
( $barcode_types->[2]->{type
}, 'CODE39MOD10', 'type is good' );
1044 is
( $barcode_types->[2]->{name
}, 'Code 39 + Modulo10', 'name is good' );
1045 is
( $barcode_types->[2]->{desc
}, 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern. Encodes Mod 10 checksum.', 'desc is good');
1046 is
( $barcode_types->[2]->{selected
}, 0, 'selected is good' );
1048 isa_ok
( $barcode_types->[3], 'HASH', '$barcode_types->[3] is a HASH' );
1049 is
( $barcode_types->[3]->{type
}, 'COOP2OF5', 'type is good' );
1050 is
( $barcode_types->[3]->{name
}, 'COOP2of5', 'name is good' );
1051 is
( $barcode_types->[3]->{desc
}, 'Creates COOP2of5 barcodes from a string consisting of the numeric characters 0-9', 'desc is good' );
1052 is
( $barcode_types->[3]->{selected
}, 0, 'selected is good' );
1054 isa_ok
( $barcode_types->[4], 'HASH', '$barcode_types->[4] is a HASH' );
1055 is
( $barcode_types->[4]->{type
}, 'EAN13', 'type is good' );
1056 is
( $barcode_types->[4]->{name
}, 'EAN13', 'name is good' );
1057 is
( $barcode_types->[4]->{desc
}, 'Creates EAN13 barcodes from a string of 12 or 13 digits. The check number (the 13:th digit) is calculated if not supplied.', 'desc is good' );
1058 is
( $barcode_types->[4]->{selected
}, 0, 'selected is good' );
1060 isa_ok
( $barcode_types->[5], 'HASH', '$barcode_types->[5] is a HASH' );
1061 is
( $barcode_types->[5]->{type
}, 'INDUSTRIAL2OF5', 'type is good' );
1062 is
( $barcode_types->[5]->{name
}, 'Industrial2of5', 'name is good' );
1063 is
( $barcode_types->[5]->{desc
}, 'Creates Industrial2of5 barcodes from a string consisting of the numeric characters 0-9', 'desc is good' );
1064 is
( $barcode_types->[5]->{selected
}, 0, 'selected is good' );
1066 # ---------- Testing get_label_types ----------------------
1067 my $label_types = get_label_types
();
1069 is
( @
$label_types, 5, 'There are 5 label types' );
1070 isa_ok
( $label_types, 'ARRAY', '$label_types is an ARRAY' );
1072 isa_ok
( $label_types->[0], 'HASH', '$label_types->[0] is a HASH' );
1073 is
( $label_types->[0]->{type
}, 'BIB', 'type is good' );
1074 is
( $label_types->[0]->{name
}, 'Biblio', 'name is good' );
1075 is
( $label_types->[0]->{desc
}, 'Only the bibliographic data is printed.', 'desc is good' );
1076 is
( $label_types->[0]->{selected
}, 0, 'selected is good' );
1078 isa_ok
( $label_types->[1], 'HASH', '$label_types->[1] is a HASH' );
1079 is
( $label_types->[1]->{type
}, 'BARBIB', 'type is good' );
1080 is
( $label_types->[1]->{name
}, 'Barcode/Biblio', 'name is good' );
1081 is
( $label_types->[1]->{desc
}, 'Barcode proceeds bibliographic data.', 'desc is good' );
1082 is
( $label_types->[1]->{selected
}, 0, 'selected is good' );
1084 isa_ok
( $label_types->[2], 'HASH', '$label_types->[2] is a HASH' );
1085 is
( $label_types->[2]->{type
}, 'BIBBAR', 'type is good' );
1086 is
( $label_types->[2]->{name
}, 'Biblio/Barcode', 'name is good' );
1087 is
( $label_types->[2]->{desc
}, 'Bibliographic data proceeds barcode.', 'desc is good' );
1088 is
( $label_types->[2]->{selected
}, 0, 'selected is good' );
1090 isa_ok
( $label_types->[3], 'HASH', '$label_types->[3] is a HASH' );
1091 is
( $label_types->[3]->{type
}, 'ALT', 'type is good' );
1092 is
( $label_types->[3]->{name
}, 'Alternating', 'name is good' );
1093 is
( $label_types->[3]->{desc
}, 'Barcode and bibliographic data are printed on alternating labels.', 'desc is good' );
1094 is
( $label_types->[3]->{selected
}, 0, 'selected is good' );
1096 isa_ok
( $label_types->[4], 'HASH', '$label_types->[4] is a HASH' );
1097 is
( $label_types->[4]->{type
}, 'BAR', 'type is good' );
1098 is
( $label_types->[4]->{name
}, 'Barcode', 'name is good' );
1099 is
( $label_types->[4]->{desc
}, 'Only the barcode is printed.', 'desc is good' );
1100 is
( $label_types->[4]->{selected
}, 0, 'selected is good' );
1102 $label_types->[0]->{selected
} = 1;
1103 $label_types = get_label_types
();
1104 is
( $label_types->[0]->{selected
}, 0, 'get_label_types must returned a new structure (copied)' );
1107 # ---------- Testing get_font_types -----------------------
1108 my $font_types = get_font_types
();
1110 is
( @
$font_types, 12, 'There are 12 font types' );
1111 isa_ok
( $font_types, 'ARRAY', '$font_types is an ARRAY' );
1113 isa_ok
( $font_types->[0], 'HASH', '$font_types->[0] is a HASH' );
1114 is
( $font_types->[0]->{type
}, 'TR', 'type is good' );
1115 is
( $font_types->[0]->{name
}, 'Times-Roman', 'name is good' );
1116 is
( $font_types->[0]->{selected
}, 0, 'selected is good' );
1118 isa_ok
( $font_types->[1], 'HASH', '$font_types->[1] is a HASH' );
1119 is
( $font_types->[1]->{type
}, 'TB', 'type is good' );
1120 is
( $font_types->[1]->{name
}, 'Times-Bold', 'name is good' );
1121 is
( $font_types->[1]->{selected
}, 0, 'selected is good' );
1123 isa_ok
( $font_types->[2], 'HASH', '$font_types->[2] is a HASH' );
1124 is
( $font_types->[2]->{type
}, 'TI', 'type is good' );
1125 is
( $font_types->[2]->{name
}, 'Times-Italic', 'name is good' );
1126 is
( $font_types->[2]->{selected
}, 0, 'selected is good' );
1128 isa_ok
( $font_types->[3], 'HASH', '$font_types->[3] is a HASH' );
1129 is
( $font_types->[3]->{type
}, 'TBI', 'type is good' );
1130 is
( $font_types->[3]->{name
}, 'Times-Bold-Italic', 'name is good' );
1131 is
( $font_types->[3]->{selected
}, 0, 'selected is good' );
1133 isa_ok
( $font_types->[4], 'HASH', '$font_types->[4] is a HASH' );
1134 is
( $font_types->[4]->{type
}, 'C', 'type is good' );
1135 is
( $font_types->[4]->{name
}, 'Courier', 'name is good' );
1136 is
( $font_types->[4]->{selected
}, 0, 'selected is good' );
1138 isa_ok
( $font_types->[5], 'HASH', '$font_types->[5] is a HASH' );
1139 is
( $font_types->[5]->{type
}, 'CB', 'type is good' );
1140 is
( $font_types->[5]->{name
}, 'Courier-Bold', 'name is good' );
1141 is
( $font_types->[5]->{selected
}, 0, 'selected is good' );
1143 isa_ok
( $font_types->[6], 'HASH', '$font_types->[6] is a HASH' );
1144 is
( $font_types->[6]->{type
}, 'CO', 'type is good' );
1145 is
( $font_types->[6]->{name
}, 'Courier-Oblique', 'name is good' );
1146 is
( $font_types->[6]->{selected
}, 0, 'selected is good' );
1148 isa_ok
( $font_types->[7], 'HASH', '$font_types->[7] is a HASH' );
1149 is
( $font_types->[7]->{type
}, 'CBO', 'type is good' );
1150 is
( $font_types->[7]->{name
}, 'Courier-Bold-Oblique', 'name is good' );
1151 is
( $font_types->[7]->{selected
}, 0, 'selected is good' );
1153 isa_ok
( $font_types->[8], 'HASH', '$font_types->[8] is a HASH' );
1154 is
( $font_types->[8]->{type
}, 'H', 'type is good' );
1155 is
( $font_types->[8]->{name
}, 'Helvetica', 'name is good' );
1156 is
( $font_types->[8]->{selected
}, 0, 'selected is good' );
1158 isa_ok
( $font_types->[9], 'HASH', '$font_types->[9] is a HASH' );
1159 is
( $font_types->[9]->{type
}, 'HO', 'type is good' );
1160 is
( $font_types->[9]->{name
}, 'Helvetica-Oblique', 'name is good' );
1161 is
( $font_types->[9]->{selected
}, 0, 'selected is good' );
1163 isa_ok
( $font_types->[10], 'HASH', '$font_types->[10] is a HASH' );
1164 is
( $font_types->[10]->{type
}, 'HB', 'type is good' );
1165 is
( $font_types->[10]->{name
}, 'Helvetica-Bold', 'name is good' );
1166 is
( $font_types->[10]->{selected
}, 0, 'selected is good' );
1168 isa_ok
( $font_types->[11], 'HASH', '$font_types->[11] is a HASH' );
1169 is
( $font_types->[11]->{type
}, 'HBO', 'type is good' );
1170 is
( $font_types->[11]->{name
}, 'Helvetica-Bold-Oblique', 'name is good' );
1171 is
( $font_types->[11]->{selected
}, 0, 'selected is good' );
1173 # ---------- Testing get_text_justification_types ---------
1174 my $text_justification_types = get_text_justification_types
();
1176 is
( @
$text_justification_types, 3, 'There are 3 text justification types' );
1177 isa_ok
( $text_justification_types, 'ARRAY', '$text_justification_types is an ARRAY' );
1179 isa_ok
( $text_justification_types->[0], 'HASH', '$font_types->[0] is a HASH' );
1180 is
( $text_justification_types->[0]->{type
}, 'L', 'type is good' );
1181 is
( $text_justification_types->[0]->{name
}, 'Left', 'name is good' );
1182 is
( $text_justification_types->[0]->{selected
}, 0, 'selected is good' );
1184 isa_ok
( $text_justification_types->[1], 'HASH', '$font_types->[1] is a HASH' );
1185 is
( $text_justification_types->[1]->{type
}, 'C', 'type is good' );
1186 is
( $text_justification_types->[1]->{name
}, 'Center', 'name is good' );
1187 is
( $text_justification_types->[1]->{selected
}, 0, 'selected is good' );
1189 isa_ok
( $text_justification_types->[2], 'HASH', '$font_types->[2] is a HASH' );
1190 is
( $text_justification_types->[2]->{type
}, 'R', 'type is good' );
1191 is
( $text_justification_types->[2]->{name
}, 'Right', 'name is good' );
1192 is
( $text_justification_types->[2]->{selected
}, 0, 'selected is good' );
1194 # ---------- Testing get_unit_values ----------------------
1195 my $unit_values = get_unit_values
();
1197 is
( @
$unit_values, 5, 'There are 5 unit values' );
1198 isa_ok
( $unit_values, 'ARRAY', '$unit_values is an ARRAY' );
1200 isa_ok
( $unit_values->[0], 'HASH', '$unit_values->[0] is a HASH' );
1201 is
( $unit_values->[0]->{type
}, 'POINT', 'type is good' );
1202 is
( $unit_values->[0]->{desc
}, 'PostScript Points', 'desc is good' );
1203 is
( $unit_values->[0]->{value
}, 1, 'value is good' );
1204 is
( $unit_values->[0]->{selected
}, 0, 'selected is good' );
1206 isa_ok
( $unit_values->[1], 'HASH', '$unit_values->[1] is a HASH' );
1207 is
( $unit_values->[1]->{type
}, 'AGATE', 'type is good' );
1208 is
( $unit_values->[1]->{desc
}, 'Adobe Agates', 'desc is good' );
1209 is
( $unit_values->[1]->{value
}, 5.1428571, 'value is good' );
1210 is
( $unit_values->[1]->{selected
}, 0, 'selected is good' );
1212 isa_ok
( $unit_values->[2], 'HASH', '$unit_values->[2] is a HASH' );
1213 is
( $unit_values->[2]->{type
}, 'INCH', 'type is good' );
1214 is
( $unit_values->[2]->{desc
}, 'US Inches', 'desc is good' );
1215 is
( $unit_values->[2]->{value
}, 72, 'value is good' );
1216 is
( $unit_values->[2]->{selected
}, 0, 'selected is good' );
1218 isa_ok
( $unit_values->[3], 'HASH', '$unit_values->[3] is a HASH' );
1219 is
( $unit_values->[3]->{type
}, 'MM', 'type is good' );
1220 is
( $unit_values->[3]->{desc
}, 'SI Millimeters', 'desc is good' );
1221 is
( $unit_values->[3]->{value
}, 2.83464567, 'value is good' );
1222 is
( $unit_values->[3]->{selected
}, 0, 'selected is good' );
1224 isa_ok
( $unit_values->[4], 'HASH', '$unit_values->[4] is a HASH' );
1225 is
( $unit_values->[4]->{type
}, 'CM', 'type is good' );
1226 is
( $unit_values->[4]->{desc
}, 'SI Centimeters', 'desc is good' );
1227 is
( $unit_values->[4]->{value
}, 28.3464567, 'value is good' );
1228 is
( $unit_values->[4]->{selected
}, 0, 'selected is good' );
1230 # ---------- Testing get_output_formats -------------------
1231 my $output_formats = get_output_formats
();
1233 is
( @
$output_formats, 2, 'There are 2 output format' );
1234 isa_ok
( $output_formats, 'ARRAY', '$output_formats is an ARRAY' );
1236 isa_ok
( $output_formats->[0], 'HASH', '$output_formats->[0] is a HASH' );
1237 is
( $output_formats->[0]->{type
}, 'pdf', 'type is good' );
1238 is
( $output_formats->[0]->{desc
}, 'PDF File', 'name is good' );
1240 isa_ok
( $output_formats->[1], 'HASH', '$output_formats->[1] is a HASH' );
1241 is
( $output_formats->[1]->{type
}, 'csv', 'type is good' );
1242 is
( $output_formats->[1]->{desc
}, 'CSV File', 'name is good' );
1244 # ---------- Testing get_table_names ----------------------
1245 my $table_names = get_table_names
("aq");
1246 my $KOHA_PATH = C4
::Context
->config("intranetdir");
1247 my $kohastructure = "$KOHA_PATH/installer/data/mysql/kohastructure.sql";
1249 open( my $fh, '<', $kohastructure ) or die $!;
1251 my $tables_names_matching = [];
1252 while ( my $intext = <$fh> ) {
1253 while ( $intext =~ /CREATE TABLE `*\w*aq\w*`*/g ) {
1254 my @tables_names_matching = split( /\ /, $intext );
1255 if ( $tables_names_matching[2] =~ /`*`/ ) {
1256 $tables_names_matching[2] =~ s/`//g;
1258 push( @
$tables_names_matching, "$tables_names_matching[2]" );
1262 @
$tables_names_matching = sort @
$tables_names_matching;
1263 is_deeply
( $table_names, $tables_names_matching, 'get_table_names return all tables matching' );
1265 # ---------- Testing html_table ---------------------------
1266 my $display_columns = [
1267 { _label_number
=> { label
=> 'Label Number', link_field
=> 0 } },
1268 { _summary
=> { label
=> 'Summary', link_field
=> 0 } },
1269 { _item_type
=> { label
=> 'Item Type', link_field
=> 0 } },
1270 { _barcode
=> { label
=> 'Barcode', link_field
=> 1 } },
1271 { _template_code
=> { label
=> 'Template Name', link_field
=> 0 } },
1272 { select => { label
=> 'Select', value
=> '_label_id' } },
1275 #without $data param ------------------
1277 my $table = html_table
( $display_columns, $db_rows );
1278 is
( $table, undef, 'No need to generate a table if there is not data to display' );
1280 #with $data param ---------------------
1282 { _label_number
=> 1,
1283 _summary
=> $summary1,
1284 _item_type
=> 'Book',
1285 _barcode
=> $barcode1,
1286 _label_id
=> 'Label ID',
1287 template_id
=> $template_id1,
1291 $table = html_table
( $display_columns, $db_rows );
1293 isa_ok
( $table, 'ARRAY', '$table is an ARRAY' );
1296 isa_ok
( $table->[0]->{header_fields
}, 'ARRAY', '$table->[0]->{header_fields} is an ARRAY' );
1297 is
( scalar( @
{ $table->[0]->{header_fields
} } ), 6, 'There are 7 header_fields' );
1299 my $field_value = $display_columns->[0]->{_label_number
}->{label
};
1300 is
( $table->[0]->{header_fields
}->[0]->{hidden
}, 0, '[Label Number] hidden field is good' );
1301 is
( $table->[0]->{header_fields
}->[0]->{select_field
}, 0, '[Label Number] select_field field is good' );
1302 is
( $table->[0]->{header_fields
}->[0]->{field_name
}, '_label_number', '[Label Number] field_name field is good' );
1303 is
( $table->[0]->{header_fields
}->[0]->{field_label
}, $field_value, '[Label Number] field_label field is good' );
1305 $field_value = $display_columns->[1]->{_summary
}->{label
};
1306 is
( $table->[0]->{header_fields
}->[1]->{hidden
}, 0, '[Summary] hidden field is good' );
1307 is
( $table->[0]->{header_fields
}->[1]->{select_field
}, 0, '[Summary] select_field field is good' );
1308 is
( $table->[0]->{header_fields
}->[1]->{field_name
}, '_summary', '[Summary] field_name field is good' );
1309 is
( $table->[0]->{header_fields
}->[1]->{field_label
}, $field_value, '[Summary] field_label field is good' );
1311 $field_value = $display_columns->[2]->{_item_type
}->{label
};
1312 is
( $table->[0]->{header_fields
}->[2]->{hidden
}, 0, '[Item Type] hidden field is good' );
1313 is
( $table->[0]->{header_fields
}->[2]->{select_field
}, 0, '[Item Type] select_field field is good' );
1314 is
( $table->[0]->{header_fields
}->[2]->{field_name
}, '_item_type', '[Item Type] field_name field is good' );
1315 is
( $table->[0]->{header_fields
}->[2]->{field_label
}, $field_value, '[Item Type] field_label field is good' );
1317 $field_value = $display_columns->[3]->{_barcode
}->{label
};
1318 is
( $table->[0]->{header_fields
}->[3]->{hidden
}, 0, '[Barcode] hidden field is good' );
1319 is
( $table->[0]->{header_fields
}->[3]->{select_field
}, 0, '[Barcode] select_field field is good' );
1320 is
( $table->[0]->{header_fields
}->[3]->{field_name
}, '_barcode', '[Barcode] field_name field is good' );
1321 is
( $table->[0]->{header_fields
}->[3]->{field_label
}, $field_value, '[Barcode] field_label field is good' );
1323 $field_value = $display_columns->[4]->{_template_code
}->{label
};
1324 is
( $table->[0]->{header_fields
}->[4]->{hidden
}, 0, '[Template Code] hidden field is good' );
1325 is
( $table->[0]->{header_fields
}->[4]->{select_field
}, 0, '[Template Code] select_field field is good' );
1326 is
( $table->[0]->{header_fields
}->[4]->{field_name
}, '_template_code', '[Template Code] field_name field is good' );
1327 is
( $table->[0]->{header_fields
}->[4]->{field_label
}, $field_value, '[Template Code] field_label field is good' );
1329 $field_value = $display_columns->[5]->{select}->{label
};
1330 is
( $table->[0]->{header_fields
}->[5]->{hidden
}, 0, '[Select] hidden field is good' );
1331 is
( $table->[0]->{header_fields
}->[5]->{select_field
}, 0, '[Select] select_field field is good' );
1332 is
( $table->[0]->{header_fields
}->[5]->{field_name
}, 'select', '[Select] field_name field is good' );
1333 is
( $table->[0]->{header_fields
}->[5]->{field_label
}, $field_value, '[Select] field_label field is good' );
1336 isa_ok
( $table->[1]->{text_fields
}, 'ARRAY', '$table->[0]->{text_fields} is an ARRAY' );
1337 is
( scalar( @
{ $table->[1]->{text_fields
} } ), 6, 'There are 6 text_fields' );
1339 #test : if (grep {$table_column eq $_} keys %$db_row)
1340 my $link_field = $display_columns->[0]->{_label_number
}->{link_field
};
1341 my $field_name = "$table->[0]->{header_fields}->[0]->{field_name}_tbl";
1342 $field_value = $db_rows->[0]->{_label_number
};
1343 is
( $table->[1]->{text_fields
}->[0]->{hidden
}, 0, '[Label Number] hidden field is good' );
1344 is
( $table->[1]->{text_fields
}->[0]->{link_field
}, $link_field, '[Label Number] link_field field is good' );
1345 is
( $table->[1]->{text_fields
}->[0]->{select_field
}, 0, '[Label Number] select_field field is good' );
1346 is
( $table->[1]->{text_fields
}->[0]->{field_name
}, $field_name, '[Label Number] field_name field is good' );
1347 is
( $table->[1]->{text_fields
}->[0]->{field_value
}, $field_value, '[Label Number] field_value field is good' );
1349 $link_field = $display_columns->[1]->{_summary
}->{link_field
};
1350 $field_value = $db_rows->[0]->{_summary
};
1351 $field_name = "$table->[0]->{header_fields}->[1]->{field_name}_tbl";
1352 is
( $table->[1]->{text_fields
}->[1]->{hidden
}, 0, '[Summary] hidden field is good' );
1353 is
( $table->[1]->{text_fields
}->[1]->{link_field
}, $link_field, '[Summary] link_field field is good' );
1354 is
( $table->[1]->{text_fields
}->[1]->{select_field
}, 0, '[Summary] select_field field is good' );
1355 is
( $table->[1]->{text_fields
}->[1]->{field_name
}, $field_name, '[Summary] field_name field is good' );
1356 is
( $table->[1]->{text_fields
}->[1]->{field_value
}, $field_value, '[Summary] field_value field is good' );
1358 $link_field = $display_columns->[2]->{_item_type
}->{link_field
};
1359 $field_name = "$table->[0]->{header_fields}->[2]->{field_name}_tbl";
1360 $field_value = $db_rows->[0]->{_item_type
};
1361 is
( $table->[1]->{text_fields
}->[2]->{hidden
}, 0, '[Item Type] hidden field is good' );
1362 is
( $table->[1]->{text_fields
}->[2]->{link_field
}, $link_field, '[Item Type] link_field field is good' );
1363 is
( $table->[1]->{text_fields
}->[2]->{select_field
}, 0, '[Item Type] select_field field is good' );
1364 is
( $table->[1]->{text_fields
}->[2]->{field_name
}, $field_name, '[Item Type] field_name field is good' );
1365 is
( $table->[1]->{text_fields
}->[2]->{field_value
}, $field_value, '[Item Type] field_value field is good' );
1367 $link_field = $display_columns->[3]->{_barcode
}->{link_field
};
1368 $field_name = "$table->[0]->{header_fields}->[3]->{field_name}_tbl";
1369 $field_value = $db_rows->[0]->{_barcode
};
1370 is
( $table->[1]->{text_fields
}->[3]->{hidden
}, 0, '[Barcode] hidden field is good' );
1371 is
( $table->[1]->{text_fields
}->[3]->{link_field
}, $link_field, '[Barcode] link_field field is good' );
1372 is
( $table->[1]->{text_fields
}->[3]->{select_field
}, 0, '[Barcode] select_field field is good' );
1373 is
( $table->[1]->{text_fields
}->[3]->{field_name
}, $field_name, '[Barcode] field_name field is good' );
1374 is
( $table->[1]->{text_fields
}->[3]->{field_value
}, $field_value, '[Barcode] field_value field is good' );
1376 #test : elsif ($table_column =~ m/^_((.*)_(.*$))/)
1377 $link_field = $display_columns->[4]->{_template_code
}->{link_field
};
1378 $field_name = "$table->[0]->{header_fields}->[4]->{field_name}_tbl";
1379 is
( $table->[1]->{text_fields
}->[4]->{hidden
}, 0, '[Template Code] hidden field is good' );
1380 is
( $table->[1]->{text_fields
}->[4]->{link_field
}, $link_field, '[Template Code] link_field field is good' );
1381 is
( $table->[1]->{text_fields
}->[4]->{select_field
}, 0, '[Template Code] select_field field is good' );
1382 is
( $table->[1]->{text_fields
}->[4]->{field_name
}, $field_name, '[Template Code] field_name field is good' );
1383 is
( $table->[1]->{text_fields
}->[4]->{field_value
}, $template_code1, '[Template Code] field_value field is good' );
1385 #test : elsif ($table_column eq 'select')
1386 $field_value = $db_rows->[0]->{_label_id
};
1387 is
( $table->[1]->{text_fields
}->[5]->{hidden
}, 0, '[Select] hidden field is good' );
1388 is
( $table->[1]->{text_fields
}->[5]->{select_field
}, 1, '[Select] select_field field is good' );
1389 is
( $table->[1]->{text_fields
}->[5]->{field_name
}, 'select', '[Select] field_name field is good' );
1390 is
( $table->[1]->{text_fields
}->[5]->{field_value
}, $field_value, '[Select] field_value field is good' );
1392 # ---------- Testing _SELECT ---------------------------
1393 # Mocking $sth->err and $sth->errstr
1395 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
1396 $dbi_st->mock( 'err', sub { return 1; } );
1397 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
1399 warning_is
{ $records = C4
::Creators
::Lib
::_SELECT
( '*', 'borrowers', "borrowernumber = $borrowernumber1" ) } 'Database returned the following error: something went wrong',
1400 '_SELECT raises warning if something went wrong with the sql request execution';
1402 is
( $records, 1, '$record return 1' );
1405 #without $params[2] -------------------
1406 my $records = C4
::Creators
::Lib
::_SELECT
( 'surname, firstname, cardnumber, branchcode, categorycode', 'borrowers' );
1408 is
( @
$records, 3, 'There are 3 borrowers' );
1409 isa_ok
( $records, 'ARRAY', '$records is an ARRAY' );
1411 isa_ok
( $records->[0], 'HASH', '$records->[0] is a HASH' );
1412 is
( $records->[0]->{surname
}, $surname1, 'surname is good' );
1413 is
( $records->[0]->{firstname
}, $firstname1, 'firstname is good' );
1414 is
( $records->[0]->{cardnumber
}, $cardnumber1, 'cardnumber is good' );
1415 is
( $records->[0]->{branchcode
}, $branchcode, 'branchcode is good' );
1416 is
( $records->[0]->{categorycode
}, $categorycode, 'categorycode is good' );
1418 isa_ok
( $records->[1], 'HASH', '$records->[1] is a HASH' );
1419 is
( $records->[1]->{surname
}, $surname2, 'surname is good' );
1420 is
( $records->[1]->{firstname
}, $firstname2, 'firstname is good' );
1421 is
( $records->[1]->{cardnumber
}, $cardnumber2, 'cardnumber is good' );
1422 is
( $records->[1]->{branchcode
}, $branchcode, 'branchcode is good' );
1423 is
( $records->[1]->{categorycode
}, $categorycode, 'categorycode is good' );
1425 isa_ok
( $records->[2], 'HASH', '$records->[2] is a HASH' );
1426 is
( $records->[2]->{surname
}, $surname3, 'surname is good' );
1427 is
( $records->[2]->{firstname
}, $firstname3, 'firstname is good' );
1428 is
( $records->[2]->{cardnumber
}, $cardnumber3, 'cardnumber is good' );
1429 is
( $records->[2]->{branchcode
}, $branchcode, 'branchcode is good' );
1430 is
( $records->[2]->{categorycode
}, $categorycode, 'categorycode is good' );
1432 #with $params[2] ----------------------
1433 $records = C4
::Creators
::Lib
::_SELECT
( 'surname, firstname, cardnumber, branchcode, categorycode', 'borrowers', "borrowernumber = $borrowernumber1" );
1435 is
( @
$records, 1, 'There is 1 borrower where borrowernumber = $borrowernumber1' );
1436 isa_ok
( $records, 'ARRAY', '$records is an ARRAY' );
1438 isa_ok
( $records->[0], 'HASH', '$records->[0] is a HASH' );
1439 is
( $records->[0]->{surname
}, $surname1, 'surname is good' );
1440 is
( $records->[0]->{firstname
}, $firstname1, 'firstname is good' );
1441 is
( $records->[0]->{cardnumber
}, $cardnumber1, 'cardnumber is good' );
1442 is
( $records->[0]->{branchcode
}, $branchcode, 'branchcode is good' );
1443 is
( $records->[0]->{categorycode
}, $categorycode, 'categorycode is good' );
1445 subtest
'_add_backtics' => sub {
1447 my @a = ( 'rows', 'rows ', ' rows ', 'table.rows,field2', 'table.field1, table.field_2_a', 'table1.*, *', 'COUNT(id) AS mycount, count(*) as mycount2' );
1448 my @a_exp = ( '`rows`', '`rows` ', ' `rows` ', '`table`.`rows`,`field2`', '`table`.`field1`, `table`.`field_2_a`', '`table1`.*, *', 'COUNT(`id`) AS `mycount`, COUNT(*) AS `mycount2`' ); # expected results
1449 my @b = C4
::Creators
::Lib
::_add_backtics
(@a);
1450 while( my $f = shift @a_exp ) {
1451 is
( shift @b, $f, (shift @a). ' became '. $f );
1455 # ---------- Sub ------------------------------------------
1458 sub mock_preference
{
1459 my $context = new Test
::MockModule
('C4::Context');
1460 my ( $pref, $value ) = @_;
1461 $preferences{$pref} = $value;
1465 my ( $self, $pref ) = @_;
1466 if ( exists $preferences{$pref} ) {
1467 return $preferences{$pref};
1469 my $method = $context->original('preference');
1470 return $method->( $self, $pref );