|
Lines 7-13
use t::lib::TestBuilder;
Link Here
|
| 7 |
|
7 |
|
| 8 |
use C4::Context; |
8 |
use C4::Context; |
| 9 |
|
9 |
|
| 10 |
use Test::More tests => 59; |
10 |
use Test::More tests => 57; |
| 11 |
use MARC::Record; |
11 |
use MARC::Record; |
| 12 |
|
12 |
|
| 13 |
use C4::Biblio; |
13 |
use C4::Biblio; |
|
Lines 242-248
is( $hold->priority, '6', "Test AlterPriority(), move to bottom" );
Link Here
|
| 242 |
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
242 |
my $foreign_biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
| 243 |
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) |
243 |
my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) |
| 244 |
= AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber); |
244 |
= AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber); |
| 245 |
$dbh->do('DELETE FROM issuingrules'); |
245 |
delete_all_rules(); |
| 246 |
$dbh->do( |
246 |
$dbh->do( |
| 247 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) |
247 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) |
| 248 |
VALUES (?, ?, ?, ?, ?)}, |
248 |
VALUES (?, ?, ?, ?, ?)}, |
|
Lines 320-366
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 );
Link Here
|
| 320 |
ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); |
320 |
ok( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'damaged', "Patron cannot reserve damaged item with AllowHoldsOnDamagedItems disabled" ); |
| 321 |
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); |
321 |
ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for damaged item with AllowHoldsOnDamagedItems disabled" ); |
| 322 |
|
322 |
|
| 323 |
# Regression test for bug 9532 |
323 |
subtest 'CanItemBeReserved' => sub { |
| 324 |
$biblio = $builder->build_sample_biblio({ itemtype => 'CANNOT' }); |
324 |
plan tests => 2; |
| 325 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblio->biblionumber); |
|
|
| 326 |
AddReserve( |
| 327 |
$branch_1, |
| 328 |
$borrowernumbers[0], |
| 329 |
$biblio->biblionumber, |
| 330 |
'', |
| 331 |
1, |
| 332 |
); |
| 333 |
is( |
| 334 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves', |
| 335 |
"cannot request item if policy that matches on item-level item type forbids it" |
| 336 |
); |
| 337 |
ModItem({ itype => 'CAN' }, $item_bibnum, $itemnumber); |
| 338 |
ok( |
| 339 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK', |
| 340 |
"can request item if policy that matches on item type allows it" |
| 341 |
); |
| 342 |
|
325 |
|
| 343 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
326 |
delete_all_rules(); |
| 344 |
ModItem({ itype => undef }, $item_bibnum, $itemnumber); |
327 |
|
| 345 |
ok( |
328 |
my $itemtype_can = $builder->build({source => "Itemtype"})->{itemtype}; |
| 346 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves', |
329 |
my $itemtype_cant = $builder->build({source => "Itemtype"})->{itemtype}; |
| 347 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
330 |
|
| 348 |
); |
331 |
$dbh->do( |
|
|
332 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, |
| 333 |
'*', '*', $itemtype_cant, 0, 99 |
| 334 |
); |
| 335 |
$dbh->do( |
| 336 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) VALUES (?, ?, ?, ?, ?)}, {}, |
| 337 |
'*', '*', $itemtype_can, 2, 2 |
| 338 |
); |
| 339 |
|
| 340 |
subtest 'noReservesAllowed' => sub { |
| 341 |
plan tests => 4; |
| 342 |
|
| 343 |
my $biblionumber_cannot = $builder->build_sample_biblio({ itemtype => $itemtype_cant })->biblionumber; |
| 344 |
my $biblionumber_can = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
| 345 |
my ( undef, undef, $itemnumber_1_can ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_cannot); |
| 346 |
my ( undef, undef, $itemnumber_1_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblionumber_cannot); |
| 347 |
|
| 348 |
my ( undef, undef, $itemnumber_2_can ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_can); |
| 349 |
my ( undef, undef, $itemnumber_2_cannot ) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $biblionumber_can); |
| 350 |
|
| 351 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
| 352 |
|
| 353 |
t::lib::Mocks::mock_preference('item-level_itypes', 1); |
| 354 |
is( |
| 355 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot), 'noReservesAllowed', |
| 356 |
"With item level set, rule from item must be picked (CANNOT)" |
| 357 |
); |
| 358 |
is( |
| 359 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_1_can), 'OK', |
| 360 |
"With item level set, rule from item must be picked (CAN)" |
| 361 |
); |
| 362 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
| 363 |
is( |
| 364 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_1_can), 'noReservesAllowed', |
| 365 |
"With biblio level set, rule from biblio must be picked (CANNOT)" |
| 366 |
); |
| 367 |
is( |
| 368 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_2_cannot), 'OK', |
| 369 |
"With biblio level set, rule from biblio must be picked (CAN)" |
| 370 |
); |
| 371 |
}; |
| 372 |
|
| 373 |
subtest 'tooManyHoldsForThisRecord + tooManyReserves + itemAlreadyOnHold' => sub { |
| 374 |
plan tests => 7; |
| 375 |
|
| 376 |
my $biblionumber_1 = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
| 377 |
my ( undef, undef, $itemnumber_11) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_1); |
| 378 |
my ( undef, undef, $itemnumber_12) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_1); |
| 379 |
my $biblionumber_2 = $builder->build_sample_biblio({ itemtype => $itemtype_can })->biblionumber; |
| 380 |
my ( undef, undef, $itemnumber_21) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_2); |
| 381 |
my ( undef, undef, $itemnumber_22) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CAN' } , $biblionumber_2); |
| 382 |
|
| 383 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
| 384 |
|
| 385 |
# Biblio-level hold |
| 386 |
AddReserve( |
| 387 |
$branch_1, |
| 388 |
$borrowernumbers[0], |
| 389 |
$biblionumber_1, |
| 390 |
'', |
| 391 |
1, |
| 392 |
); |
| 393 |
for my $item_level ( 0..1 ) { |
| 394 |
t::lib::Mocks::mock_preference('item-level_itypes', $item_level); |
| 395 |
is( |
| 396 |
# FIXME This is not really correct, but CanItemBeReserved does not check if biblio-level holds already exist |
| 397 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_11), 'OK', |
| 398 |
"A biblio-level hold already exists - another hold can be placed on a specific item item" |
| 399 |
); |
| 400 |
} |
| 401 |
|
| 402 |
Koha::Holds->search({borrowernumber => $borrowernumbers[0]})->delete; |
| 403 |
# Item-level hold |
| 404 |
AddReserve( |
| 405 |
$branch_1, |
| 406 |
$borrowernumbers[0], |
| 407 |
$biblionumber_1, |
| 408 |
'', |
| 409 |
1, |
| 410 |
undef, undef, undef, undef, $itemnumber_11 |
| 411 |
); |
| 412 |
$dbh->do(q{UPDATE issuingrules set reservesallowed=5, holds_per_record=1}); |
| 413 |
is( |
| 414 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12), 'tooManyHoldsForThisRecord', |
| 415 |
"A item-level hold already exists and holds_per_record=1, another hold cannot be placed on this record" |
| 416 |
); |
| 417 |
$dbh->do(q{UPDATE issuingrules set reservesallowed=1, holds_per_record=1}); |
| 418 |
is( |
| 419 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12), 'tooManyHoldsForThisRecord', |
| 420 |
"A item-level hold already exists and holds_per_record=1 - tooManyHoldsForThisRecord has priority over tooManyReserves" |
| 421 |
); |
| 422 |
$dbh->do(q{UPDATE issuingrules set reservesallowed=5, holds_per_record=2}); |
| 423 |
is( |
| 424 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_12), 'OK', |
| 425 |
"A item-level hold already exists but holds_per_record=2- another item-level hold can be placed on this record" |
| 426 |
); |
| 427 |
|
| 428 |
AddReserve( |
| 429 |
$branch_1, |
| 430 |
$borrowernumbers[0], |
| 431 |
$biblionumber_2, |
| 432 |
'', |
| 433 |
1, |
| 434 |
undef, undef, undef, undef, $itemnumber_21 |
| 435 |
); |
| 436 |
$dbh->do(q{UPDATE issuingrules set reservesallowed=2, holds_per_record=2}); |
| 437 |
is( |
| 438 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_21), 'itemAlreadyOnHold', |
| 439 |
"A item-level holds already exists on this item, itemAlreadyOnHold should be raised" |
| 440 |
); |
| 441 |
is( |
| 442 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber_22), 'tooManyReserves', |
| 443 |
"This patron has already placed reservesallowed holds, tooManyReserves should be raised" |
| 444 |
); |
| 445 |
}; |
| 446 |
}; |
| 349 |
|
447 |
|
| 350 |
|
448 |
|
| 351 |
# Test branch item rules |
449 |
# Test branch item rules |
| 352 |
|
450 |
|
| 353 |
$dbh->do('DELETE FROM issuingrules'); |
451 |
delete_all_rules(); |
| 354 |
$dbh->do( |
452 |
$dbh->do( |
| 355 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
453 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
| 356 |
VALUES (?, ?, ?, ?)}, |
454 |
VALUES (?, ?, ?, ?)}, |
| 357 |
{}, |
455 |
{}, |
| 358 |
'*', '*', '*', 25 |
456 |
'*', '*', '*', 25 |
| 359 |
); |
457 |
); |
| 360 |
$dbh->do('DELETE FROM branch_item_rules'); |
|
|
| 361 |
$dbh->do('DELETE FROM default_branch_circ_rules'); |
| 362 |
$dbh->do('DELETE FROM default_branch_item_rules'); |
| 363 |
$dbh->do('DELETE FROM default_circ_rules'); |
| 364 |
$dbh->do(q{ |
458 |
$dbh->do(q{ |
| 365 |
INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch) |
459 |
INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, returnbranch) |
| 366 |
VALUES (?, ?, ?, ?) |
460 |
VALUES (?, ?, ?, ?) |
|
Lines 675-677
subtest 'CanItemBeReserved / holds_per_day tests' => sub {
Link Here
|
| 675 |
|
769 |
|
| 676 |
$schema->storage->txn_rollback; |
770 |
$schema->storage->txn_rollback; |
| 677 |
}; |
771 |
}; |
| 678 |
- |
772 |
|
|
|
773 |
sub delete_all_rules { |
| 774 |
my $dbh = C4::Context->dbh; |
| 775 |
$dbh->do('DELETE FROM issuingrules'); |
| 776 |
$dbh->do('DELETE FROM branch_item_rules'); |
| 777 |
$dbh->do('DELETE FROM default_branch_circ_rules'); |
| 778 |
$dbh->do('DELETE FROM default_branch_item_rules'); |
| 779 |
$dbh->do('DELETE FROM default_circ_rules'); |
| 780 |
} |