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

(-)a/t/db_dependent/Circulation.t (-3 / +116 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 113;
20
use Test::More tests => 114;
21
21
22
use DateTime;
22
use DateTime;
23
23
Lines 220-226 C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'"); Link Here
220
C4::Context->dbh->do("DELETE FROM accountlines");
220
C4::Context->dbh->do("DELETE FROM accountlines");
221
{
221
{
222
# CanBookBeRenewed tests
222
# CanBookBeRenewed tests
223
223
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' ); #Ensure pref doesn't affect current tests
224
    # Generate test biblio
224
    # Generate test biblio
225
    my $title = 'Silence in the library';
225
    my $title = 'Silence in the library';
226
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
226
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
Lines 2044-2050 subtest 'CanBookBeIssued | is_overdue' => sub { Link Here
2044
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->{barcode},$ten_days_go, undef, undef, undef);
2044
    my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->{barcode},$ten_days_go, undef, undef, undef);
2045
    is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal");
2045
    is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal");
2046
    is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal");
2046
    is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal");
2047
};
2048
2049
subtest 'ItemsDeniedRenewal preference' => sub {
2050
    plan tests => 16;
2047
2051
2052
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' );
2053
2054
    $dbh->do('DELETE FROM issues');
2055
    $dbh->do('DELETE FROM items');
2056
    $dbh->do('DELETE FROM issuingrules');
2057
    $dbh->do(
2058
        q{
2059
        INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod,
2060
                    norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
2061
        },
2062
        {},
2063
        '*', '*', '*', 25,
2064
        20,  14,  'days',
2065
        10,   7,
2066
        undef,  0,
2067
        .10, 1
2068
    );
2069
2070
    my $deny_book = $builder->build_object({ class => 'Koha::Items', value => {
2071
        withdrawn => 1,
2072
        itype => 'HIDE',
2073
        location => 'PROC',
2074
        itemcallnumber => undef,
2075
        itemnotes => "",
2076
        }
2077
    });
2078
    my $allow_book = $builder->build_object({ class => 'Koha::Items', value => {
2079
        withdrawn => 0,
2080
        itype => 'NOHIDE',
2081
        location => 'NOPROC'
2082
        }
2083
    });
2084
2085
    my $idr_borrower = $builder->build_object({ class => 'Koha::Patrons'});
2086
    my $future = dt_from_string->add( days => 1 );
2087
    my $deny_issue = $builder->build_object({ class => 'Koha::Checkouts', value => {
2088
        returndate => undef,
2089
        renewals => 0,
2090
        auto_renew => 0,
2091
        borrowernumber => $idr_borrower->borrowernumber,
2092
        itemnumber => $deny_book->itemnumber,
2093
        onsite_checkout => 0,
2094
        date_due => $future,
2095
        }
2096
    });
2097
    my $allow_issue = $builder->build_object({ class => 'Koha::Checkouts', value => {
2098
        returndate => undef,
2099
        renewals => 0,
2100
        auto_renew => 0,
2101
        borrowernumber => $idr_borrower->borrowernumber,
2102
        itemnumber => $allow_book->itemnumber,
2103
        onsite_checkout => 0,
2104
        date_due => $future,
2105
        }
2106
    });
2107
2108
    my $idr_rules;
2109
2110
    my ( $idr_mayrenew, $idr_error ) =
2111
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
2112
    is( $idr_mayrenew, 1, 'Renewal allowed when no rules' );
2113
    is( $idr_error, undef, 'Renewal allowed when no rules' );
2114
2115
    $idr_rules="withdrawn: [1]";
2116
2117
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules );
2118
    ( $idr_mayrenew, $idr_error ) =
2119
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
2120
    is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' );
2121
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' );
2122
    ( $idr_mayrenew, $idr_error ) =
2123
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
2124
    is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' );
2125
    is( $idr_error, undef, 'Renewal allowed when 1 rules not matched (withdrawn)' );
2126
2127
    $idr_rules="withdrawn: [1]\ntype: [HIDE,INVISILE]";
2128
2129
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules );
2130
    ( $idr_mayrenew, $idr_error ) =
2131
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
2132
    is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' );
2133
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' );
2134
    ( $idr_mayrenew, $idr_error ) =
2135
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
2136
    is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
2137
    is( $idr_error, undef, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
2138
2139
    $idr_rules="withdrawn: [1]\nitype: [HIDE,INVISIBLE]\nlocation: [PROC]";
2140
2141
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules );
2142
    ( $idr_mayrenew, $idr_error ) =
2143
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
2144
    is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' );
2145
    is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' );
2146
    ( $idr_mayrenew, $idr_error ) =
2147
    CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber );
2148
    is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
2149
    is( $idr_error, undef, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
2150
2151
    $idr_rules="itemcallnumber: [NULL]";
2152
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules );
2153
    ( $idr_mayrenew, $idr_error ) =
2154
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
2155
    is( $idr_mayrenew, 0, 'Renewal blocked for undef when NULL in pref' );
2156
2157
    $idr_rules="itemnotes: ['']";
2158
    t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules );
2159
    ( $idr_mayrenew, $idr_error ) =
2160
    CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber );
2161
    is( $idr_mayrenew, 0, 'Renewal blocked for empty string when "" in pref' );
2048
};
2162
};
2049
2163
2050
sub set_userenv {
2164
sub set_userenv {
2051
- 

Return to bug 15494