|
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 => 14; |
| 23 |
|
23 |
|
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
use Test::Exception; |
25 |
use Test::Exception; |
|
Lines 1501-1587
subtest 'filter_out_lost() tests' => sub {
Link Here
|
| 1501 |
$schema->storage->txn_rollback; |
1501 |
$schema->storage->txn_rollback; |
| 1502 |
}; |
1502 |
}; |
| 1503 |
|
1503 |
|
| 1504 |
subtest 'filter_out_opachiddenitems() tests' => sub { |
|
|
| 1505 |
|
| 1506 |
plan tests => 6; |
| 1507 |
|
| 1508 |
$schema->storage->txn_begin; |
| 1509 |
|
| 1510 |
# have a fresh biblio |
| 1511 |
my $biblio = $builder->build_sample_biblio; |
| 1512 |
# have two itemtypes |
| 1513 |
my $itype_1 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
| 1514 |
my $itype_2 = $builder->build_object({ class => 'Koha::ItemTypes' }); |
| 1515 |
# have 5 items on that biblio |
| 1516 |
my $item_1 = $builder->build_sample_item( |
| 1517 |
{ |
| 1518 |
biblionumber => $biblio->biblionumber, |
| 1519 |
itype => $itype_1->itemtype, |
| 1520 |
withdrawn => 1 |
| 1521 |
} |
| 1522 |
); |
| 1523 |
my $item_2 = $builder->build_sample_item( |
| 1524 |
{ |
| 1525 |
biblionumber => $biblio->biblionumber, |
| 1526 |
itype => $itype_2->itemtype, |
| 1527 |
withdrawn => 2 |
| 1528 |
} |
| 1529 |
); |
| 1530 |
my $item_3 = $builder->build_sample_item( |
| 1531 |
{ |
| 1532 |
biblionumber => $biblio->biblionumber, |
| 1533 |
itype => $itype_1->itemtype, |
| 1534 |
withdrawn => 3 |
| 1535 |
} |
| 1536 |
); |
| 1537 |
my $item_4 = $builder->build_sample_item( |
| 1538 |
{ |
| 1539 |
biblionumber => $biblio->biblionumber, |
| 1540 |
itype => $itype_2->itemtype, |
| 1541 |
withdrawn => 4 |
| 1542 |
} |
| 1543 |
); |
| 1544 |
my $item_5 = $builder->build_sample_item( |
| 1545 |
{ |
| 1546 |
biblionumber => $biblio->biblionumber, |
| 1547 |
itype => $itype_1->itemtype, |
| 1548 |
withdrawn => 5 |
| 1549 |
} |
| 1550 |
); |
| 1551 |
my $item_6 = $builder->build_sample_item( |
| 1552 |
{ |
| 1553 |
biblionumber => $biblio->biblionumber, |
| 1554 |
itype => $itype_1->itemtype, |
| 1555 |
withdrawn => 5 |
| 1556 |
} |
| 1557 |
); |
| 1558 |
|
| 1559 |
my $rules = undef; |
| 1560 |
|
| 1561 |
my $mocked_context = Test::MockModule->new('C4::Context'); |
| 1562 |
$mocked_context->mock( 'yaml_preference', sub { |
| 1563 |
return $rules; |
| 1564 |
}); |
| 1565 |
|
| 1566 |
is( $biblio->items->filter_out_opachiddenitems->count, 6, 'No rules passed' ); |
| 1567 |
|
| 1568 |
$rules = {}; |
| 1569 |
|
| 1570 |
$rules = { withdrawn => [ 1, 2 ] }; |
| 1571 |
is( $biblio->items->filter_out_opachiddenitems->count, 4, 'Rules on withdrawn' ); |
| 1572 |
|
| 1573 |
$rules = { itype => [ $itype_1->itemtype ] }; |
| 1574 |
is( $biblio->items->filter_out_opachiddenitems->count, 2, 'Rules on itype' ); |
| 1575 |
|
| 1576 |
$rules = { withdrawn => [ 1, 2 ], itype => [ $itype_1->itemtype ] }; |
| 1577 |
is( $biblio->items->filter_out_opachiddenitems->count, 1, 'Rules on itype and withdrawn' ); |
| 1578 |
is( $biblio->items->filter_out_opachiddenitems->next->itemnumber, |
| 1579 |
$item_4->itemnumber, |
| 1580 |
'The right item is returned' |
| 1581 |
); |
| 1582 |
|
| 1583 |
$rules = { withdrawn => [ 1, 2 ], itype => [ $itype_2->itemtype ] }; |
| 1584 |
is( $biblio->items->filter_out_opachiddenitems->count, 3, 'Rules on itype and withdrawn' ); |
| 1585 |
|
| 1586 |
$schema->storage->txn_rollback; |
| 1587 |
}; |
| 1588 |
- |