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
=> 644;
27 use_ok
('C4::Creators::Lib');
29 use_ok
('C4::Context');
30 use_ok
('Koha::Borrower');
31 use_ok
('MARC::Record');
35 'C4::Creators::Lib', qw(
46 get_text_justification_types
53 my $dbh = C4
::Context
->dbh;
54 $dbh->{AutoCommit
} = 0;
55 $dbh->{RaiseError
} = 1;
56 $dbh->do('DELETE FROM creator_templates');
57 $dbh->do('DELETE FROM creator_layouts');
58 $dbh->do('DELETE FROM creator_images');
59 $dbh->do('DELETE FROM creator_batches');
60 $dbh->do('DELETE FROM printers_profile');
61 $dbh->do('DELETE FROM borrowers');
62 $dbh->do('DELETE FROM items');
63 $dbh->do('DELETE FROM biblioitems');
65 ###########################################################
67 ###########################################################
69 # ---------- Some Templates --------------------
71 INSERT INTO creator_templates
72 (profile_id , template_code, template_desc, page_width,
73 page_height , label_width , label_height , top_text_margin,
74 left_text_margin, top_margin , left_margin , cols,
75 rows , col_gap , row_gap , units,
77 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
78 my $insert_sth = $dbh->prepare($query);
79 $insert_sth->execute( 1, 'TEMPL1', 'Template 1', 100, 150, 10, 15, 2, 3, 1, 4, 9, 6, 0.1, 0.2, 'POINT', 'Labels' );
81 $insert_sth->execute( 2, 'TEMPL2', 'Template 2', 101, 151, 11, 16, 3, 4, 2, 5, 10, 7, 0.2, 0.3, 'POINT', 'Labels' );
83 SELECT template_id, template_code
84 FROM creator_templates
87 my ( $template_id1, $template_code1 ) = $dbh->selectrow_array( $query, {}, 1 );
89 # ---------- Some Layouts -----------------------
91 INSERT INTO creator_layouts
92 (barcode_type , start_label , printing_type, layout_name,
93 guidebox , font , font_size , units ,
94 callnum_split , text_justify, format_string, layout_xml ,
96 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)';
97 $insert_sth = $dbh->prepare($query);
98 $insert_sth->execute( 'COOP2OF5', 1, 'BAR1', 'NAME1', 1, 'TR', 11, 'POINT', 1, 'L', 'barcode', 'layout_xml1', 'Labels' );
100 $insert_sth->execute( 'EAN13', 2, 'BAR2', 'NAME2', 2, 'TR', 12, 'POINT', 2, 'L', 'barcode', 'layout_xml2', 'Labels' );
102 # ---------- Some Printers ---------------------
104 INSERT INTO printers_profile
105 (printer_name, template_id, paper_bin,
106 offset_horz , offset_vert, creep_horz,
107 creep_vert , units , creator)
108 VALUES (?,?,?,?,?,?,?,?,?)';
109 $insert_sth = $dbh->prepare($query);
110 $insert_sth->execute( 'Layout1 Name', 1234, 'Bypass', 0.1, 0.2, 0.3, 0.4, 'POINT', 'Labels' );
112 $insert_sth->execute( 'Layout2 Name', 1235, 'Bypass', 0.2, 0.3, 0.4, 0.5, 'POINT', 'Labels' );
114 # ---------- Some Images -----------------------
115 my $image1 = Graphics
::Magick
->new;
116 my $image2 = Graphics
::Magick
->new;
119 INSERT INTO creator_images
120 (imagefile, image_name)
122 $insert_sth = $dbh->prepare($query);
123 $insert_sth->execute( "$image1->ImageToBlob()", 'Image 1' );
124 $insert_sth->execute( "$image2->ImageToBlob()", 'Image 2' );
126 # ---------- Some biblios -----------------------
127 my $title1 = 'Title 1';
128 my $title2 = 'Title 2';
129 my $title3 = 'Title 3';
130 my $author1 = 'Author 1';
131 my $author2 = 'Author 2';
132 my $author3 = 'Author 3';
138 $insert_sth = $dbh->prepare($query);
139 $insert_sth->execute( $title1, $author1 );
140 $insert_sth->execute( $title2, undef );
141 $insert_sth->execute( $title3, $author3 );
147 my $biblionumber1 = $dbh->selectrow_array( $query, {}, $title1 );
148 my $biblionumber2 = $dbh->selectrow_array( $query, {}, $title2 );
149 my $biblionumber3 = $dbh->selectrow_array( $query, {}, $title3 );
151 # ---------- Some biblio items -------------------------
153 INSERT INTO biblioitems
154 (biblionumber, itemtype)
156 $insert_sth = $dbh->prepare($query);
157 $insert_sth->execute( $biblionumber1, 'Book' );
158 $insert_sth->execute( $biblionumber2, 'Music' );
159 $insert_sth->execute( $biblionumber3, 'Book' );
162 SELECT biblioitemnumber
164 WHERE biblionumber = ?';
165 my $biblioitemnumber1 = $dbh->selectrow_array( $query, {}, $biblionumber1 );
166 my $biblioitemnumber2 = $dbh->selectrow_array( $query, {}, $biblionumber2 );
167 my $biblioitemnumber3 = $dbh->selectrow_array( $query, {}, $biblionumber3 );
169 # ---------- Some items -------------------------
170 my $barcode1 = '111111';
171 my $barcode2 = '222222';
172 my $barcode3 = '333333';
176 (biblionumber, biblioitemnumber, barcode, itype)
178 $insert_sth = $dbh->prepare($query);
179 $insert_sth->execute( $biblionumber1, $biblioitemnumber1, $barcode1, 'Book' );
180 $insert_sth->execute( $biblionumber2, $biblioitemnumber2, $barcode2, 'Music' );
181 $insert_sth->execute( $biblionumber3, $biblioitemnumber3, $barcode3, 'Book' );
187 my $item_number1 = $dbh->selectrow_array( $query, {}, $barcode1 );
188 my $item_number2 = $dbh->selectrow_array( $query, {}, $barcode2 );
189 my $item_number3 = $dbh->selectrow_array( $query, {}, $barcode3 );
191 # ---------- Some borrowers ---------------------
192 my $surname1 = 'Borrower 1';
193 my $surname2 = 'Borrower 2';
194 my $surname3 = 'Borrower 3';
195 my $firstname1 = 'firstname 1';
196 my $firstname2 = 'firstname 2';
197 my $firstname3 = 'firstname 3';
198 my $cardnumber1 = '00001';
199 my $cardnumber2 = '00002';
200 my $cardnumber3 = '00003';
201 my $categorycode = Koha
::Database
->new()->schema()->resultset('Category')->first()->categorycode();
202 my $branchcode = Koha
::Database
->new()->schema()->resultset('Branch')->first()->branchcode();
205 INSERT INTO borrowers
206 (surname, firstname, cardnumber, branchcode, categorycode)
208 $insert_sth = $dbh->prepare($query);
209 $insert_sth->execute( $surname1, $firstname1, $cardnumber1, $branchcode, $categorycode );
210 $insert_sth->execute( $surname2, $firstname2, $cardnumber2, $branchcode, $categorycode );
211 $insert_sth->execute( $surname3, $firstname3, $cardnumber3, $branchcode, $categorycode );
214 SELECT borrowernumber
217 my $borrowernumber1 = $dbh->selectrow_array( $query, {}, $surname1 );
218 my $borrowernumber2 = $dbh->selectrow_array( $query, {}, $surname2 );
219 my $borrowernumber3 = $dbh->selectrow_array( $query, {}, $surname3 );
221 # ---------- Some batches -----------------------
223 INSERT INTO creator_batches
224 (batch_id , item_number, borrower_number,
225 timestamp, branch_code, creator)
226 VALUES (?,?,?,?,?,?)';
227 $insert_sth = $dbh->prepare($query);
228 $insert_sth->execute( 11, $item_number1, $borrowernumber1, 'now()', 'CPL', 'Labels' );
230 $insert_sth->execute( 12, $item_number2, $borrowernumber2, 'now()', 'MPL', 'Labels' );
232 $insert_sth->execute( 12, $item_number3, $borrowernumber3, 'now()', 'PVL', 'Labels' );
234 ###########################################################
236 ###########################################################
238 # ---------- Testing get_all_templates --------------------
239 # Mocking $sth->err and $sth->errstr
241 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
242 $dbi_st->mock( 'err', sub { return 1; } );
243 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
245 warning_is
{ $templates = get_all_templates
() } 'Database returned the following error: something went wrong',
246 'get_all_templates() raises warning if something went wrong with the sql request execution';
248 is
( $templates, -1, '$templates return -1' );
251 # Without params ----------------------
252 my $templates = get_all_templates
();
256 FROM creator_templates
258 my $count = $dbh->selectrow_array($query);
259 is
( $count, 2, 'There are 2 templates' );
260 is
( @
$templates, $count, 'There are 2 templates matching' );
261 isa_ok
( $templates, 'ARRAY', '$templates is an ARRAY' );
263 isa_ok
( $templates->[0], 'HASH', '$templates->[0] is a HASH' );
264 is
( $templates->[0]->{profile_id
}, 1, 'profile_id is good' );
265 is
( $templates->[0]->{template_code
}, 'TEMPL1', 'template_code is good' );
266 is
( $templates->[0]->{template_desc
}, 'Template 1', 'template_desc is good' );
267 is
( $templates->[0]->{page_width
}, 100, 'page_width is good' );
268 is
( $templates->[0]->{page_height
}, 150, 'page_height is good' );
269 is
( $templates->[0]->{label_width
}, 10, 'label_width is good' );
270 is
( $templates->[0]->{label_height
}, 15, 'label_height is good' );
271 is
( $templates->[0]->{top_text_margin
}, 2, 'top_text_margin is good' );
272 is
( $templates->[0]->{left_text_margin
}, 3, 'left_text_margin is good' );
273 is
( $templates->[0]->{top_margin
}, 1, 'top_margin is good' );
274 is
( $templates->[0]->{left_margin
}, 4, 'left_margin is good' );
275 is
( $templates->[0]->{cols
}, 9, 'cols is good' );
276 is
( $templates->[0]->{rows
}, 6, 'rows is good' );
277 is
( $templates->[0]->{col_gap
}, 0.1, 'col_gap is good' );
278 is
( $templates->[0]->{row_gap
}, 0.2, 'row_gap is good' );
279 is
( $templates->[0]->{units
}, 'POINT', 'units is good' );
280 is
( $templates->[0]->{creator
}, 'Labels', 'creator is good' );
282 isa_ok
( $templates->[1], 'HASH', '$templates->[1] is a HASH' );
283 is
( $templates->[1]->{profile_id
}, 2, 'profile_id is good' );
284 is
( $templates->[1]->{template_code
}, 'TEMPL2', 'template_code is good' );
285 is
( $templates->[1]->{template_desc
}, 'Template 2', 'template_desc is good' );
286 is
( $templates->[1]->{page_width
}, 101, 'page_width is good' );
287 is
( $templates->[1]->{page_height
}, 151, 'page_height is good' );
288 is
( $templates->[1]->{label_width
}, 11, 'label_width is good' );
289 is
( $templates->[1]->{label_height
}, 16, 'label_height is good' );
290 is
( $templates->[1]->{top_text_margin
}, 3, 'top_text_margin is good' );
291 is
( $templates->[1]->{left_text_margin
}, 4, 'left_text_margin is good' );
292 is
( $templates->[1]->{top_margin
}, 2, 'top_margin is good' );
293 is
( $templates->[1]->{left_margin
}, 5, 'left_margin is good' );
294 is
( $templates->[1]->{cols
}, 10, 'cols is good' );
295 is
( $templates->[1]->{rows
}, 7, 'rows is good' );
296 is
( $templates->[1]->{col_gap
}, 0.2, 'col_gap is good' );
297 is
( $templates->[1]->{row_gap
}, 0.3, 'row_gap is good' );
298 is
( $templates->[1]->{units
}, 'POINT', 'units is good' );
299 is
( $templates->[1]->{creator
}, 'Labels', 'creator is good' );
301 # With field_list params --------------
302 $templates = get_all_templates
( field_list
=> 'units, cols, rows' );
306 FROM creator_templates
308 $count = $dbh->selectrow_array($query);
309 is
( $count, 2, 'There are 2 templates' );
310 is
( @
$templates, $count, 'There are 2 templates matching' );
311 isa_ok
( $templates, 'ARRAY', '$templates is an ARRAY' );
313 isa_ok
( $templates->[0], 'HASH', '$templates->[0] is a HASH' );
314 isnt
( exists $templates->[0]->{profile_id
}, 1, 'profile_id is good' );
315 isnt
( exists $templates->[0]->{template_code
}, 'TEMPL1', 'template_code is good' );
316 isnt
( exists $templates->[0]->{template_desc
}, 'Template 1', 'template_desc is good' );
317 isnt
( exists $templates->[0]->{page_width
}, 100, 'page_width is good' );
318 isnt
( exists $templates->[0]->{page_height
}, 150, 'page_height is good' );
319 isnt
( exists $templates->[0]->{label_width
}, 10, 'label_width is good' );
320 isnt
( exists $templates->[0]->{label_height
}, 15, 'label_height is good' );
321 isnt
( exists $templates->[0]->{top_text_margin
}, 2, 'top_text_margin is good' );
322 isnt
( exists $templates->[0]->{left_text_margin
}, 3, 'left_text_margin is good' );
323 isnt
( exists $templates->[0]->{top_margin
}, 1, 'top_margin is good' );
324 isnt
( exists $templates->[0]->{left_margin
}, 4, 'left_margin is good' );
325 is
( $templates->[0]->{cols
}, 9, 'cols is good' );
326 is
( $templates->[0]->{rows
}, 6, 'rows is good' );
327 isnt
( exists $templates->[0]->{col_gap
}, 0.1, 'col_gap is good' );
328 isnt
( exists $templates->[0]->{row_gap
}, 0.2, 'row_gap is good' );
329 is
( $templates->[0]->{units
}, 'POINT', 'units is good' );
330 isnt
( exists $templates->[0]->{creator
}, 'Labels', 'creator is good' );
332 isa_ok
( $templates->[1], 'HASH', '$templates->[1] is a HASH' );
333 isnt
( exists $templates->[1]->{profile_id
}, 2, 'profile_id is good' );
334 isnt
( exists $templates->[1]->{template_code
}, 'TEMPL2', 'template_code is good' );
335 isnt
( exists $templates->[1]->{template_desc
}, 'Template 2', 'template_desc is good' );
336 isnt
( exists $templates->[1]->{page_width
}, 101, 'page_width is good' );
337 isnt
( exists $templates->[1]->{page_height
}, 151, 'page_height is good' );
338 isnt
( exists $templates->[1]->{label_width
}, 11, 'label_width is good' );
339 isnt
( exists $templates->[1]->{label_height
}, 16, 'label_height is good' );
340 isnt
( exists $templates->[1]->{top_text_margin
}, 3, 'top_text_margin is good' );
341 isnt
( exists $templates->[1]->{left_text_margin
}, 4, 'left_text_margin is good' );
342 isnt
( exists $templates->[1]->{top_margin
}, 2, 'top_margin is good' );
343 isnt
( exists $templates->[1]->{left_margin
}, 5, 'left_margin is good' );
344 is
( $templates->[1]->{cols
}, 10, 'cols is good' );
345 is
( $templates->[1]->{rows
}, 7, 'rows is good' );
346 isnt
( exists $templates->[1]->{col_gap
}, 0.2, 'col_gap is good' );
347 isnt
( exists $templates->[1]->{row_gap
}, 0.3, 'row_gap is good' );
348 is
( $templates->[1]->{units
}, 'POINT', 'units is good' );
349 isnt
( exists $templates->[1]->{creator
}, 'Labels', 'creator is good' );
351 # With filter params ------------------
352 $templates = get_all_templates
( filter
=> 'rows = 7' );
356 FROM creator_templates
359 $count = $dbh->selectrow_array($query);
360 is
( $count, 1, 'There is 1 template matching' );
361 is
( @
$templates, $count, 'There is 1 template matching' );
362 isa_ok
( $templates, 'ARRAY', '$templates is an ARRAY' );
364 isa_ok
( $templates->[0], 'HASH', '$templates->[0] is a HASH' );
365 is
( $templates->[0]->{profile_id
}, 2, 'profile_id is good' );
366 is
( $templates->[0]->{template_code
}, 'TEMPL2', 'template_code is good' );
367 is
( $templates->[0]->{template_desc
}, 'Template 2', 'template_desc is good' );
368 is
( $templates->[0]->{page_width
}, 101, 'page_width is good' );
369 is
( $templates->[0]->{page_height
}, 151, 'page_height is good' );
370 is
( $templates->[0]->{label_width
}, 11, 'label_width is good' );
371 is
( $templates->[0]->{label_height
}, 16, 'label_height is good' );
372 is
( $templates->[0]->{top_text_margin
}, 3, 'top_text_margin is good' );
373 is
( $templates->[0]->{left_text_margin
}, 4, 'left_text_margin is good' );
374 is
( $templates->[0]->{top_margin
}, 2, 'top_margin is good' );
375 is
( $templates->[0]->{left_margin
}, 5, 'left_margin is good' );
376 is
( $templates->[0]->{cols
}, 10, 'cols is good' );
377 is
( $templates->[0]->{rows
}, 7, 'rows is good' );
378 is
( $templates->[0]->{col_gap
}, 0.2, 'col_gap is good' );
379 is
( $templates->[0]->{row_gap
}, 0.3, 'row_gap is good' );
380 is
( $templates->[0]->{units
}, 'POINT', 'units is good' );
381 is
( $templates->[0]->{creator
}, 'Labels', 'creator is good' );
383 # With orderby param ------------------
384 $templates = get_all_templates
( orderby
=> 'rows DESC' );
388 FROM creator_templates
391 $count = $dbh->selectrow_array($query);
392 is
( $count, 2, 'There are 2 templates' );
393 is
( @
$templates, $count, 'There are 2 templates matching' );
394 isa_ok
( $templates, 'ARRAY', '$templates is an ARRAY' );
396 isa_ok
( $templates->[0], 'HASH', '$templates->[0] is a HASH' );
397 is
( $templates->[0]->{profile_id
}, 2, 'profile_id is good' );
398 is
( $templates->[0]->{template_code
}, 'TEMPL2', 'template_code is good' );
399 is
( $templates->[0]->{template_desc
}, 'Template 2', 'template_desc is good' );
400 is
( $templates->[0]->{page_width
}, 101, 'page_width is good' );
401 is
( $templates->[0]->{page_height
}, 151, 'page_height is good' );
402 is
( $templates->[0]->{label_width
}, 11, 'label_width is good' );
403 is
( $templates->[0]->{label_height
}, 16, 'label_height is good' );
404 is
( $templates->[0]->{top_text_margin
}, 3, 'top_text_margin is good' );
405 is
( $templates->[0]->{left_text_margin
}, 4, 'left_text_margin is good' );
406 is
( $templates->[0]->{top_margin
}, 2, 'top_margin is good' );
407 is
( $templates->[0]->{left_margin
}, 5, 'left_margin is good' );
408 is
( $templates->[0]->{cols
}, 10, 'cols is good' );
409 is
( $templates->[0]->{rows
}, 7, 'rows is good' );
410 is
( $templates->[0]->{col_gap
}, 0.2, 'col_gap is good' );
411 is
( $templates->[0]->{row_gap
}, 0.3, 'row_gap is good' );
412 is
( $templates->[0]->{units
}, 'POINT', 'units is good' );
413 is
( $templates->[0]->{creator
}, 'Labels', 'creator is good' );
415 isa_ok
( $templates->[1], 'HASH', '$templates->[1] is a HASH' );
416 is
( $templates->[1]->{profile_id
}, 1, 'profile_id is good' );
417 is
( $templates->[1]->{template_code
}, 'TEMPL1', 'template_code is good' );
418 is
( $templates->[1]->{template_desc
}, 'Template 1', 'template_desc is good' );
419 is
( $templates->[1]->{page_width
}, 100, 'page_width is good' );
420 is
( $templates->[1]->{page_height
}, 150, 'page_height is good' );
421 is
( $templates->[1]->{label_width
}, 10, 'label_width is good' );
422 is
( $templates->[1]->{label_height
}, 15, 'label_height is good' );
423 is
( $templates->[1]->{top_text_margin
}, 2, 'top_text_margin is good' );
424 is
( $templates->[1]->{left_text_margin
}, 3, 'left_text_margin is good' );
425 is
( $templates->[1]->{top_margin
}, 1, 'top_margin is good' );
426 is
( $templates->[1]->{left_margin
}, 4, 'left_margin is good' );
427 is
( $templates->[1]->{cols
}, 9, 'cols is good' );
428 is
( $templates->[1]->{rows
}, 6, 'rows is good' );
429 is
( $templates->[1]->{col_gap
}, 0.1, 'col_gap is good' );
430 is
( $templates->[1]->{row_gap
}, 0.2, 'row_gap is good' );
431 is
( $templates->[1]->{units
}, 'POINT', 'units is good' );
432 is
( $templates->[1]->{creator
}, 'Labels', 'creator is good' );
434 # ---------- Testing get_all_layouts ----------------------
435 # Mocking $sth->err and $sth->errstr
437 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
438 $dbi_st->mock( 'err', sub { return 1; } );
439 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
441 warning_is
{ $layouts = get_all_layouts
() } 'Database returned the following error: something went wrong',
442 'get_all_layouts() raises warning if something went wrong with the sql request execution';
444 is
( $layouts, -1, '$layouts return -1' );
447 # Without params ----------------------
448 my $layouts = get_all_layouts
();
454 $count = $dbh->selectrow_array($query);
455 is
( $count, 2, 'There are 2 layouts' );
456 is
( @
$layouts, $count, 'There are 2 layouts matching' );
457 isa_ok
( $layouts, 'ARRAY', '$layouts is an ARRAY' );
459 isa_ok
( $layouts->[0], 'HASH', '$layouts->[0] is a HASH' );
460 is
( $layouts->[0]->{barcode_type
}, 'COOP2OF5', 'barcode_type is good' );
461 is
( $layouts->[0]->{start_label
}, 1, 'start_label is good' );
462 is
( $layouts->[0]->{printing_type
}, 'BAR1', 'printing_type is good' );
463 is
( $layouts->[0]->{layout_name
}, 'NAME1', 'layout_name is good' );
464 is
( $layouts->[0]->{guidebox
}, 1, 'guidebox is good' );
465 is
( $layouts->[0]->{font
}, 'TR', 'font is good' );
466 is
( $layouts->[0]->{font_size
}, 11, 'font_size is good' );
467 is
( $layouts->[0]->{units
}, 'POINT', 'units is good' );
468 is
( $layouts->[0]->{callnum_split
}, 1, 'callnum_split is good' );
469 is
( $layouts->[0]->{text_justify
}, 'L', 'text_justify is good' );
470 is
( $layouts->[0]->{format_string
}, 'barcode', 'format_string is good' );
471 is
( $layouts->[0]->{layout_xml
}, 'layout_xml1', 'layout_xml is good' );
472 is
( $layouts->[0]->{creator
}, 'Labels', 'creator is good' );
474 isa_ok
( $layouts->[1], 'HASH', '$layouts->[1] is a HASH' );
475 is
( $layouts->[1]->{barcode_type
}, 'EAN13', 'barcode_type is good' );
476 is
( $layouts->[1]->{start_label
}, 2, 'start_label is good' );
477 is
( $layouts->[1]->{printing_type
}, 'BAR2', 'printing_type is good' );
478 is
( $layouts->[1]->{layout_name
}, 'NAME2', 'layout_name is good' );
479 is
( $layouts->[1]->{guidebox
}, 2, 'guidebox is good' );
480 is
( $layouts->[1]->{font
}, 'TR', 'font is good' );
481 is
( $layouts->[1]->{font_size
}, 12, 'font_size is good' );
482 is
( $layouts->[1]->{units
}, 'POINT', 'units is good' );
483 is
( $layouts->[1]->{callnum_split
}, 2, 'callnum_split is good' );
484 is
( $layouts->[1]->{text_justify
}, 'L', 'text_justify is good' );
485 is
( $layouts->[1]->{format_string
}, 'barcode', 'format_string is good' );
486 is
( $layouts->[1]->{layout_xml
}, 'layout_xml2', 'layout_xml is good' );
487 is
( $layouts->[1]->{creator
}, 'Labels', 'creator is good' );
489 # With field_list params --------------
490 $layouts = get_all_layouts
( field_list
=> 'barcode_type, layout_name, font' );
496 $count = $dbh->selectrow_array($query);
497 is
( $count, 2, 'There are 2 layouts' );
498 is
( @
$layouts, $count, 'There are 2 layouts matching' );
499 isa_ok
( $layouts, 'ARRAY', '$layouts is an ARRAY' );
501 isa_ok
( $layouts->[0], 'HASH', '$layouts->[0] is a HASH' );
502 is
( $layouts->[0]->{barcode_type
}, 'COOP2OF5', 'barcode_type is good' );
503 isnt
( exists $layouts->[0]->{start_label
}, 1, 'start_label is good' );
504 isnt
( exists $layouts->[0]->{printing_type
}, 'BAR1', 'printing_type is good' );
505 is
( $layouts->[0]->{layout_name
}, 'NAME1', 'layout_name is good' );
506 isnt
( exists $layouts->[0]->{guidebox
}, 1, 'guidebox is good' );
507 is
( $layouts->[0]->{font
}, 'TR', 'font is good' );
508 isnt
( exists $layouts->[0]->{font_size
}, 11, 'font_size is good' );
509 isnt
( exists $layouts->[0]->{units
}, 'POINT', 'units is good' );
510 isnt
( exists $layouts->[0]->{callnum_split
}, 1, 'callnum_split is good' );
511 isnt
( exists $layouts->[0]->{text_justify
}, 'L', 'text_justify is good' );
512 isnt
( exists $layouts->[0]->{format_string
}, 'barcode', 'format_string is good' );
513 isnt
( exists $layouts->[0]->{layout_xml
}, 'layout_xml1', 'layout_xml is good' );
514 isnt
( exists $layouts->[0]->{creator
}, 'Labels', 'creator is good' );
516 isa_ok
( $layouts->[1], 'HASH', '$layouts->[1] is a HASH' );
517 is
( $layouts->[1]->{barcode_type
}, 'EAN13', 'barcode_type is good' );
518 isnt
( exists $layouts->[1]->{start_label
}, 2, 'start_label is good' );
519 isnt
( exists $layouts->[1]->{printing_type
}, 'BAR2', 'printing_type is good' );
520 is
( $layouts->[1]->{layout_name
}, 'NAME2', 'layout_name is good' );
521 isnt
( exists $layouts->[1]->{guidebox
}, 2, 'guidebox is good' );
522 is
( $layouts->[1]->{font
}, 'TR', 'font is good' );
523 isnt
( exists $layouts->[1]->{font_size
}, 12, 'font_size is good' );
524 isnt
( exists $layouts->[1]->{units
}, 'POINT', 'units is good' );
525 isnt
( exists $layouts->[1]->{callnum_split
}, 2, 'callnum_split is good' );
526 isnt
( exists $layouts->[1]->{text_justify
}, 'L', 'text_justify is good' );
527 isnt
( exists $layouts->[1]->{format_string
}, 'barcode', 'format_string is good' );
528 isnt
( exists $layouts->[1]->{layout_xml
}, 'layout_xml2', 'layout_xml is good' );
529 isnt
( exists $layouts->[1]->{creator
}, 'Labels', 'creator is good' );
531 # With filter params ------------------
532 $layouts = get_all_layouts
( filter
=> 'font_size = 12' );
539 $count = $dbh->selectrow_array($query);
540 is
( $count, 1, 'There is 1 layout matching' );
541 is
( @
$layouts, $count, 'There is 1 layout matching' );
542 isa_ok
( $layouts, 'ARRAY', '$layouts is an ARRAY' );
544 isa_ok
( $layouts->[0], 'HASH', '$layouts->[0] is a HASH' );
545 is
( $layouts->[0]->{barcode_type
}, 'EAN13', 'barcode_type is good' );
546 is
( $layouts->[0]->{start_label
}, 2, 'start_label is good' );
547 is
( $layouts->[0]->{printing_type
}, 'BAR2', 'printing_type is good' );
548 is
( $layouts->[0]->{layout_name
}, 'NAME2', 'layout_name is good' );
549 is
( $layouts->[0]->{guidebox
}, 2, 'guidebox is good' );
550 is
( $layouts->[0]->{font
}, 'TR', 'font is good' );
551 is
( $layouts->[0]->{font_size
}, 12, 'font_size is good' );
552 is
( $layouts->[0]->{units
}, 'POINT', 'units is good' );
553 is
( $layouts->[0]->{callnum_split
}, 2, 'callnum_split is good' );
554 is
( $layouts->[0]->{text_justify
}, 'L', 'text_justify is good' );
555 is
( $layouts->[0]->{format_string
}, 'barcode', 'format_string is good' );
556 is
( $layouts->[0]->{layout_xml
}, 'layout_xml2', 'layout_xml is good' );
557 is
( $layouts->[0]->{creator
}, 'Labels', 'creator is good' );
559 # With orderby param ------------------
560 $layouts = get_all_layouts
( orderby
=> 'font_size DESC' );
565 ORDER BY font_size DESC
567 $count = $dbh->selectrow_array($query);
568 is
( $count, 2, 'There are layout matching' );
569 is
( @
$layouts, $count, 'There are 2 layouts matching' );
570 isa_ok
( $layouts, 'ARRAY', '$layouts is an ARRAY' );
572 isa_ok
( $layouts->[0], 'HASH', '$layouts->[0] is a HASH' );
573 is
( $layouts->[0]->{barcode_type
}, 'EAN13', 'barcode_type is good' );
574 is
( $layouts->[0]->{start_label
}, 2, 'start_label is good' );
575 is
( $layouts->[0]->{printing_type
}, 'BAR2', 'printing_type is good' );
576 is
( $layouts->[0]->{layout_name
}, 'NAME2', 'layout_name is good' );
577 is
( $layouts->[0]->{guidebox
}, 2, 'guidebox is good' );
578 is
( $layouts->[0]->{font
}, 'TR', 'font is good' );
579 is
( $layouts->[0]->{font_size
}, 12, 'font_size is good' );
580 is
( $layouts->[0]->{units
}, 'POINT', 'units is good' );
581 is
( $layouts->[0]->{callnum_split
}, 2, 'callnum_split is good' );
582 is
( $layouts->[0]->{text_justify
}, 'L', 'text_justify is good' );
583 is
( $layouts->[0]->{format_string
}, 'barcode', 'format_string is good' );
584 is
( $layouts->[0]->{layout_xml
}, 'layout_xml2', 'layout_xml is good' );
585 is
( $layouts->[0]->{creator
}, 'Labels', 'creator is good' );
587 isa_ok
( $layouts->[1], 'HASH', '$layouts->[1] is a HASH' );
588 is
( $layouts->[1]->{barcode_type
}, 'COOP2OF5', 'barcode_type is good' );
589 is
( $layouts->[1]->{start_label
}, 1, 'start_label is good' );
590 is
( $layouts->[1]->{printing_type
}, 'BAR1', 'printing_type is good' );
591 is
( $layouts->[1]->{layout_name
}, 'NAME1', 'layout_name is good' );
592 is
( $layouts->[1]->{guidebox
}, 1, 'guidebox is good' );
593 is
( $layouts->[1]->{font
}, 'TR', 'font is good' );
594 is
( $layouts->[1]->{font_size
}, 11, 'font_size is good' );
595 is
( $layouts->[1]->{units
}, 'POINT', 'units is good' );
596 is
( $layouts->[1]->{callnum_split
}, 1, 'callnum_split is good' );
597 is
( $layouts->[1]->{text_justify
}, 'L', 'text_justify is good' );
598 is
( $layouts->[1]->{format_string
}, 'barcode', 'format_string is good' );
599 is
( $layouts->[1]->{layout_xml
}, 'layout_xml1', 'layout_xml is good' );
600 is
( $layouts->[1]->{creator
}, 'Labels', 'creator is good' );
602 # ---------- Testing get_all_profiles ---------------------
603 # Mocking $sth->err and $sth->errstr
605 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
606 $dbi_st->mock( 'err', sub { return 1; } );
607 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
609 warning_is
{ $profiles = get_all_profiles
() } 'Database returned the following error: something went wrong',
610 'get_all_profiles() raises warning if something went wrong with the sql request execution';
612 is
( $profiles, -1, '$profiles return -1' );
615 # Without params ----------------------
616 my $profiles = get_all_profiles
();
620 FROM printers_profile
622 $count = $dbh->selectrow_array($query);
623 is
( $count, 2, 'There are 2 profiles' );
624 is
( @
$profiles, $count, 'There are 2 profiles matching' );
625 isa_ok
( $profiles, 'ARRAY', '$profiles is an ARRAY' );
627 isa_ok
( $profiles->[0], 'HASH', '$profiles->[0] is a HASH' );
628 is
( $profiles->[0]->{printer_name
}, 'Layout1 Name', 'printer_name is good' );
629 is
( $profiles->[0]->{template_id
}, 1234, 'template_id is good' );
630 is
( $profiles->[0]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
631 is
( $profiles->[0]->{offset_horz
}, 0.1, 'offset_horz is good' );
632 is
( $profiles->[0]->{offset_vert
}, 0.2, 'offset_vert is good' );
633 is
( $profiles->[0]->{creep_horz
}, 0.3, 'creep_horz is good' );
634 is
( $profiles->[0]->{creep_vert
}, 0.4, 'creep_vert is good' );
635 is
( $profiles->[0]->{units
}, 'POINT', 'units is good' );
636 is
( $profiles->[0]->{creator
}, 'Labels', 'creator is good' );
638 isa_ok
( $profiles->[1], 'HASH', '$profiles->[1] is a HASH' );
639 is
( $profiles->[1]->{printer_name
}, 'Layout2 Name', 'printer_name is good' );
640 is
( $profiles->[1]->{template_id
}, 1235, 'template_id is good' );
641 is
( $profiles->[1]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
642 is
( $profiles->[1]->{offset_horz
}, 0.2, 'offset_horz is good' );
643 is
( $profiles->[1]->{offset_vert
}, 0.3, 'offset_vert is good' );
644 is
( $profiles->[1]->{creep_horz
}, 0.4, 'creep_horz is good' );
645 is
( $profiles->[1]->{creep_vert
}, 0.5, 'creep_vert is good' );
646 is
( $profiles->[1]->{units
}, 'POINT', 'units is good' );
647 is
( $profiles->[1]->{creator
}, 'Labels', 'creator is good' );
649 # With field_list params --------------
650 $profiles = get_all_profiles
( field_list
=> 'printer_name, template_id' );
654 FROM printers_profile
656 $count = $dbh->selectrow_array($query);
657 is
( $count, 2, 'There are 2 profiles' );
658 is
( @
$profiles, $count, 'There are 2 profiles matching' );
659 isa_ok
( $profiles, 'ARRAY', '$profiles is an ARRAY' );
661 isa_ok
( $profiles->[0], 'HASH', '$profiles->[0] is a HASH' );
662 is
( $profiles->[0]->{printer_name
}, 'Layout1 Name', 'printer_name is good' );
663 is
( $profiles->[0]->{template_id
}, 1234, 'template_id is good' );
664 isnt
( exists $profiles->[0]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
665 isnt
( exists $profiles->[0]->{offset_horz
}, 0.1, 'offset_horz is good' );
666 isnt
( exists $profiles->[0]->{offset_vert
}, 0.2, 'offset_vert is good' );
667 isnt
( exists $profiles->[0]->{creep_horz
}, 0.3, 'creep_horz is good' );
668 isnt
( exists $profiles->[0]->{creep_vert
}, 0.4, 'creep_vert is good' );
669 isnt
( exists $profiles->[0]->{units
}, 'POINT', 'units is good' );
670 isnt
( exists $profiles->[0]->{creator
}, 'Labels', 'creator is good' );
672 isa_ok
( $profiles->[1], 'HASH', '$profiles->[1] is a HASH' );
673 is
( $profiles->[1]->{printer_name
}, 'Layout2 Name', 'printer_name is good' );
674 is
( $profiles->[1]->{template_id
}, 1235, 'template_id is good' );
675 isnt
( exists $profiles->[1]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
676 isnt
( exists $profiles->[1]->{offset_horz
}, 0.2, 'offset_horz is good' );
677 isnt
( exists $profiles->[1]->{offset_vert
}, 0.3, 'offset_vert is good' );
678 isnt
( exists $profiles->[1]->{creep_horz
}, 0.4, 'creep_horz is good' );
679 isnt
( exists $profiles->[1]->{creep_vert
}, 0.5, 'creep_vert is good' );
680 isnt
( exists $profiles->[1]->{units
}, 'POINT', 'units is good' );
681 isnt
( exists $profiles->[1]->{creator
}, 'Labels', 'creator is good' );
683 # With filter params ------------------
684 $profiles = get_all_profiles
( filter
=> 'template_id = 1235' );
688 FROM printers_profile
689 WHERE template_id = 1235
691 $count = $dbh->selectrow_array($query);
692 is
( $count, 1, 'There is 1 profile matching' );
693 is
( @
$profiles, $count, 'There is 1 profile matching' );
694 isa_ok
( $profiles, 'ARRAY', '$profiles is an ARRAY' );
696 isa_ok
( $profiles->[0], 'HASH', '$profiles->[0] is a HASH' );
697 is
( $profiles->[0]->{printer_name
}, 'Layout2 Name', 'printer_name is good' );
698 is
( $profiles->[0]->{template_id
}, 1235, 'template_id is good' );
699 isnt
( exists $profiles->[0]->{paper_bin
}, 'Bypass', 'paper_bin is good' );
700 isnt
( exists $profiles->[0]->{offset_horz
}, 0.2, 'offset_horz is good' );
701 isnt
( exists $profiles->[0]->{offset_vert
}, 0.3, 'offset_vert is good' );
702 isnt
( exists $profiles->[0]->{creep_horz
}, 0.4, 'creep_horz is good' );
703 isnt
( exists $profiles->[0]->{creep_vert
}, 0.5, 'creep_vert is good' );
704 isnt
( exists $profiles->[0]->{units
}, 'POINT', 'units is good' );
705 isnt
( exists $profiles->[0]->{creator
}, 'Labels', 'creator is good' );
707 # ---------- Testing get_all_image_names ------------------
709 # Mocking $sth->err and $sth->errstr
711 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
712 $dbi_st->mock( 'err', sub { return 1; } );
713 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
715 warning_is
{ $images = get_all_image_names
() } 'Database returned the following error: something went wrong',
716 'get_all_image_names() raises warning if something went wrong with the sql request execution';
718 is
( $images, -1, '$images return -1' );
721 # Without params ----------------------
722 my $images = get_all_image_names
();
728 $count = $dbh->selectrow_array($query);
729 is
( $count, 2, 'There are 2 images' );
730 is
( @
$images, $count, 'There are 2 images matching' );
731 isa_ok
( $images, 'ARRAY', '$images is an ARRAY' );
733 isa_ok
( $images->[0], 'HASH', '$images->[0] is a HASH' );
734 is
( $images->[0]->{name
}, 'Image 1', 'name is good' );
735 is
( $images->[0]->{selected
}, 0, 'selected is good' );
736 is
( $images->[0]->{type
}, $images->[0]->{name
}, 'type is good' );
738 isa_ok
( $images->[1], 'HASH', '$images->[1] is a HASH' );
739 is
( $images->[1]->{name
}, 'Image 2', 'name is good' );
740 is
( $images->[1]->{selected
}, 0, 'selected is good' );
741 is
( $images->[1]->{type
}, $images->[1]->{name
}, 'type is good' );
743 # ---------- Testing get_batch_summary --------------------
745 # Mocking $sth->err and $sth->errstr
747 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
748 $dbi_st->mock( 'err', sub { return 1; } );
749 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
751 warning_is
{ $batches = get_batch_summary
() } 'Database returned the following error on attempted SELECT: something went wrong',
752 'get_batch_summary() raises warning if something went wrong with the sql request execution';
754 is
( $batches, -1, '$batches return -1' );
757 # Without creator params --------------
758 my $batches = get_batch_summary
( creator
=> 'Labels' );
761 SELECT batch_id, count(batch_id)
766 my $sth = $dbh->prepare($query);
767 $sth->execute('Labels');
769 is
( $count, 2, 'There are 2 batches' );
770 is
( @
$batches, $count, 'There are 2 batches matching' );
771 isa_ok
( $batches, 'ARRAY', '$batches is an ARRAY' );
774 SELECT count(batch_id)
779 $count = $dbh->selectrow_array( $query, {}, 'Labels', 11 );
780 is
( $count, 1, 'There is 1 batch where batch_id = 11' );
782 isa_ok
( $batches->[0], 'HASH', '$batches->[0] is a HASH' );
783 is
( $batches->[0]->{batch_id
}, 11, 'batch_id is good' );
784 is
( $batches->[0]->{_item_count
}, $count, 'item_number is good for this batch_id' );
786 $count = $dbh->selectrow_array( $query, {}, 'Labels', 12 );
787 is
( $count, 2, 'There are 2 batches where batch_id = 12' );
789 isa_ok
( $batches->[1], 'HASH', '$batches->[1] is a HASH' );
790 is
( $batches->[1]->{batch_id
}, 12, 'batch_id is good' );
791 is
( $batches->[1]->{_item_count
}, $count, 'item_number is good for this batch_id' );
793 # Without filter & creator params -----
794 $batches = get_batch_summary
( filter
=> 'branch_code=\'MPL\'', creator
=> 'Labels' );
795 is
( @
$batches, 1, 'There is 1 batch matching' );
798 SELECT batch_id, count(batch_id)
804 my ( $id, $nb ) = $dbh->selectrow_array( $query, {}, 'Labels', 'MPL' );
806 is
( $batches->[0]->{batch_id
}, $id, 'batch_id is good' );
807 is
( $batches->[0]->{_item_count
}, $nb, 'item_number is good for this batch_id' );
809 # ---------- Testing get_label_summary --------------------
810 # Mocking $sth->err and $sth->errstr
812 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
813 $dbi_st->mock( 'err', sub { return 1; } );
814 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
816 my @items = [ { item_number
=> $item_number1 } ];
818 warning_is
{ $labels = get_label_summary
( items
=> @items ) } 'Database returned the following error on attempted SELECT: something went wrong',
819 'get_label_summary() raises warning if something went wrong with the sql request execution';
821 is
( $labels, -1, '$labels return -1' );
824 # Without params ----------------------
825 my $labels = get_label_summary
();
827 isa_ok
( $labels, 'ARRAY', '$labels is an ARRAY' );
828 is
( @
$labels, 0, '$labels is empty' );
830 # With items param --------------------
832 SELECT biblionumber, title, author
834 WHERE biblionumber = ?
836 my ( $b_biblionumber1, $b_title1, $b_author1 ) = $dbh->selectrow_array( $query, {}, $biblionumber1 );
837 my ( $b_biblionumber2, $b_title2, $b_author2 ) = $dbh->selectrow_array( $query, {}, $biblionumber2 );
840 SELECT biblionumber, biblioitemnumber, itemtype
842 WHERE biblioitemnumber = ?
844 my ( $bi_biblionumber1, $bi_biblioitemnumber1, $bi_itemtype1 ) = $dbh->selectrow_array( $query, {}, $biblioitemnumber1 );
845 my ( $bi_biblionumber2, $bi_biblioitemnumber2, $bi_itemtype2 ) = $dbh->selectrow_array( $query, {}, $biblioitemnumber2 );
848 SELECT biblionumber, biblioitemnumber, itemnumber, barcode, itype
852 my ( $i_biblionumber1, $i_biblioitemnumber1, $i_itemnumber1, $i_barcode1, $i_itype1 ) = $dbh->selectrow_array( $query, {}, $item_number1 );
853 my ( $i_biblionumber2, $i_biblioitemnumber2, $i_itemnumber2, $i_barcode2, $i_itype2 ) = $dbh->selectrow_array( $query, {}, $item_number2 );
856 SELECT label_id, batch_id, item_number
858 WHERE item_number = ?
860 my ( $c_label_id1, $c_batch_id1, $c_item_number1 ) = $dbh->selectrow_array( $query, {}, $item_number1 );
861 my ( $c_label_id2, $c_batch_id2, $c_item_number2 ) = $dbh->selectrow_array( $query, {}, $item_number2 );
863 is
( $c_item_number1, $i_itemnumber1, 'CREATOR_BATCHES.item_number == ITEMS.itemnumber' );
864 is
( $i_biblioitemnumber1, $bi_biblioitemnumber1, 'ITEMS.biblioitemnumber == BIBLIOITEMS.biblioitemnumber' );
865 is
( $bi_biblionumber1, $b_biblionumber1, 'BIBLIOITEMS.biblionumber == BIBLIO.biblionumber' );
867 is
( $c_item_number2, $i_itemnumber2, 'CREATOR_BATCHES.item_number == ITEMS.itemnumber' );
868 is
( $i_biblioitemnumber2, $bi_biblioitemnumber2, 'ITEMS.biblioitemnumber == BIBLIOITEMS.biblioitemnumber' );
869 is
( $bi_biblionumber2, $b_biblionumber2, 'BIBLIOITEMS.biblionumber == BIBLIO.biblionumber' );
872 { item_number
=> $item_number1,
873 label_id
=> $c_label_id1,
876 $labels = get_label_summary
( items
=> @items, batch_id
=> $c_batch_id1 );
878 is
( @
$labels, 1, 'There is 1 label for $item_number1' );
879 isa_ok
( $labels, 'ARRAY', '$labels is an array' );
880 isa_ok
( $labels->[0], 'HASH', '$labels->[0] is an hash' );
882 my $record_author = $b_author1;
883 my $record_title = $b_title1;
884 $record_author =~ s/[^\.|\w]$//;
885 $record_title =~ s/\W*$//;
886 $record_title = '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' . $b_biblionumber1 . '"> ' . $b_title1 . '</a>';
887 my $summary1 = $record_title . " | " . ( $b_author1 ?
$b_author1 : 'N/A' );
888 my $itemtypes_pref = C4
::Context
->preference("item-level_itypes");
889 my $record_itemtype = $itemtypes_pref ?
$i_itype1 : $bi_itemtype1;
891 is
( $labels->[0]->{_label_number
}, 1, '_label_number is good' );
892 is
( $labels->[0]->{_summary
}, $summary1, '_summary is good' );
893 is
( $labels->[0]->{_item_type
}, $record_itemtype, '_item_type is good' );
894 is
( $labels->[0]->{_barcode
}, $i_barcode1, '_barcode is good' );
895 is
( $labels->[0]->{_item_number
}, $i_itemnumber1, '_item_number is good' );
896 is
( $labels->[0]->{_label_id
}, $c_label_id1, '_label_id is good' );
898 # record without author
900 { item_number
=> $item_number2,
901 label_id
=> $c_label_id2,
904 $labels = get_label_summary
( items
=> @items, batch_id
=> $c_batch_id2 );
906 is
( @
$labels, 1, 'There is 1 label for $item_number2' );
907 isa_ok
( $labels, 'ARRAY', '$labels is an array' );
908 isa_ok
( $labels->[0], 'HASH', '$labels->[0] is an hash' );
910 $record_author = $b_author2;
911 $record_title = $b_title2;
912 $record_author =~ s/[^\.|\w]$// if $b_author2;
913 $record_title =~ s/\W*$//;
914 $record_title = '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' . $b_biblionumber2 . '"> ' . $b_title2 . '</a>';
915 my $summary2 = $record_title . " | " . ( $b_author2 ?
$b_author2 : 'N/A' );
916 $itemtypes_pref = C4
::Context
->preference("item-level_itypes");
917 $record_itemtype = $itemtypes_pref ?
$i_itype2 : $bi_itemtype2;
919 is
( $labels->[0]->{_label_number
}, 1, '_label_number is good' );
920 is
( $labels->[0]->{_summary
}, $summary2, '_summary is good' );
921 is
( $labels->[0]->{_item_type
}, $record_itemtype, '_item_type is good' );
922 is
( $labels->[0]->{_barcode
}, $i_barcode2, '_barcode is good' );
923 is
( $labels->[0]->{_item_number
}, $i_itemnumber2, '_item_number is good' );
924 is
( $labels->[0]->{_label_id
}, $c_label_id2, '_label_id is good' );
926 #Mocking C4::Context->preference("item-level_itypes")
928 t
::lib
::Mocks
::mock_preference
( "item-level_itypes", 0 );
929 my $h = C4
::Context
->preference("item-level_itypes");
932 { item_number
=> $item_number1,
933 label_id
=> $c_label_id1,
936 $labels = get_label_summary
( items
=> @items, batch_id
=> $c_batch_id1 );
938 is
( @
$labels, 1, 'There is 1 label for $item_number1' );
939 isa_ok
( $labels, 'ARRAY', '$labels is an array' );
940 isa_ok
( $labels->[0], 'HASH', '$labels->[0] is an hash' );
942 my $record_author = $b_author1;
943 my $record_title = $b_title1;
944 $record_author =~ s/[^\.|\w]$//;
945 $record_title =~ s/\W*$//;
946 $record_title = '<a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' . $b_biblionumber1 . '"> ' . $b_title1 . '</a>';
947 my $summary1 = $record_title . " | " . ( $b_author1 ?
$b_author1 : 'N/A' );
948 my $itemtypes_pref = C4
::Context
->preference("item-level_itypes");
949 my $record_itemtype = $itemtypes_pref ?
$i_itype1 : $bi_itemtype1;
951 is
( $labels->[0]->{_label_number
}, 1, '_label_number is good' );
952 is
( $labels->[0]->{_summary
}, $summary1, '_summary is good' );
953 is
( $labels->[0]->{_item_type
}, $record_itemtype, '_item_type is good' );
954 is
( $labels->[0]->{_barcode
}, $i_barcode1, '_barcode is good' );
955 is
( $labels->[0]->{_item_number
}, $i_itemnumber1, '_item_number is good' );
956 is
( $labels->[0]->{_label_id
}, $c_label_id1, '_label_id is good' );
959 # ---------- Testing get_card_summary ---------------------
960 # Mocking $sth->err and $sth->errstr
962 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
963 $dbi_st->mock( 'err', sub { return 1; } );
964 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
966 my @items = [ { item_number
=> $item_number1 } ];
968 warning_is
{ $cards = get_card_summary
( items
=> @items ) } 'Database returned the following error on attempted SELECT: something went wrong',
969 'get_card_summary() raises warning if something went wrong with the sql request execution';
971 is
( $cards, -1, '$cards return -1' );
974 # Without params ----------------------
975 my $cards = get_card_summary
();
977 isa_ok
( $cards, 'ARRAY', '$cards is an ARRAY' );
978 is
( @
$cards, 0, '$cards is empty' );
980 # With items param --------------------
982 SELECT surname, firstname, cardnumber
984 WHERE borrowernumber = ?
986 my ( $b_surname1, $b_firstname1, $b_cardnumber1 ) = $dbh->selectrow_array( $query, {}, $borrowernumber1 );
989 { item_number
=> $item_number1,
990 label_id
=> $c_label_id1,
991 borrower_number
=> $borrowernumber1,
994 $cards = get_card_summary
( items
=> @items );
996 is
( @
$cards, 1, 'There is 1 card for $item_number1' );
997 isa_ok
( $cards, 'ARRAY', '$cards is an array' );
998 isa_ok
( $cards->[0], 'HASH', '$cards->[0] is an hash' );
1000 my $name1 = "$b_surname1, $b_firstname1";
1001 is
( $cards->[0]->{_card_number
}, 1, '_card_number is good' );
1002 is
( $cards->[0]->{_summary
}, $name1, '_summary is good' );
1003 is
( $cards->[0]->{borrowernumber
}, $borrowernumber1, 'borrowernumber is good' );
1004 is
( $cards->[0]->{_label_id
}, $c_label_id1, '_label_id is good' );
1006 # ---------- Testing get_barcode_types --------------------
1007 my $barcode_types = get_barcode_types
();
1009 is
( @
$barcode_types, 6, 'There are 6 barcodes types' );
1010 isa_ok
( $barcode_types, 'ARRAY', '$barcode_types is an ARRAY' );
1012 isa_ok
( $barcode_types->[0], 'HASH', '$barcode_types->[0] is a HASH' );
1013 is
( $barcode_types->[0]->{type
}, 'CODE39', 'type is good' );
1014 is
( $barcode_types->[0]->{name
}, 'Code 39', 'name is good' );
1015 is
( $barcode_types->[0]->{desc
}, 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern.', 'desc is good' );
1016 is
( $barcode_types->[0]->{selected
}, 0, 'selected is good' );
1018 isa_ok
( $barcode_types->[1], 'HASH', '$barcode_types->[1] is a HASH' );
1019 is
( $barcode_types->[1]->{type
}, 'CODE39MOD', 'type is good' );
1020 is
( $barcode_types->[1]->{name
}, 'Code 39 + Modulo43', 'name is good' );
1021 is
( $barcode_types->[1]->{desc
},
1022 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern. Encodes Mod 43 checksum.',
1025 is
( $barcode_types->[1]->{selected
}, 0, 'selected is good' );
1027 isa_ok
( $barcode_types->[2], 'HASH', '$barcode_types->[2] is a HASH' );
1028 is
( $barcode_types->[2]->{type
}, 'CODE39MOD10', 'type is good' );
1029 is
( $barcode_types->[2]->{name
}, 'Code 39 + Modulo10', 'name is good' );
1030 is
( $barcode_types->[2]->{desc
}, 'Translates the characters 0-9, A-Z, \'-\', \'*\', \'+\', \'$\', \'%\', \'/\', \'.\' and \' \' to a barcode pattern. Encodes Mod 10 checksum.', 'desc is good');
1031 is
( $barcode_types->[2]->{selected
}, 0, 'selected is good' );
1033 isa_ok
( $barcode_types->[3], 'HASH', '$barcode_types->[3] is a HASH' );
1034 is
( $barcode_types->[3]->{type
}, 'COOP2OF5', 'type is good' );
1035 is
( $barcode_types->[3]->{name
}, 'COOP2of5', 'name is good' );
1036 is
( $barcode_types->[3]->{desc
}, 'Creates COOP2of5 barcodes from a string consisting of the numeric characters 0-9', 'desc is good' );
1037 is
( $barcode_types->[3]->{selected
}, 0, 'selected is good' );
1039 isa_ok
( $barcode_types->[4], 'HASH', '$barcode_types->[4] is a HASH' );
1040 is
( $barcode_types->[4]->{type
}, 'EAN13', 'type is good' );
1041 is
( $barcode_types->[4]->{name
}, 'EAN13', 'name is good' );
1042 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' );
1043 is
( $barcode_types->[4]->{selected
}, 0, 'selected is good' );
1045 isa_ok
( $barcode_types->[5], 'HASH', '$barcode_types->[5] is a HASH' );
1046 is
( $barcode_types->[5]->{type
}, 'INDUSTRIAL2OF5', 'type is good' );
1047 is
( $barcode_types->[5]->{name
}, 'Industrial2of5', 'name is good' );
1048 is
( $barcode_types->[5]->{desc
}, 'Creates Industrial2of5 barcodes from a string consisting of the numeric characters 0-9', 'desc is good' );
1049 is
( $barcode_types->[5]->{selected
}, 0, 'selected is good' );
1051 # ---------- Testing get_label_types ----------------------
1052 my $label_types = get_label_types
();
1054 is
( @
$label_types, 5, 'There are 5 label types' );
1055 isa_ok
( $label_types, 'ARRAY', '$label_types is an ARRAY' );
1057 isa_ok
( $label_types->[0], 'HASH', '$label_types->[0] is a HASH' );
1058 is
( $label_types->[0]->{type
}, 'BIB', 'type is good' );
1059 is
( $label_types->[0]->{name
}, 'Biblio', 'name is good' );
1060 is
( $label_types->[0]->{desc
}, 'Only the bibliographic data is printed.', 'desc is good' );
1061 is
( $label_types->[0]->{selected
}, 0, 'selected is good' );
1063 isa_ok
( $label_types->[1], 'HASH', '$label_types->[1] is a HASH' );
1064 is
( $label_types->[1]->{type
}, 'BARBIB', 'type is good' );
1065 is
( $label_types->[1]->{name
}, 'Barcode/Biblio', 'name is good' );
1066 is
( $label_types->[1]->{desc
}, 'Barcode proceeds bibliographic data.', 'desc is good' );
1067 is
( $label_types->[1]->{selected
}, 0, 'selected is good' );
1069 isa_ok
( $label_types->[2], 'HASH', '$label_types->[2] is a HASH' );
1070 is
( $label_types->[2]->{type
}, 'BIBBAR', 'type is good' );
1071 is
( $label_types->[2]->{name
}, 'Biblio/Barcode', 'name is good' );
1072 is
( $label_types->[2]->{desc
}, 'Bibliographic data proceeds barcode.', 'desc is good' );
1073 is
( $label_types->[2]->{selected
}, 0, 'selected is good' );
1075 isa_ok
( $label_types->[3], 'HASH', '$label_types->[3] is a HASH' );
1076 is
( $label_types->[3]->{type
}, 'ALT', 'type is good' );
1077 is
( $label_types->[3]->{name
}, 'Alternating', 'name is good' );
1078 is
( $label_types->[3]->{desc
}, 'Barcode and bibliographic data are printed on alternating labels.', 'desc is good' );
1079 is
( $label_types->[3]->{selected
}, 0, 'selected is good' );
1081 isa_ok
( $label_types->[4], 'HASH', '$label_types->[4] is a HASH' );
1082 is
( $label_types->[4]->{type
}, 'BAR', 'type is good' );
1083 is
( $label_types->[4]->{name
}, 'Barcode', 'name is good' );
1084 is
( $label_types->[4]->{desc
}, 'Only the barcode is printed.', 'desc is good' );
1085 is
( $label_types->[4]->{selected
}, 0, 'selected is good' );
1087 # ---------- Testing get_font_types -----------------------
1088 my $font_types = get_font_types
();
1090 is
( @
$font_types, 12, 'There are 12 font types' );
1091 isa_ok
( $font_types, 'ARRAY', '$font_types is an ARRAY' );
1093 isa_ok
( $font_types->[0], 'HASH', '$font_types->[0] is a HASH' );
1094 is
( $font_types->[0]->{type
}, 'TR', 'type is good' );
1095 is
( $font_types->[0]->{name
}, 'Times-Roman', 'name is good' );
1096 is
( $font_types->[0]->{selected
}, 0, 'selected is good' );
1098 isa_ok
( $font_types->[1], 'HASH', '$font_types->[1] is a HASH' );
1099 is
( $font_types->[1]->{type
}, 'TB', 'type is good' );
1100 is
( $font_types->[1]->{name
}, 'Times-Bold', 'name is good' );
1101 is
( $font_types->[1]->{selected
}, 0, 'selected is good' );
1103 isa_ok
( $font_types->[2], 'HASH', '$font_types->[2] is a HASH' );
1104 is
( $font_types->[2]->{type
}, 'TI', 'type is good' );
1105 is
( $font_types->[2]->{name
}, 'Times-Italic', 'name is good' );
1106 is
( $font_types->[2]->{selected
}, 0, 'selected is good' );
1108 isa_ok
( $font_types->[3], 'HASH', '$font_types->[3] is a HASH' );
1109 is
( $font_types->[3]->{type
}, 'TBI', 'type is good' );
1110 is
( $font_types->[3]->{name
}, 'Times-Bold-Italic', 'name is good' );
1111 is
( $font_types->[3]->{selected
}, 0, 'selected is good' );
1113 isa_ok
( $font_types->[4], 'HASH', '$font_types->[4] is a HASH' );
1114 is
( $font_types->[4]->{type
}, 'C', 'type is good' );
1115 is
( $font_types->[4]->{name
}, 'Courier', 'name is good' );
1116 is
( $font_types->[4]->{selected
}, 0, 'selected is good' );
1118 isa_ok
( $font_types->[5], 'HASH', '$font_types->[5] is a HASH' );
1119 is
( $font_types->[5]->{type
}, 'CB', 'type is good' );
1120 is
( $font_types->[5]->{name
}, 'Courier-Bold', 'name is good' );
1121 is
( $font_types->[5]->{selected
}, 0, 'selected is good' );
1123 isa_ok
( $font_types->[6], 'HASH', '$font_types->[6] is a HASH' );
1124 is
( $font_types->[6]->{type
}, 'CO', 'type is good' );
1125 is
( $font_types->[6]->{name
}, 'Courier-Oblique', 'name is good' );
1126 is
( $font_types->[6]->{selected
}, 0, 'selected is good' );
1128 isa_ok
( $font_types->[7], 'HASH', '$font_types->[7] is a HASH' );
1129 is
( $font_types->[7]->{type
}, 'CBO', 'type is good' );
1130 is
( $font_types->[7]->{name
}, 'Courier-Bold-Oblique', 'name is good' );
1131 is
( $font_types->[7]->{selected
}, 0, 'selected is good' );
1133 isa_ok
( $font_types->[8], 'HASH', '$font_types->[8] is a HASH' );
1134 is
( $font_types->[8]->{type
}, 'H', 'type is good' );
1135 is
( $font_types->[8]->{name
}, 'Helvetica', 'name is good' );
1136 is
( $font_types->[8]->{selected
}, 0, 'selected is good' );
1138 isa_ok
( $font_types->[9], 'HASH', '$font_types->[9] is a HASH' );
1139 is
( $font_types->[9]->{type
}, 'HO', 'type is good' );
1140 is
( $font_types->[9]->{name
}, 'Helvetica-Oblique', 'name is good' );
1141 is
( $font_types->[9]->{selected
}, 0, 'selected is good' );
1143 isa_ok
( $font_types->[10], 'HASH', '$font_types->[10] is a HASH' );
1144 is
( $font_types->[10]->{type
}, 'HB', 'type is good' );
1145 is
( $font_types->[10]->{name
}, 'Helvetica-Bold', 'name is good' );
1146 is
( $font_types->[10]->{selected
}, 0, 'selected is good' );
1148 isa_ok
( $font_types->[11], 'HASH', '$font_types->[11] is a HASH' );
1149 is
( $font_types->[11]->{type
}, 'HBO', 'type is good' );
1150 is
( $font_types->[11]->{name
}, 'Helvetica-Bold-Oblique', 'name is good' );
1151 is
( $font_types->[11]->{selected
}, 0, 'selected is good' );
1153 # ---------- Testing get_text_justification_types ---------
1154 my $text_justification_types = get_text_justification_types
();
1156 is
( @
$text_justification_types, 3, 'There are 3 text justification types' );
1157 isa_ok
( $text_justification_types, 'ARRAY', '$text_justification_types is an ARRAY' );
1159 isa_ok
( $text_justification_types->[0], 'HASH', '$font_types->[0] is a HASH' );
1160 is
( $text_justification_types->[0]->{type
}, 'L', 'type is good' );
1161 is
( $text_justification_types->[0]->{name
}, 'Left', 'name is good' );
1162 is
( $text_justification_types->[0]->{selected
}, 0, 'selected is good' );
1164 isa_ok
( $text_justification_types->[1], 'HASH', '$font_types->[1] is a HASH' );
1165 is
( $text_justification_types->[1]->{type
}, 'C', 'type is good' );
1166 is
( $text_justification_types->[1]->{name
}, 'Center', 'name is good' );
1167 is
( $text_justification_types->[1]->{selected
}, 0, 'selected is good' );
1169 isa_ok
( $text_justification_types->[2], 'HASH', '$font_types->[2] is a HASH' );
1170 is
( $text_justification_types->[2]->{type
}, 'R', 'type is good' );
1171 is
( $text_justification_types->[2]->{name
}, 'Right', 'name is good' );
1172 is
( $text_justification_types->[2]->{selected
}, 0, 'selected is good' );
1174 # ---------- Testing get_unit_values ----------------------
1175 my $unit_values = get_unit_values
();
1177 is
( @
$unit_values, 5, 'There are 5 unit values' );
1178 isa_ok
( $unit_values, 'ARRAY', '$unit_values is an ARRAY' );
1180 isa_ok
( $unit_values->[0], 'HASH', '$unit_values->[0] is a HASH' );
1181 is
( $unit_values->[0]->{type
}, 'POINT', 'type is good' );
1182 is
( $unit_values->[0]->{desc
}, 'PostScript Points', 'desc is good' );
1183 is
( $unit_values->[0]->{value
}, 1, 'value is good' );
1184 is
( $unit_values->[0]->{selected
}, 0, 'selected is good' );
1186 isa_ok
( $unit_values->[1], 'HASH', '$unit_values->[1] is a HASH' );
1187 is
( $unit_values->[1]->{type
}, 'AGATE', 'type is good' );
1188 is
( $unit_values->[1]->{desc
}, 'Adobe Agates', 'desc is good' );
1189 is
( $unit_values->[1]->{value
}, 5.1428571, 'value is good' );
1190 is
( $unit_values->[1]->{selected
}, 0, 'selected is good' );
1192 isa_ok
( $unit_values->[2], 'HASH', '$unit_values->[2] is a HASH' );
1193 is
( $unit_values->[2]->{type
}, 'INCH', 'type is good' );
1194 is
( $unit_values->[2]->{desc
}, 'US Inches', 'desc is good' );
1195 is
( $unit_values->[2]->{value
}, 72, 'value is good' );
1196 is
( $unit_values->[2]->{selected
}, 0, 'selected is good' );
1198 isa_ok
( $unit_values->[3], 'HASH', '$unit_values->[3] is a HASH' );
1199 is
( $unit_values->[3]->{type
}, 'MM', 'type is good' );
1200 is
( $unit_values->[3]->{desc
}, 'SI Millimeters', 'desc is good' );
1201 is
( $unit_values->[3]->{value
}, 2.83464567, 'value is good' );
1202 is
( $unit_values->[3]->{selected
}, 0, 'selected is good' );
1204 isa_ok
( $unit_values->[4], 'HASH', '$unit_values->[4] is a HASH' );
1205 is
( $unit_values->[4]->{type
}, 'CM', 'type is good' );
1206 is
( $unit_values->[4]->{desc
}, 'SI Centimeters', 'desc is good' );
1207 is
( $unit_values->[4]->{value
}, 28.3464567, 'value is good' );
1208 is
( $unit_values->[4]->{selected
}, 0, 'selected is good' );
1210 # ---------- Testing get_output_formats -------------------
1211 my $output_formats = get_output_formats
();
1213 is
( @
$output_formats, 2, 'There are 2 output format' );
1214 isa_ok
( $output_formats, 'ARRAY', '$output_formats is an ARRAY' );
1216 isa_ok
( $output_formats->[0], 'HASH', '$output_formats->[0] is a HASH' );
1217 is
( $output_formats->[0]->{type
}, 'pdf', 'type is good' );
1218 is
( $output_formats->[0]->{desc
}, 'PDF File', 'name is good' );
1220 isa_ok
( $output_formats->[1], 'HASH', '$output_formats->[1] is a HASH' );
1221 is
( $output_formats->[1]->{type
}, 'csv', 'type is good' );
1222 is
( $output_formats->[1]->{desc
}, 'CSV File', 'name is good' );
1224 # ---------- Testing get_table_names ----------------------
1225 my $table_names = get_table_names
("aq");
1226 my $KOHA_PATH = C4
::Context
->config("intranetdir");
1227 my $kohastructure = "$KOHA_PATH/installer/data/mysql/kohastructure.sql";
1229 open( my $fh, '<', $kohastructure ) or die $!;
1231 my $tables_names_matching = [];
1232 while ( my $intext = <$fh> ) {
1233 while ( $intext =~ /CREATE TABLE `*\w*aq\w*`*/g ) {
1234 my @tables_names_matching = split( /\ /, $intext );
1235 if ( $tables_names_matching[2] =~ /`*`/ ) {
1236 $tables_names_matching[2] =~ s/`//g;
1238 push( @
$tables_names_matching, "$tables_names_matching[2]" );
1242 @
$tables_names_matching = sort @
$tables_names_matching;
1243 is_deeply
( $table_names, $tables_names_matching, 'get_table_names return all tables matching' );
1245 # ---------- Testing html_table ---------------------------
1246 my $display_columns = [
1247 { _label_number
=> { label
=> 'Label Number', link_field
=> 0 } },
1248 { _summary
=> { label
=> 'Summary', link_field
=> 0 } },
1249 { _item_type
=> { label
=> 'Item Type', link_field
=> 0 } },
1250 { _barcode
=> { label
=> 'Barcode', link_field
=> 1 } },
1251 { _template_code
=> { label
=> 'Template Name', link_field
=> 0 } },
1252 { select => { label
=> 'Select', value
=> '_label_id' } },
1255 #without $data param ------------------
1257 my $table = html_table
( $display_columns, $db_rows );
1258 is
( $table, undef, 'No need to generate a table if there is not data to display' );
1260 #with $data param ---------------------
1262 { _label_number
=> 1,
1263 _summary
=> $summary1,
1264 _item_type
=> 'Book',
1265 _barcode
=> $barcode1,
1266 _label_id
=> 'Label ID',
1267 template_id
=> $template_id1,
1271 $table = html_table
( $display_columns, $db_rows );
1273 isa_ok
( $table, 'ARRAY', '$table is an ARRAY' );
1276 isa_ok
( $table->[0]->{header_fields
}, 'ARRAY', '$table->[0]->{header_fields} is an ARRAY' );
1277 is
( scalar( @
{ $table->[0]->{header_fields
} } ), 6, 'There are 7 header_fields' );
1279 my $field_value = $display_columns->[0]->{_label_number
}->{label
};
1280 is
( $table->[0]->{header_fields
}->[0]->{hidden
}, 0, '[Label Number] hidden field is good' );
1281 is
( $table->[0]->{header_fields
}->[0]->{select_field
}, 0, '[Label Number] select_field field is good' );
1282 is
( $table->[0]->{header_fields
}->[0]->{field_name
}, '_label_number', '[Label Number] field_name field is good' );
1283 is
( $table->[0]->{header_fields
}->[0]->{field_label
}, $field_value, '[Label Number] field_label field is good' );
1285 $field_value = $display_columns->[1]->{_summary
}->{label
};
1286 is
( $table->[0]->{header_fields
}->[1]->{hidden
}, 0, '[Summary] hidden field is good' );
1287 is
( $table->[0]->{header_fields
}->[1]->{select_field
}, 0, '[Summary] select_field field is good' );
1288 is
( $table->[0]->{header_fields
}->[1]->{field_name
}, '_summary', '[Summary] field_name field is good' );
1289 is
( $table->[0]->{header_fields
}->[1]->{field_label
}, $field_value, '[Summary] field_label field is good' );
1291 $field_value = $display_columns->[2]->{_item_type
}->{label
};
1292 is
( $table->[0]->{header_fields
}->[2]->{hidden
}, 0, '[Item Type] hidden field is good' );
1293 is
( $table->[0]->{header_fields
}->[2]->{select_field
}, 0, '[Item Type] select_field field is good' );
1294 is
( $table->[0]->{header_fields
}->[2]->{field_name
}, '_item_type', '[Item Type] field_name field is good' );
1295 is
( $table->[0]->{header_fields
}->[2]->{field_label
}, $field_value, '[Item Type] field_label field is good' );
1297 $field_value = $display_columns->[3]->{_barcode
}->{label
};
1298 is
( $table->[0]->{header_fields
}->[3]->{hidden
}, 0, '[Barcode] hidden field is good' );
1299 is
( $table->[0]->{header_fields
}->[3]->{select_field
}, 0, '[Barcode] select_field field is good' );
1300 is
( $table->[0]->{header_fields
}->[3]->{field_name
}, '_barcode', '[Barcode] field_name field is good' );
1301 is
( $table->[0]->{header_fields
}->[3]->{field_label
}, $field_value, '[Barcode] field_label field is good' );
1303 $field_value = $display_columns->[4]->{_template_code
}->{label
};
1304 is
( $table->[0]->{header_fields
}->[4]->{hidden
}, 0, '[Template Code] hidden field is good' );
1305 is
( $table->[0]->{header_fields
}->[4]->{select_field
}, 0, '[Template Code] select_field field is good' );
1306 is
( $table->[0]->{header_fields
}->[4]->{field_name
}, '_template_code', '[Template Code] field_name field is good' );
1307 is
( $table->[0]->{header_fields
}->[4]->{field_label
}, $field_value, '[Template Code] field_label field is good' );
1309 $field_value = $display_columns->[5]->{select}->{label
};
1310 is
( $table->[0]->{header_fields
}->[5]->{hidden
}, 0, '[Select] hidden field is good' );
1311 is
( $table->[0]->{header_fields
}->[5]->{select_field
}, 0, '[Select] select_field field is good' );
1312 is
( $table->[0]->{header_fields
}->[5]->{field_name
}, 'select', '[Select] field_name field is good' );
1313 is
( $table->[0]->{header_fields
}->[5]->{field_label
}, $field_value, '[Select] field_label field is good' );
1316 isa_ok
( $table->[1]->{text_fields
}, 'ARRAY', '$table->[0]->{text_fields} is an ARRAY' );
1317 is
( scalar( @
{ $table->[1]->{text_fields
} } ), 6, 'There are 6 text_fields' );
1319 #test : if (grep {$table_column eq $_} keys %$db_row)
1320 my $link_field = $display_columns->[0]->{_label_number
}->{link_field
};
1321 my $field_name = "$table->[0]->{header_fields}->[0]->{field_name}_tbl";
1322 $field_value = $db_rows->[0]->{_label_number
};
1323 is
( $table->[1]->{text_fields
}->[0]->{hidden
}, 0, '[Label Number] hidden field is good' );
1324 is
( $table->[1]->{text_fields
}->[0]->{link_field
}, $link_field, '[Label Number] link_field field is good' );
1325 is
( $table->[1]->{text_fields
}->[0]->{select_field
}, 0, '[Label Number] select_field field is good' );
1326 is
( $table->[1]->{text_fields
}->[0]->{field_name
}, $field_name, '[Label Number] field_name field is good' );
1327 is
( $table->[1]->{text_fields
}->[0]->{field_value
}, $field_value, '[Label Number] field_value field is good' );
1329 $link_field = $display_columns->[1]->{_summary
}->{link_field
};
1330 $field_value = $db_rows->[0]->{_summary
};
1331 $field_name = "$table->[0]->{header_fields}->[1]->{field_name}_tbl";
1332 is
( $table->[1]->{text_fields
}->[1]->{hidden
}, 0, '[Summary] hidden field is good' );
1333 is
( $table->[1]->{text_fields
}->[1]->{link_field
}, $link_field, '[Summary] link_field field is good' );
1334 is
( $table->[1]->{text_fields
}->[1]->{select_field
}, 0, '[Summary] select_field field is good' );
1335 is
( $table->[1]->{text_fields
}->[1]->{field_name
}, $field_name, '[Summary] field_name field is good' );
1336 is
( $table->[1]->{text_fields
}->[1]->{field_value
}, $field_value, '[Summary] field_value field is good' );
1338 $link_field = $display_columns->[2]->{_item_type
}->{link_field
};
1339 $field_name = "$table->[0]->{header_fields}->[2]->{field_name}_tbl";
1340 $field_value = $db_rows->[0]->{_item_type
};
1341 is
( $table->[1]->{text_fields
}->[2]->{hidden
}, 0, '[Item Type] hidden field is good' );
1342 is
( $table->[1]->{text_fields
}->[2]->{link_field
}, $link_field, '[Item Type] link_field field is good' );
1343 is
( $table->[1]->{text_fields
}->[2]->{select_field
}, 0, '[Item Type] select_field field is good' );
1344 is
( $table->[1]->{text_fields
}->[2]->{field_name
}, $field_name, '[Item Type] field_name field is good' );
1345 is
( $table->[1]->{text_fields
}->[2]->{field_value
}, $field_value, '[Item Type] field_value field is good' );
1347 $link_field = $display_columns->[3]->{_barcode
}->{link_field
};
1348 $field_name = "$table->[0]->{header_fields}->[3]->{field_name}_tbl";
1349 $field_value = $db_rows->[0]->{_barcode
};
1350 is
( $table->[1]->{text_fields
}->[3]->{hidden
}, 0, '[Barcode] hidden field is good' );
1351 is
( $table->[1]->{text_fields
}->[3]->{link_field
}, $link_field, '[Barcode] link_field field is good' );
1352 is
( $table->[1]->{text_fields
}->[3]->{select_field
}, 0, '[Barcode] select_field field is good' );
1353 is
( $table->[1]->{text_fields
}->[3]->{field_name
}, $field_name, '[Barcode] field_name field is good' );
1354 is
( $table->[1]->{text_fields
}->[3]->{field_value
}, $field_value, '[Barcode] field_value field is good' );
1356 #test : elsif ($table_column =~ m/^_((.*)_(.*$))/)
1357 $link_field = $display_columns->[4]->{_template_code
}->{link_field
};
1358 $field_name = "$table->[0]->{header_fields}->[4]->{field_name}_tbl";
1359 is
( $table->[1]->{text_fields
}->[4]->{hidden
}, 0, '[Template Code] hidden field is good' );
1360 is
( $table->[1]->{text_fields
}->[4]->{link_field
}, $link_field, '[Template Code] link_field field is good' );
1361 is
( $table->[1]->{text_fields
}->[4]->{select_field
}, 0, '[Template Code] select_field field is good' );
1362 is
( $table->[1]->{text_fields
}->[4]->{field_name
}, $field_name, '[Template Code] field_name field is good' );
1363 is
( $table->[1]->{text_fields
}->[4]->{field_value
}, $template_code1, '[Template Code] field_value field is good' );
1365 #test : elsif ($table_column eq 'select')
1366 $field_value = $db_rows->[0]->{_label_id
};
1367 is
( $table->[1]->{text_fields
}->[5]->{hidden
}, 0, '[Select] hidden field is good' );
1368 is
( $table->[1]->{text_fields
}->[5]->{select_field
}, 1, '[Select] select_field field is good' );
1369 is
( $table->[1]->{text_fields
}->[5]->{field_name
}, 'select', '[Select] field_name field is good' );
1370 is
( $table->[1]->{text_fields
}->[5]->{field_value
}, $field_value, '[Select] field_value field is good' );
1372 # ---------- Testing _SELECT ---------------------------
1373 # Mocking $sth->err and $sth->errstr
1375 my $dbi_st = Test
::MockModule
->new( 'DBI::st', no_auto
=> 1 );
1376 $dbi_st->mock( 'err', sub { return 1; } );
1377 $dbi_st->mock( 'errstr', sub { return 'something went wrong'; } );
1379 warning_is
{ $records = C4
::Creators
::Lib
::_SELECT
( '*', 'borrowers', "borrowernumber = $borrowernumber1" ) } 'Database returned the following error: something went wrong',
1380 '_SELECT raises warning if something went wrong with the sql request execution';
1382 is
( $records, 1, '$record return 1' );
1385 #without $params[2] -------------------
1386 my $records = C4
::Creators
::Lib
::_SELECT
( 'surname, firstname, cardnumber, branchcode, categorycode', 'borrowers' );
1388 is
( @
$records, 3, 'There are 3 borrowers' );
1389 isa_ok
( $records, 'ARRAY', '$records is an ARRAY' );
1391 isa_ok
( $records->[0], 'HASH', '$records->[0] is a HASH' );
1392 is
( $records->[0]->{surname
}, $surname1, 'surname is good' );
1393 is
( $records->[0]->{firstname
}, $firstname1, 'firstname is good' );
1394 is
( $records->[0]->{cardnumber
}, $cardnumber1, 'cardnumber is good' );
1395 is
( $records->[0]->{branchcode
}, $branchcode, 'branchcode is good' );
1396 is
( $records->[0]->{categorycode
}, $categorycode, 'categorycode is good' );
1398 isa_ok
( $records->[1], 'HASH', '$records->[1] is a HASH' );
1399 is
( $records->[1]->{surname
}, $surname2, 'surname is good' );
1400 is
( $records->[1]->{firstname
}, $firstname2, 'firstname is good' );
1401 is
( $records->[1]->{cardnumber
}, $cardnumber2, 'cardnumber is good' );
1402 is
( $records->[1]->{branchcode
}, $branchcode, 'branchcode is good' );
1403 is
( $records->[1]->{categorycode
}, $categorycode, 'categorycode is good' );
1405 isa_ok
( $records->[2], 'HASH', '$records->[2] is a HASH' );
1406 is
( $records->[2]->{surname
}, $surname3, 'surname is good' );
1407 is
( $records->[2]->{firstname
}, $firstname3, 'firstname is good' );
1408 is
( $records->[2]->{cardnumber
}, $cardnumber3, 'cardnumber is good' );
1409 is
( $records->[2]->{branchcode
}, $branchcode, 'branchcode is good' );
1410 is
( $records->[2]->{categorycode
}, $categorycode, 'categorycode is good' );
1412 #with $params[2] ----------------------
1413 $records = C4
::Creators
::Lib
::_SELECT
( 'surname, firstname, cardnumber, branchcode, categorycode', 'borrowers', "borrowernumber = $borrowernumber1" );
1415 is
( @
$records, 1, 'There is 1 borrower where borrowernumber = $borrowernumber1' );
1416 isa_ok
( $records, 'ARRAY', '$records is an ARRAY' );
1418 isa_ok
( $records->[0], 'HASH', '$records->[0] is a HASH' );
1419 is
( $records->[0]->{surname
}, $surname1, 'surname is good' );
1420 is
( $records->[0]->{firstname
}, $firstname1, 'firstname is good' );
1421 is
( $records->[0]->{cardnumber
}, $cardnumber1, 'cardnumber is good' );
1422 is
( $records->[0]->{branchcode
}, $branchcode, 'branchcode is good' );
1423 is
( $records->[0]->{categorycode
}, $categorycode, 'categorycode is good' );
1425 # ---------- Sub ------------------------------------------
1428 sub mock_preference
{
1429 my $context = new Test
::MockModule
('C4::Context');
1430 my ( $pref, $value ) = @_;
1431 $preferences{$pref} = $value;
1435 my ( $self, $pref ) = @_;
1436 if ( exists $preferences{$pref} ) {
1437 return $preferences{$pref};
1439 my $method = $context->original('preference');
1440 return $method->( $self, $pref );