|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 15; |
22 |
use Test::More tests => 13; |
| 23 |
|
23 |
|
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
use Test::Exception; |
25 |
use Test::Exception; |
|
Lines 423-510
subtest 'filter_out_lost() tests' => sub {
Link Here
|
| 423 |
|
423 |
|
| 424 |
$schema->storage->txn_rollback; |
424 |
$schema->storage->txn_rollback; |
| 425 |
}; |
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 |
}; |
| 511 |
- |