Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 119; |
20 |
use Test::More tests => 120; |
21 |
|
21 |
|
22 |
use Data::Dumper; |
22 |
use Data::Dumper; |
23 |
use DateTime; |
23 |
use DateTime; |
Lines 226-232
C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'");
Link Here
|
226 |
C4::Context->dbh->do("DELETE FROM accountlines"); |
226 |
C4::Context->dbh->do("DELETE FROM accountlines"); |
227 |
{ |
227 |
{ |
228 |
# CanBookBeRenewed tests |
228 |
# CanBookBeRenewed tests |
229 |
|
229 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' ); #Ensure pref doesn't affect current tests |
230 |
# Generate test biblio |
230 |
# Generate test biblio |
231 |
my $title = 'Silence in the library'; |
231 |
my $title = 'Silence in the library'; |
232 |
my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven'); |
232 |
my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven'); |
Lines 2209-2215
subtest 'CanBookBeIssued | is_overdue' => sub {
Link Here
|
2209 |
my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->{barcode},$ten_days_go, undef, undef, undef); |
2209 |
my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->{barcode},$ten_days_go, undef, undef, undef); |
2210 |
is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal"); |
2210 |
is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal"); |
2211 |
is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal"); |
2211 |
is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal"); |
|
|
2212 |
}; |
2213 |
|
2214 |
subtest 'ItemsDeniedRenewal preference' => sub { |
2215 |
plan tests => 16; |
2212 |
|
2216 |
|
|
|
2217 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' ); |
2218 |
|
2219 |
$dbh->do('DELETE FROM issues'); |
2220 |
$dbh->do('DELETE FROM items'); |
2221 |
$dbh->do('DELETE FROM issuingrules'); |
2222 |
$dbh->do( |
2223 |
q{ |
2224 |
INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod, |
2225 |
norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) |
2226 |
}, |
2227 |
{}, |
2228 |
'*', '*', '*', 25, |
2229 |
20, 14, 'days', |
2230 |
10, 7, |
2231 |
undef, 0, |
2232 |
.10, 1 |
2233 |
); |
2234 |
|
2235 |
my $deny_book = $builder->build_object({ class => 'Koha::Items', value => { |
2236 |
withdrawn => 1, |
2237 |
itype => 'HIDE', |
2238 |
location => 'PROC', |
2239 |
itemcallnumber => undef, |
2240 |
itemnotes => "", |
2241 |
} |
2242 |
}); |
2243 |
my $allow_book = $builder->build_object({ class => 'Koha::Items', value => { |
2244 |
withdrawn => 0, |
2245 |
itype => 'NOHIDE', |
2246 |
location => 'NOPROC' |
2247 |
} |
2248 |
}); |
2249 |
|
2250 |
my $idr_borrower = $builder->build_object({ class => 'Koha::Patrons'}); |
2251 |
my $future = dt_from_string->add( days => 1 ); |
2252 |
my $deny_issue = $builder->build_object({ class => 'Koha::Checkouts', value => { |
2253 |
returndate => undef, |
2254 |
renewals => 0, |
2255 |
auto_renew => 0, |
2256 |
borrowernumber => $idr_borrower->borrowernumber, |
2257 |
itemnumber => $deny_book->itemnumber, |
2258 |
onsite_checkout => 0, |
2259 |
date_due => $future, |
2260 |
} |
2261 |
}); |
2262 |
my $allow_issue = $builder->build_object({ class => 'Koha::Checkouts', value => { |
2263 |
returndate => undef, |
2264 |
renewals => 0, |
2265 |
auto_renew => 0, |
2266 |
borrowernumber => $idr_borrower->borrowernumber, |
2267 |
itemnumber => $allow_book->itemnumber, |
2268 |
onsite_checkout => 0, |
2269 |
date_due => $future, |
2270 |
} |
2271 |
}); |
2272 |
|
2273 |
my $idr_rules; |
2274 |
|
2275 |
my ( $idr_mayrenew, $idr_error ) = |
2276 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
2277 |
is( $idr_mayrenew, 1, 'Renewal allowed when no rules' ); |
2278 |
is( $idr_error, undef, 'Renewal allowed when no rules' ); |
2279 |
|
2280 |
$idr_rules="withdrawn: [1]"; |
2281 |
|
2282 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); |
2283 |
( $idr_mayrenew, $idr_error ) = |
2284 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
2285 |
is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' ); |
2286 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' ); |
2287 |
( $idr_mayrenew, $idr_error ) = |
2288 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
2289 |
is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' ); |
2290 |
is( $idr_error, undef, 'Renewal allowed when 1 rules not matched (withdrawn)' ); |
2291 |
|
2292 |
$idr_rules="withdrawn: [1]\ntype: [HIDE,INVISILE]"; |
2293 |
|
2294 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); |
2295 |
( $idr_mayrenew, $idr_error ) = |
2296 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
2297 |
is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' ); |
2298 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' ); |
2299 |
( $idr_mayrenew, $idr_error ) = |
2300 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
2301 |
is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); |
2302 |
is( $idr_error, undef, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); |
2303 |
|
2304 |
$idr_rules="withdrawn: [1]\nitype: [HIDE,INVISIBLE]\nlocation: [PROC]"; |
2305 |
|
2306 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); |
2307 |
( $idr_mayrenew, $idr_error ) = |
2308 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
2309 |
is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' ); |
2310 |
is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' ); |
2311 |
( $idr_mayrenew, $idr_error ) = |
2312 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); |
2313 |
is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); |
2314 |
is( $idr_error, undef, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); |
2315 |
|
2316 |
$idr_rules="itemcallnumber: [NULL]"; |
2317 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); |
2318 |
( $idr_mayrenew, $idr_error ) = |
2319 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
2320 |
is( $idr_mayrenew, 0, 'Renewal blocked for undef when NULL in pref' ); |
2321 |
|
2322 |
$idr_rules="itemnotes: ['']"; |
2323 |
t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); |
2324 |
( $idr_mayrenew, $idr_error ) = |
2325 |
CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); |
2326 |
is( $idr_mayrenew, 0, 'Renewal blocked for empty string when "" in pref' ); |
2213 |
}; |
2327 |
}; |
2214 |
|
2328 |
|
2215 |
subtest 'CanBookBeIssued | item-level_itypes=biblio' => sub { |
2329 |
subtest 'CanBookBeIssued | item-level_itypes=biblio' => sub { |
2216 |
- |
|
|