Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 71; |
20 |
use Test::More tests => 73; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 1492-1494
subtest 'AlterPriorty() tests' => sub {
Link Here
|
1492 |
|
1492 |
|
1493 |
$schema->storage->txn_rollback; |
1493 |
$schema->storage->txn_rollback; |
1494 |
}; |
1494 |
}; |
1495 |
- |
1495 |
|
|
|
1496 |
subtest 'CanBookBeReserved() tests' => sub { |
1497 |
|
1498 |
plan tests => 4; |
1499 |
|
1500 |
$schema->storage->txn_begin; |
1501 |
|
1502 |
my $library = $builder->build_object( |
1503 |
{ class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
1504 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1505 |
my $itype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
1506 |
|
1507 |
my $biblio = $builder->build_sample_biblio(); |
1508 |
my $item_1 = $builder->build_sample_item( |
1509 |
{ biblionumber => $biblio->id, itype => $itype->id } ); |
1510 |
my $item_2 = $builder->build_sample_item( |
1511 |
{ biblionumber => $biblio->id, itype => $itype->id } ); |
1512 |
|
1513 |
Koha::CirculationRules->delete; |
1514 |
Koha::CirculationRules->set_rules( |
1515 |
{ |
1516 |
branchcode => undef, |
1517 |
categorycode => undef, |
1518 |
itemtype => undef, |
1519 |
rules => { |
1520 |
holds_per_record => 100, |
1521 |
} |
1522 |
} |
1523 |
); |
1524 |
Koha::CirculationRules->set_rules( |
1525 |
{ |
1526 |
branchcode => undef, |
1527 |
categorycode => undef, |
1528 |
itemtype => $itype->id, |
1529 |
rules => { |
1530 |
reservesallowed => 2, |
1531 |
} |
1532 |
} |
1533 |
); |
1534 |
|
1535 |
C4::Reserves::AddReserve( |
1536 |
{ |
1537 |
branchcode => $library->id, |
1538 |
borrowernumber => $patron->id, |
1539 |
biblionumber => $biblio->id, |
1540 |
title => $biblio->title, |
1541 |
itemnumber => $item_1->id |
1542 |
} |
1543 |
); |
1544 |
|
1545 |
## Limit on item type is 2, only one hold, success tests |
1546 |
|
1547 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1548 |
|
1549 |
my $res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1550 |
{ itemtype => $itype->id } ); |
1551 |
is_deeply( $res, { status => 'OK' }, |
1552 |
'Holds on itemtype limit not reached' ); |
1553 |
|
1554 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1555 |
|
1556 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1557 |
{ itemtype => $itype->id } ); |
1558 |
is_deeply( |
1559 |
$res, |
1560 |
{ status => 'OK' }, |
1561 |
'Holds on itemtype not considering biblio-level' |
1562 |
); |
1563 |
|
1564 |
# Add a second hold, biblio-level and item type-constrained |
1565 |
C4::Reserves::AddReserve( |
1566 |
{ |
1567 |
branchcode => $library->id, |
1568 |
borrowernumber => $patron->id, |
1569 |
biblionumber => $biblio->id, |
1570 |
title => $biblio->title, |
1571 |
itemtype => $itype->id, |
1572 |
} |
1573 |
); |
1574 |
|
1575 |
## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained |
1576 |
|
1577 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1578 |
|
1579 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1580 |
{ itemtype => $itype->id } ); |
1581 |
is_deeply( $res, { status => '' }, 'Holds on itemtype limit reached' ); |
1582 |
|
1583 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1584 |
|
1585 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1586 |
{ itemtype => $itype->id } ); |
1587 |
is_deeply( |
1588 |
$res, |
1589 |
{ status => 'OK' }, |
1590 |
'Holds on itemtype not considering biblio-level' |
1591 |
); |
1592 |
|
1593 |
$schema->storage->txn_rollback; |
1594 |
}; |
1595 |
|
1596 |
subtest 'CanItemBeReserved() tests' => sub { |
1597 |
|
1598 |
plan tests => 4; |
1599 |
|
1600 |
$schema->storage->txn_begin; |
1601 |
|
1602 |
my $library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
1603 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1604 |
my $itype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
1605 |
|
1606 |
my $biblio = $builder->build_sample_biblio(); |
1607 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id }); |
1608 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id }); |
1609 |
|
1610 |
Koha::CirculationRules->delete; |
1611 |
Koha::CirculationRules->set_rules( |
1612 |
{ branchcode => undef, |
1613 |
categorycode => undef, |
1614 |
itemtype => undef, |
1615 |
rules => { |
1616 |
holds_per_record => 100, |
1617 |
} |
1618 |
} |
1619 |
); |
1620 |
Koha::CirculationRules->set_rules( |
1621 |
{ branchcode => undef, |
1622 |
categorycode => undef, |
1623 |
itemtype => $itype->id, |
1624 |
rules => { |
1625 |
reservesallowed => 2, |
1626 |
} |
1627 |
} |
1628 |
); |
1629 |
|
1630 |
C4::Reserves::AddReserve( |
1631 |
{ |
1632 |
branchcode => $library->id, |
1633 |
borrowernumber => $patron->id, |
1634 |
biblionumber => $biblio->id, |
1635 |
title => $biblio->title, |
1636 |
itemnumber => $item_1->id |
1637 |
} |
1638 |
); |
1639 |
|
1640 |
## Limit on item type is 2, only one hold, success tests |
1641 |
|
1642 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1643 |
|
1644 |
my $res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1645 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype limit not reached' ); |
1646 |
|
1647 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1648 |
|
1649 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1650 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype not considering biblio-level' ); |
1651 |
|
1652 |
# Add a second hold, biblio-level and item type-constrained |
1653 |
C4::Reserves::AddReserve( |
1654 |
{ |
1655 |
branchcode => $library->id, |
1656 |
borrowernumber => $patron->id, |
1657 |
biblionumber => $biblio->id, |
1658 |
title => $biblio->title, |
1659 |
itemtype => $itype->id, |
1660 |
} |
1661 |
); |
1662 |
|
1663 |
## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained |
1664 |
|
1665 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1666 |
|
1667 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1668 |
is_deeply( $res, { status => 'tooManyReserves', limit => 2 }, 'Holds on itemtype limit reached' ); |
1669 |
|
1670 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1671 |
|
1672 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1673 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype not considering biblio-level' ); |
1674 |
|
1675 |
$schema->storage->txn_rollback; |
1676 |
}; |