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 1519-1521
subtest 'AlterPriorty() tests' => sub {
Link Here
|
1519 |
|
1519 |
|
1520 |
$schema->storage->txn_rollback; |
1520 |
$schema->storage->txn_rollback; |
1521 |
}; |
1521 |
}; |
1522 |
- |
1522 |
|
|
|
1523 |
subtest 'CanBookBeReserved() tests' => sub { |
1524 |
|
1525 |
plan tests => 4; |
1526 |
|
1527 |
$schema->storage->txn_begin; |
1528 |
|
1529 |
my $library = $builder->build_object( |
1530 |
{ class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
1531 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1532 |
my $itype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
1533 |
|
1534 |
my $biblio = $builder->build_sample_biblio(); |
1535 |
my $item_1 = $builder->build_sample_item( |
1536 |
{ biblionumber => $biblio->id, itype => $itype->id } ); |
1537 |
my $item_2 = $builder->build_sample_item( |
1538 |
{ biblionumber => $biblio->id, itype => $itype->id } ); |
1539 |
|
1540 |
Koha::CirculationRules->delete; |
1541 |
Koha::CirculationRules->set_rules( |
1542 |
{ |
1543 |
branchcode => undef, |
1544 |
categorycode => undef, |
1545 |
itemtype => undef, |
1546 |
rules => { |
1547 |
holds_per_record => 100, |
1548 |
} |
1549 |
} |
1550 |
); |
1551 |
Koha::CirculationRules->set_rules( |
1552 |
{ |
1553 |
branchcode => undef, |
1554 |
categorycode => undef, |
1555 |
itemtype => $itype->id, |
1556 |
rules => { |
1557 |
reservesallowed => 2, |
1558 |
} |
1559 |
} |
1560 |
); |
1561 |
|
1562 |
C4::Reserves::AddReserve( |
1563 |
{ |
1564 |
branchcode => $library->id, |
1565 |
borrowernumber => $patron->id, |
1566 |
biblionumber => $biblio->id, |
1567 |
title => $biblio->title, |
1568 |
itemnumber => $item_1->id |
1569 |
} |
1570 |
); |
1571 |
|
1572 |
## Limit on item type is 2, only one hold, success tests |
1573 |
|
1574 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1575 |
|
1576 |
my $res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1577 |
{ itemtype => $itype->id } ); |
1578 |
is_deeply( $res, { status => 'OK' }, |
1579 |
'Holds on itemtype limit not reached' ); |
1580 |
|
1581 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1582 |
|
1583 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1584 |
{ itemtype => $itype->id } ); |
1585 |
is_deeply( |
1586 |
$res, |
1587 |
{ status => 'OK' }, |
1588 |
'Holds on itemtype not considering biblio-level' |
1589 |
); |
1590 |
|
1591 |
# Add a second hold, biblio-level and item type-constrained |
1592 |
C4::Reserves::AddReserve( |
1593 |
{ |
1594 |
branchcode => $library->id, |
1595 |
borrowernumber => $patron->id, |
1596 |
biblionumber => $biblio->id, |
1597 |
title => $biblio->title, |
1598 |
itemtype => $itype->id, |
1599 |
} |
1600 |
); |
1601 |
|
1602 |
## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained |
1603 |
|
1604 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1605 |
|
1606 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1607 |
{ itemtype => $itype->id } ); |
1608 |
is_deeply( $res, { status => '' }, 'Holds on itemtype limit reached' ); |
1609 |
|
1610 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1611 |
|
1612 |
$res = CanBookBeReserved( $patron->id, $biblio->id, $library->id, |
1613 |
{ itemtype => $itype->id } ); |
1614 |
is_deeply( |
1615 |
$res, |
1616 |
{ status => 'OK' }, |
1617 |
'Holds on itemtype not considering biblio-level' |
1618 |
); |
1619 |
|
1620 |
$schema->storage->txn_rollback; |
1621 |
}; |
1622 |
|
1623 |
subtest 'CanItemBeReserved() tests' => sub { |
1624 |
|
1625 |
plan tests => 4; |
1626 |
|
1627 |
$schema->storage->txn_begin; |
1628 |
|
1629 |
my $library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
1630 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1631 |
my $itype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
1632 |
|
1633 |
my $biblio = $builder->build_sample_biblio(); |
1634 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id }); |
1635 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id }); |
1636 |
|
1637 |
Koha::CirculationRules->delete; |
1638 |
Koha::CirculationRules->set_rules( |
1639 |
{ branchcode => undef, |
1640 |
categorycode => undef, |
1641 |
itemtype => undef, |
1642 |
rules => { |
1643 |
holds_per_record => 100, |
1644 |
} |
1645 |
} |
1646 |
); |
1647 |
Koha::CirculationRules->set_rules( |
1648 |
{ branchcode => undef, |
1649 |
categorycode => undef, |
1650 |
itemtype => $itype->id, |
1651 |
rules => { |
1652 |
reservesallowed => 2, |
1653 |
} |
1654 |
} |
1655 |
); |
1656 |
|
1657 |
C4::Reserves::AddReserve( |
1658 |
{ |
1659 |
branchcode => $library->id, |
1660 |
borrowernumber => $patron->id, |
1661 |
biblionumber => $biblio->id, |
1662 |
title => $biblio->title, |
1663 |
itemnumber => $item_1->id |
1664 |
} |
1665 |
); |
1666 |
|
1667 |
## Limit on item type is 2, only one hold, success tests |
1668 |
|
1669 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1670 |
|
1671 |
my $res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1672 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype limit not reached' ); |
1673 |
|
1674 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1675 |
|
1676 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1677 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype not considering biblio-level' ); |
1678 |
|
1679 |
# Add a second hold, biblio-level and item type-constrained |
1680 |
C4::Reserves::AddReserve( |
1681 |
{ |
1682 |
branchcode => $library->id, |
1683 |
borrowernumber => $patron->id, |
1684 |
biblionumber => $biblio->id, |
1685 |
title => $biblio->title, |
1686 |
itemtype => $itype->id, |
1687 |
} |
1688 |
); |
1689 |
|
1690 |
## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained |
1691 |
|
1692 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 1 ); |
1693 |
|
1694 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1695 |
is_deeply( $res, { status => 'tooManyReserves', limit => 2 }, 'Holds on itemtype limit reached' ); |
1696 |
|
1697 |
t::lib::Mocks::mock_preference( 'BiblioHoldItemTypeUseForRules', 0 ); |
1698 |
|
1699 |
$res = CanItemBeReserved( $patron, $item_2, $library->id ); |
1700 |
is_deeply( $res, { status => 'OK' }, 'Holds on itemtype not considering biblio-level' ); |
1701 |
|
1702 |
$schema->storage->txn_rollback; |
1703 |
}; |