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

(-)a/t/db_dependent/Circulation.t (-3 / +108 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 95;
20
use Test::More tests => 96;
21
21
22
use DateTime;
22
use DateTime;
23
23
Lines 205-211 C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'"); Link Here
205
C4::Context->dbh->do("DELETE FROM accountlines");
205
C4::Context->dbh->do("DELETE FROM accountlines");
206
{
206
{
207
# CanBookBeRenewed tests
207
# CanBookBeRenewed tests
208
208
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' ); #Ensure pref doesn't affect current tests
209
    # Generate test biblio
209
    # Generate test biblio
210
    my $biblio = MARC::Record->new();
210
    my $biblio = MARC::Record->new();
211
    my $title = 'Silence in the library';
211
    my $title = 'Silence in the library';
Lines 1626-1631 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1626
    is( $debarments->[0]->{expiration}, $expected_expiration );
1626
    is( $debarments->[0]->{expiration}, $expected_expiration );
1627
};
1627
};
1628
1628
1629
subtest 'ItemsDeniedRenewal preference' => sub {
1630
    plan tests => 14;
1631
1632
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' );
1633
1634
    $dbh->do('DELETE FROM issues');
1635
    $dbh->do('DELETE FROM items');
1636
    $dbh->do('DELETE FROM issuingrules');
1637
    $dbh->do(
1638
        q{
1639
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
1640
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
1641
        },
1642
        {},
1643
        '*', '*', '*', 25,
1644
        20,  14,  'days',
1645
        10,   7,
1646
        undef,  0,
1647
        .10, 1
1648
    );
1649
1650
    my $deny_book = $builder->build_object({ class => 'Koha::Items', value => {
1651
        withdrawn => 1,
1652
        itype => 'HIDE',
1653
        location => 'PROC'
1654
        }
1655
    });
1656
    my $allow_book = $builder->build_object({ class => 'Koha::Items', value => {
1657
        withdrawn => 0,
1658
        itype => 'NOHIDE',
1659
        location => 'NOPROC'
1660
        }
1661
    });
1662
1663
    my $idr_borrower = $builder->build_object({ class => 'Koha::Patrons'});
1664
1665
    my $deny_issue = $builder->build_object({ class => 'Koha::Checkouts', value => {
1666
        returndate => undef,
1667
        renewals => 0,
1668
        auto_renew => 0,
1669
        borrowernumber => $idr_borrower->borrowernumber,
1670
        itemnumber => $deny_book->itemnumber,
1671
        onsite_checkout => 0,
1672
        }
1673
    });
1674
    my $allow_issue = $builder->build_object({ class => 'Koha::Checkouts', value => {
1675
        returndate => undef,
1676
        renewals => 0,
1677
        auto_renew => 0,
1678
        borrowernumber => $idr_borrower->borrowernumber,
1679
        itemnumber => $allow_book->itemnumber,
1680
        onsite_checkout => 0,
1681
        }
1682
    });
1683
1684
    my $idr_rules;
1685
1686
    my ( $idr_mayrenew, $idr_error ) =
1687
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
1688
    is( $idr_mayrenew, 1, 'Renewal allowed when no rules' );
1689
    is( $idr_error, undef, 'Renewal allowed when no rules' );
1690
1691
    $idr_rules="
1692
        withdrawn: [1]";
1693
1694
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules );
1695
    ( $idr_mayrenew, $idr_error ) =
1696
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
1697
    is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' );
1698
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' );
1699
    ( $idr_mayrenew, $idr_error ) =
1700
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
1701
    is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' );
1702
    is( $idr_error, undef, 'Renewal allowed when 1 rules not matched (withdrawn)' );
1703
1704
    $idr_rules="
1705
        withdrawn: [1]
1706
        itype: [HIDE,INVISILE]";
1707
1708
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules );
1709
    ( $idr_mayrenew, $idr_error ) =
1710
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
1711
    is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' );
1712
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' );
1713
    ( $idr_mayrenew, $idr_error ) =
1714
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
1715
    is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
1716
    is( $idr_error, undef, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
1717
1718
    $idr_rules="
1719
        withdrawn: [1]
1720
        itype: [HIDE,INVISIBLE]
1721
        location: [PROC]";
1722
1723
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules );
1724
    ( $idr_mayrenew, $idr_error ) =
1725
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
1726
    is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' );
1727
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' );
1728
    ( $idr_mayrenew, $idr_error ) =
1729
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
1730
    is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
1731
    is( $idr_error, undef, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
1732
1733
};
1734
1629
sub set_userenv {
1735
sub set_userenv {
1630
    my ( $library ) = @_;
1736
    my ( $library ) = @_;
1631
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
1737
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
1632
- 

Return to bug 15494