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 |
use Time::Fake; |
26 |
use Time::Fake; |
25 |
|
27 |
|
Lines 1321-1330
$schema->storage->txn_rollback;
Link Here
|
1321 |
|
1323 |
|
1322 |
subtest 'filter_by_visible_in_opac() tests' => sub { |
1324 |
subtest 'filter_by_visible_in_opac() tests' => sub { |
1323 |
|
1325 |
|
1324 |
plan tests => 8; |
1326 |
plan tests => 11; |
1325 |
|
1327 |
|
1326 |
$schema->storage->txn_begin; |
1328 |
$schema->storage->txn_begin; |
1327 |
|
1329 |
|
|
|
1330 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1331 |
my $mocked_category = Test::MockModule->new('Koha::Patron::Category'); |
1332 |
my $exception = 1; |
1333 |
$mocked_category->mock( 'override_hidden_items', sub { |
1334 |
return $exception; |
1335 |
}); |
1336 |
|
1328 |
# have a fresh biblio |
1337 |
# have a fresh biblio |
1329 |
my $biblio = $builder->build_sample_biblio; |
1338 |
my $biblio = $builder->build_sample_biblio; |
1330 |
# have two itemtypes |
1339 |
# have two itemtypes |
Lines 1391-1396
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
1391 |
is( $biblio->items->filter_by_visible_in_opac->count, |
1400 |
is( $biblio->items->filter_by_visible_in_opac->count, |
1392 |
6, 'No rules passed, hidelostitems unset' ); |
1401 |
6, 'No rules passed, hidelostitems unset' ); |
1393 |
|
1402 |
|
|
|
1403 |
is( $biblio->items->filter_by_visible_in_opac({ patron => $patron })->count, |
1404 |
6, 'No rules passed, hidelostitems unset, patron exception changes nothing' ); |
1405 |
|
1394 |
$rules = {}; |
1406 |
$rules = {}; |
1395 |
|
1407 |
|
1396 |
t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); |
1408 |
t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); |
Lines 1400-1405
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
1400 |
'No rules passed, hidelostitems set' |
1412 |
'No rules passed, hidelostitems set' |
1401 |
); |
1413 |
); |
1402 |
|
1414 |
|
|
|
1415 |
is( |
1416 |
$biblio->items->filter_by_visible_in_opac({ patron => $patron })->count, |
1417 |
3, |
1418 |
'No rules passed, hidelostitems set, patron exception changes nothing' |
1419 |
); |
1420 |
|
1403 |
$rules = { withdrawn => [ 1, 2 ] }; |
1421 |
$rules = { withdrawn => [ 1, 2 ] }; |
1404 |
is( |
1422 |
is( |
1405 |
$biblio->items->filter_by_visible_in_opac->count, |
1423 |
$biblio->items->filter_by_visible_in_opac->count, |
Lines 1407-1412
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
1407 |
'Rules on withdrawn, hidelostitems set' |
1425 |
'Rules on withdrawn, hidelostitems set' |
1408 |
); |
1426 |
); |
1409 |
|
1427 |
|
|
|
1428 |
is( |
1429 |
$biblio->items->filter_by_visible_in_opac({ patron => $patron })->count, |
1430 |
3, |
1431 |
'hidelostitems set, rules on withdrawn but patron override passed' |
1432 |
); |
1433 |
|
1410 |
$rules = { itype => [ $itype_1->itemtype ] }; |
1434 |
$rules = { itype => [ $itype_1->itemtype ] }; |
1411 |
is( |
1435 |
is( |
1412 |
$biblio->items->filter_by_visible_in_opac->count, |
1436 |
$biblio->items->filter_by_visible_in_opac->count, |
Lines 1442-1444
subtest 'filter_by_visible_in_opac() tests' => sub {
Link Here
|
1442 |
|
1466 |
|
1443 |
$schema->storage->txn_rollback; |
1467 |
$schema->storage->txn_rollback; |
1444 |
}; |
1468 |
}; |
1445 |
- |
1469 |
|
|
|
1470 |
subtest 'filter_out_lost() tests' => sub { |
1471 |
|
1472 |
plan tests => 2; |
1473 |
|
1474 |
$schema->storage->txn_begin; |
1475 |
|
1476 |
# have a fresh biblio |
1477 |
my $biblio = $builder->build_sample_biblio; |
1478 |
# have 3 items on that biblio |
1479 |
my $item_1 = $builder->build_sample_item( |
1480 |
{ |
1481 |
biblionumber => $biblio->biblionumber, |
1482 |
itemlost => -1, |
1483 |
} |
1484 |
); |
1485 |
my $item_2 = $builder->build_sample_item( |
1486 |
{ |
1487 |
biblionumber => $biblio->biblionumber, |
1488 |
itemlost => 0, |
1489 |
} |
1490 |
); |
1491 |
my $item_3 = $builder->build_sample_item( |
1492 |
{ |
1493 |
biblionumber => $biblio->biblionumber, |
1494 |
itemlost => 1, |
1495 |
} |
1496 |
); |
1497 |
|
1498 |
is( $biblio->items->filter_out_lost->next->itemnumber, $item_2->itemnumber, 'Right item returned' ); |
1499 |
is( $biblio->items->filter_out_lost->count, 1, 'Only one item is not lost' ); |
1500 |
|
1501 |
$schema->storage->txn_rollback; |
1502 |
}; |
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 |
}; |