Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 69; |
20 |
use Test::More tests => 71; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 1397-1399
subtest 'IsAvailableForItemLevelRequest() tests' => sub {
Link Here
|
1397 |
|
1397 |
|
1398 |
$schema->storage->txn_rollback; |
1398 |
$schema->storage->txn_rollback; |
1399 |
}; |
1399 |
}; |
1400 |
- |
1400 |
|
|
|
1401 |
subtest 'CanBookBeReserved() tests' => sub { |
1402 |
|
1403 |
plan tests => 4; |
1404 |
|
1405 |
$schema->storage->txn_begin; |
1406 |
|
1407 |
my $library = $builder->build_object( |
1408 |
{ class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
1409 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1410 |
my $itype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
1411 |
|
1412 |
my $biblio = $builder->build_sample_biblio(); |
1413 |
my $item_1 = $builder->build_sample_item( |
1414 |
{ biblionumber => $biblio->id, itype => $itype->id } ); |
1415 |
my $item_2 = $builder->build_sample_item( |
1416 |
{ biblionumber => $biblio->id, itype => $itype->id } ); |
1417 |
|
1418 |
Koha::CirculationRules->delete; |
1419 |
Koha::CirculationRules->set_rules( |
1420 |
{ |
1421 |
branchcode => undef, |
1422 |
categorycode => undef, |
1423 |
itemtype => undef, |
1424 |
rules => { |
1425 |
holds_per_record => 100, |
1426 |
} |
1427 |
} |
1428 |
); |
1429 |
Koha::CirculationRules->set_rules( |
1430 |
{ |
1431 |
branchcode => undef, |
1432 |
categorycode => undef, |
1433 |
itemtype => $itype->id, |
1434 |
rules => { |
1435 |
reservesallowed => 2, |
1436 |
} |
1437 |
} |
1438 |
); |
1439 |
|
1440 |
C4::Reserves::AddReserve( |
1441 |
{ |
1442 |
branchcode => $library->id, |
1443 |
borrowernumber => $patron->id, |
1444 |
biblionumber => $biblio->id, |
1445 |
title => $biblio->title, |
1446 |
itemnumber => $item_1->id |
1447 |
} |
1448 |
); |
1449 |
|
1450 |
## Limit on item type is 2, only one hold, success tests |
1451 |
|
1452 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1453 |
|
1454 |
my $res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1455 |
{ itemtype => $itype->id } ); |
1456 |
is_deeply( $res, { status => 'OK' }, |
1457 |
'Holds on itemtype limit not reached' ); |
1458 |
|
1459 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1460 |
|
1461 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1462 |
{ itemtype => $itype->id } ); |
1463 |
is_deeply( |
1464 |
$res, |
1465 |
{ status => 'OK' }, |
1466 |
'Holds on itemtype not considering biblio-level' |
1467 |
); |
1468 |
|
1469 |
# Add a second hold, biblio-level and item type-constrained |
1470 |
C4::Reserves::AddReserve( |
1471 |
{ |
1472 |
branchcode => $library->id, |
1473 |
borrowernumber => $patron->id, |
1474 |
biblionumber => $biblio->id, |
1475 |
title => $biblio->title, |
1476 |
itemtype => $itype->id, |
1477 |
} |
1478 |
); |
1479 |
|
1480 |
## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained |
1481 |
|
1482 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1483 |
|
1484 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1485 |
{ itemtype => $itype->id } ); |
1486 |
is_deeply( $res, { status => '' }, 'Holds on itemtype limit reached' ); |
1487 |
|
1488 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1489 |
|
1490 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1491 |
{ itemtype => $itype->id } ); |
1492 |
is_deeply( |
1493 |
$res, |
1494 |
{ status => 'OK' }, |
1495 |
'Holds on itemtype not considering biblio-level' |
1496 |
); |
1497 |
|
1498 |
$schema->storage->txn_rollback; |
1499 |
}; |
1500 |
|
1501 |
|
1502 |
subtest 'CanItemBeReserved() tests' => sub { |
1503 |
|
1504 |
plan tests => 4; |
1505 |
|
1506 |
$schema->storage->txn_begin; |
1507 |
|
1508 |
my $library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
1509 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1510 |
my $itype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
1511 |
|
1512 |
my $biblio = $builder->build_sample_biblio(); |
1513 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id }); |
1514 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id }); |
1515 |
|
1516 |
Koha::CirculationRules->delete; |
1517 |
Koha::CirculationRules->set_rules( |
1518 |
{ branchcode => undef, |
1519 |
categorycode => undef, |
1520 |
itemtype => undef, |
1521 |
rules => { |
1522 |
holds_per_record => 100, |
1523 |
} |
1524 |
} |
1525 |
); |
1526 |
Koha::CirculationRules->set_rules( |
1527 |
{ branchcode => undef, |
1528 |
categorycode => undef, |
1529 |
itemtype => $itype->id, |
1530 |
rules => { |
1531 |
reservesallowed => 2, |
1532 |
} |
1533 |
} |
1534 |
); |
1535 |
|
1536 |
C4::Reserves::AddReserve( |
1537 |
{ |
1538 |
branchcode => $library->id, |
1539 |
borrowernumber => $patron->id, |
1540 |
biblionumber => $biblio->id, |
1541 |
title => $biblio->title, |
1542 |
itemnumber => $item_1->id |
1543 |
} |
1544 |
); |
1545 |
|
1546 |
## Limit on item type is 2, only one hold, success tests |
1547 |
|
1548 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1549 |
|
1550 |
my $res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1551 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype limit not reached' ); |
1552 |
|
1553 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1554 |
|
1555 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1556 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype not considering biblio-level' ); |
1557 |
|
1558 |
# Add a second hold, biblio-level and item type-constrained |
1559 |
C4::Reserves::AddReserve( |
1560 |
{ |
1561 |
branchcode => $library->id, |
1562 |
borrowernumber => $patron->id, |
1563 |
biblionumber => $biblio->id, |
1564 |
title => $biblio->title, |
1565 |
itemtype => $itype->id, |
1566 |
} |
1567 |
); |
1568 |
|
1569 |
## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained |
1570 |
|
1571 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1572 |
|
1573 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1574 |
is_deeply( $res, { status => 'tooManyReserves', limit => 2 }, 'Holds on itemtype limit reached' ); |
1575 |
|
1576 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1577 |
|
1578 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1579 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype not considering biblio-level' ); |
1580 |
|
1581 |
$schema->storage->txn_rollback; |
1582 |
}; |