|
Lines 1467-1475
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
| 1467 |
$schema->storage->txn_rollback; |
1467 |
$schema->storage->txn_rollback; |
| 1468 |
}; |
1468 |
}; |
| 1469 |
|
1469 |
|
| 1470 |
subtest 'filter_out_lost() tests' => sub { |
1470 |
subtest 'filter_by_lost() tests' => sub { |
| 1471 |
|
1471 |
|
| 1472 |
plan tests => 2; |
1472 |
plan tests => 3; |
| 1473 |
|
1473 |
|
| 1474 |
$schema->storage->txn_begin; |
1474 |
$schema->storage->txn_begin; |
| 1475 |
|
1475 |
|
|
Lines 1495-1587
subtest 'filter_out_lost() tests' => sub {
Link Here
|
| 1495 |
} |
1495 |
} |
| 1496 |
); |
1496 |
); |
| 1497 |
|
1497 |
|
| 1498 |
is( $biblio->items->filter_out_lost->next->itemnumber, $item_2->itemnumber, 'Right item returned' ); |
1498 |
my $results = $biblio->items->filter_by_lost; |
| 1499 |
is( $biblio->items->filter_out_lost->count, 1, 'Only one item is not lost' ); |
1499 |
is( $results->count, 2, 'Two items are not lost' ); |
|
|
1500 |
isnt( $results->next->itemnumber, $item_2->itemnumber, 'Right first item returned' ); |
| 1501 |
isnt( $results->next->itemnumber, $item_2->itemnumber, 'Right second item returned' ); |
| 1500 |
|
1502 |
|
| 1501 |
$schema->storage->txn_rollback; |
1503 |
$schema->storage->txn_rollback; |
| 1502 |
}; |
1504 |
}; |
| 1503 |
|
1505 |
|
| 1504 |
subtest 'filter_out_opachiddenitems() tests' => sub { |
1506 |
subtest 'filter_by_not_lost() tests' => sub { |
| 1505 |
|
1507 |
|
| 1506 |
plan tests => 6; |
1508 |
plan tests => 2; |
| 1507 |
|
1509 |
|
| 1508 |
$schema->storage->txn_begin; |
1510 |
$schema->storage->txn_begin; |
| 1509 |
|
1511 |
|
| 1510 |
# have a fresh biblio |
1512 |
# have a fresh biblio |
| 1511 |
my $biblio = $builder->build_sample_biblio; |
1513 |
my $biblio = $builder->build_sample_biblio; |
| 1512 |
# have two itemtypes |
1514 |
# have 3 items on that biblio |
| 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( |
1515 |
my $item_1 = $builder->build_sample_item( |
| 1517 |
{ |
1516 |
{ |
| 1518 |
biblionumber => $biblio->biblionumber, |
1517 |
biblionumber => $biblio->biblionumber, |
| 1519 |
itype => $itype_1->itemtype, |
1518 |
itemlost => -1, |
| 1520 |
withdrawn => 1 |
|
|
| 1521 |
} |
1519 |
} |
| 1522 |
); |
1520 |
); |
| 1523 |
my $item_2 = $builder->build_sample_item( |
1521 |
my $item_2 = $builder->build_sample_item( |
| 1524 |
{ |
1522 |
{ |
| 1525 |
biblionumber => $biblio->biblionumber, |
1523 |
biblionumber => $biblio->biblionumber, |
| 1526 |
itype => $itype_2->itemtype, |
1524 |
itemlost => 0, |
| 1527 |
withdrawn => 2 |
|
|
| 1528 |
} |
1525 |
} |
| 1529 |
); |
1526 |
); |
| 1530 |
my $item_3 = $builder->build_sample_item( |
1527 |
my $item_3 = $builder->build_sample_item( |
| 1531 |
{ |
1528 |
{ |
| 1532 |
biblionumber => $biblio->biblionumber, |
1529 |
biblionumber => $biblio->biblionumber, |
| 1533 |
itype => $itype_1->itemtype, |
1530 |
itemlost => 1, |
| 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 |
} |
1531 |
} |
| 1557 |
); |
1532 |
); |
| 1558 |
|
1533 |
|
| 1559 |
my $rules = undef; |
1534 |
is( $biblio->items->filter_by_not_lost->next->itemnumber, $item_2->itemnumber, 'Right item returned' ); |
| 1560 |
|
1535 |
is( $biblio->items->filter_by_not_lost->count, 1, 'Only one item is not lost' ); |
| 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 |
|
1536 |
|
| 1586 |
$schema->storage->txn_rollback; |
1537 |
$schema->storage->txn_rollback; |
| 1587 |
}; |
1538 |
}; |
| 1588 |
- |
|
|