Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 13; |
22 |
use Test::More tests => 15; |
|
|
23 |
|
24 |
use Test::MockModule; |
23 |
use Test::Exception; |
25 |
use Test::Exception; |
24 |
|
26 |
|
25 |
use C4::Circulation; |
27 |
use C4::Circulation; |
Lines 244-253
$schema->storage->txn_rollback;
Link Here
|
244 |
|
246 |
|
245 |
subtest 'filter_by_visible_in_opac() tests' => sub { |
247 |
subtest 'filter_by_visible_in_opac() tests' => sub { |
246 |
|
248 |
|
247 |
plan tests => 8; |
249 |
plan tests => 11; |
248 |
|
250 |
|
249 |
$schema->storage->txn_begin; |
251 |
$schema->storage->txn_begin; |
250 |
|
252 |
|
|
|
253 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
254 |
my $mocked_category = Test::MockModule->new('Koha::Patron::Category'); |
255 |
my $exception = 1; |
256 |
$mocked_category->mock( 'override_hidden_items', sub { |
257 |
return $exception; |
258 |
}); |
259 |
|
251 |
# have a fresh biblio |
260 |
# have a fresh biblio |
252 |
my $biblio = $builder->build_sample_biblio; |
261 |
my $biblio = $builder->build_sample_biblio; |
253 |
# have two itemtypes |
262 |
# have two itemtypes |
Lines 314-319
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
314 |
is( $biblio->items->filter_by_visible_in_opac->count, |
323 |
is( $biblio->items->filter_by_visible_in_opac->count, |
315 |
6, 'No rules passed, hidelostitems unset' ); |
324 |
6, 'No rules passed, hidelostitems unset' ); |
316 |
|
325 |
|
|
|
326 |
is( $biblio->items->filter_by_visible_in_opac({ patron => $patron })->count, |
327 |
6, 'No rules passed, hidelostitems unset, patron exception changes nothing' ); |
328 |
|
317 |
$rules = {}; |
329 |
$rules = {}; |
318 |
|
330 |
|
319 |
t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); |
331 |
t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); |
Lines 323-328
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
323 |
'No rules passed, hidelostitems set' |
335 |
'No rules passed, hidelostitems set' |
324 |
); |
336 |
); |
325 |
|
337 |
|
|
|
338 |
is( |
339 |
$biblio->items->filter_by_visible_in_opac({ patron => $patron })->count, |
340 |
3, |
341 |
'No rules passed, hidelostitems set, patron exception changes nothing' |
342 |
); |
343 |
|
326 |
$rules = { withdrawn => [ 1, 2 ] }; |
344 |
$rules = { withdrawn => [ 1, 2 ] }; |
327 |
is( |
345 |
is( |
328 |
$biblio->items->filter_by_visible_in_opac->count, |
346 |
$biblio->items->filter_by_visible_in_opac->count, |
Lines 330-335
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
330 |
'Rules on withdrawn, hidelostitems set' |
348 |
'Rules on withdrawn, hidelostitems set' |
331 |
); |
349 |
); |
332 |
|
350 |
|
|
|
351 |
is( |
352 |
$biblio->items->filter_by_visible_in_opac({ patron => $patron })->count, |
353 |
3, |
354 |
'hidelostitems set, rules on withdrawn but patron override passed' |
355 |
); |
356 |
|
333 |
$rules = { itype => [ $itype_1->itemtype ] }; |
357 |
$rules = { itype => [ $itype_1->itemtype ] }; |
334 |
is( |
358 |
is( |
335 |
$biblio->items->filter_by_visible_in_opac->count, |
359 |
$biblio->items->filter_by_visible_in_opac->count, |
Lines 365-367
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
365 |
|
389 |
|
366 |
$schema->storage->txn_rollback; |
390 |
$schema->storage->txn_rollback; |
367 |
}; |
391 |
}; |
368 |
- |
392 |
|
|
|
393 |
subtest 'filter_out_lost() tests' => sub { |
394 |
|
395 |
plan tests => 2; |
396 |
|
397 |
$schema->storage->txn_begin; |
398 |
|
399 |
# have a fresh biblio |
400 |
my $biblio = $builder->build_sample_biblio; |
401 |
# have 3 items on that biblio |
402 |
my $item_1 = $builder->build_sample_item( |
403 |
{ |
404 |
biblionumber => $biblio->biblionumber, |
405 |
itemlost => -1, |
406 |
} |
407 |
); |
408 |
my $item_2 = $builder->build_sample_item( |
409 |
{ |
410 |
biblionumber => $biblio->biblionumber, |
411 |
itemlost => 0, |
412 |
} |
413 |
); |
414 |
my $item_3 = $builder->build_sample_item( |
415 |
{ |
416 |
biblionumber => $biblio->biblionumber, |
417 |
itemlost => 1, |
418 |
} |
419 |
); |
420 |
|
421 |
is( $biblio->items->filter_out_lost->next->itemnumber, $item_2->itemnumber, 'Right item returned' ); |
422 |
is( $biblio->items->filter_out_lost->count, 1, 'Only one item is not lost' ); |
423 |
|
424 |
$schema->storage->txn_rollback; |
425 |
}; |
426 |
|
427 |
subtest 'filter_out_opachiddenitems() tests' => sub { |
428 |
|
429 |
plan tests => 6; |
430 |
|
431 |
$schema->storage->txn_begin; |
432 |
|
433 |
# have a fresh biblio |
434 |
my $biblio = $builder->build_sample_biblio; |
435 |
# have two itemtypes |
436 |
my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
437 |
my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
438 |
# have 5 items on that biblio |
439 |
my $item_1 = $builder->build_sample_item( |
440 |
{ |
441 |
biblionumber => $biblio->biblionumber, |
442 |
itype => $itype_1->itemtype, |
443 |
withdrawn => 1 |
444 |
} |
445 |
); |
446 |
my $item_2 = $builder->build_sample_item( |
447 |
{ |
448 |
biblionumber => $biblio->biblionumber, |
449 |
itype => $itype_2->itemtype, |
450 |
withdrawn => 2 |
451 |
} |
452 |
); |
453 |
my $item_3 = $builder->build_sample_item( |
454 |
{ |
455 |
biblionumber => $biblio->biblionumber, |
456 |
itype => $itype_1->itemtype, |
457 |
withdrawn => 3 |
458 |
} |
459 |
); |
460 |
my $item_4 = $builder->build_sample_item( |
461 |
{ |
462 |
biblionumber => $biblio->biblionumber, |
463 |
itype => $itype_2->itemtype, |
464 |
withdrawn => 4 |
465 |
} |
466 |
); |
467 |
my $item_5 = $builder->build_sample_item( |
468 |
{ |
469 |
biblionumber => $biblio->biblionumber, |
470 |
itype => $itype_1->itemtype, |
471 |
withdrawn => 5 |
472 |
} |
473 |
); |
474 |
my $item_6 = $builder->build_sample_item( |
475 |
{ |
476 |
biblionumber => $biblio->biblionumber, |
477 |
itype => $itype_1->itemtype, |
478 |
withdrawn => 5 |
479 |
} |
480 |
); |
481 |
|
482 |
my $rules = undef; |
483 |
|
484 |
my $mocked_context = Test::MockModule->new('C4::Context'); |
485 |
$mocked_context->mock( 'yaml_preference', sub { |
486 |
return $rules; |
487 |
}); |
488 |
|
489 |
is( $biblio->items->filter_out_opachiddenitems->count, 6, 'No rules passed' ); |
490 |
|
491 |
$rules = {}; |
492 |
|
493 |
$rules = { withdrawn => [ 1, 2 ] }; |
494 |
is( $biblio->items->filter_out_opachiddenitems->count, 4, 'Rules on withdrawn' ); |
495 |
|
496 |
$rules = { itype => [ $itype_1->itemtype ] }; |
497 |
is( $biblio->items->filter_out_opachiddenitems->count, 2, 'Rules on itype' ); |
498 |
|
499 |
$rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] }; |
500 |
is( $biblio->items->filter_out_opachiddenitems->count, 1, 'Rules on itype and withdrawn' ); |
501 |
is( $biblio->items->filter_out_opachiddenitems->next->itemnumber, |
502 |
$item_4->itemnumber, |
503 |
'The right item is returned' |
504 |
); |
505 |
|
506 |
$rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] }; |
507 |
is( $biblio->items->filter_out_opachiddenitems->count, 3, 'Rules on itype and withdrawn' ); |
508 |
|
509 |
$schema->storage->txn_rollback; |
510 |
}; |