View | Details | Raw Unified | Return to bug 28529
Collapse All | Expand All

(-)a/t/db_dependent/Reserves.t (-2 / +145 lines)
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 => 2;
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
    my $res = CanBookBeReserved( $patron->id, $biblio->id, $library->id,
1575
        { itemtype => $itype->id } );
1576
    is_deeply( $res, { status => 'OK' },
1577
        'Holds on itemtype limit not reached' );
1578
1579
    # Add a second hold, biblio-level and item type-constrained
1580
    C4::Reserves::AddReserve(
1581
        {
1582
            branchcode     => $library->id,
1583
            borrowernumber => $patron->id,
1584
            biblionumber   => $biblio->id,
1585
            title          => $biblio->title,
1586
            itemtype       => $itype->id,
1587
        }
1588
    );
1589
1590
    ## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained
1591
1592
    $res = CanBookBeReserved( $patron->id, $biblio->id, $library->id,
1593
        { itemtype => $itype->id } );
1594
    is_deeply( $res, { status => '' }, 'Holds on itemtype limit reached' );
1595
1596
    $schema->storage->txn_rollback;
1597
};
1598
1599
subtest 'CanItemBeReserved() tests' => sub {
1600
1601
    plan tests => 2;
1602
1603
    $schema->storage->txn_begin;
1604
1605
    my $library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
1606
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
1607
    my $itype   = $builder->build_object( { class => 'Koha::ItemTypes' } );
1608
1609
    my $biblio = $builder->build_sample_biblio();
1610
    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id });
1611
    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->id, itype => $itype->id });
1612
1613
    Koha::CirculationRules->delete;
1614
    Koha::CirculationRules->set_rules(
1615
        {   branchcode   => undef,
1616
            categorycode => undef,
1617
            itemtype     => undef,
1618
            rules        => {
1619
                holds_per_record => 100,
1620
            }
1621
        }
1622
    );
1623
    Koha::CirculationRules->set_rules(
1624
        {   branchcode   => undef,
1625
            categorycode => undef,
1626
            itemtype     => $itype->id,
1627
            rules        => {
1628
                reservesallowed => 2,
1629
            }
1630
        }
1631
    );
1632
1633
    C4::Reserves::AddReserve(
1634
        {
1635
            branchcode     => $library->id,
1636
            borrowernumber => $patron->id,
1637
            biblionumber   => $biblio->id,
1638
            title          => $biblio->title,
1639
            itemnumber     => $item_1->id
1640
        }
1641
    );
1642
1643
    ## Limit on item type is 2, only one hold, success tests
1644
1645
    my $res = CanItemBeReserved( $patron, $item_2, $library->id );
1646
    is_deeply( $res, { status => 'OK' }, 'Holds on itemtype limit not reached' );
1647
1648
    # Add a second hold, biblio-level and item type-constrained
1649
    C4::Reserves::AddReserve(
1650
        {
1651
            branchcode     => $library->id,
1652
            borrowernumber => $patron->id,
1653
            biblionumber   => $biblio->id,
1654
            title          => $biblio->title,
1655
            itemtype       => $itype->id,
1656
        }
1657
    );
1658
1659
    ## Limit on item type is 2, two holds, one of them biblio-level/item type-constrained
1660
1661
    $res = CanItemBeReserved( $patron, $item_2, $library->id );
1662
    is_deeply( $res, { status => 'tooManyReserves', limit => 2 }, 'Holds on itemtype limit reached' );
1663
1664
    $schema->storage->txn_rollback;
1665
};

Return to bug 28529