|
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 => 62; |
| 11 |
use MARC::Record; |
11 |
use MARC::Record; |
| 12 |
|
12 |
|
| 13 |
use C4::Biblio; |
13 |
use C4::Biblio; |
|
Lines 282-311
ok(
Link Here
|
| 282 |
'... unless canreservefromotherbranches is ON (bug 2394)' |
282 |
'... unless canreservefromotherbranches is ON (bug 2394)' |
| 283 |
); |
283 |
); |
| 284 |
|
284 |
|
| 285 |
{ |
285 |
# Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities |
| 286 |
# Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities |
286 |
$biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
| 287 |
$biblio = $builder->build_sample_biblio({ itemtype => 'DUMMY' }); |
287 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
| 288 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
288 |
my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1); |
| 289 |
my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1); |
289 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
| 290 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
290 |
my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2); |
| 291 |
my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $biblio->biblionumber, '', 2); |
291 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
| 292 |
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $biblio->biblionumber); |
292 |
my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3); |
| 293 |
my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $biblio->biblionumber, '', 3); |
293 |
my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber }); |
| 294 |
my $hhh = Koha::Holds->search({ biblionumber => $biblio->biblionumber }); |
294 |
my $hold3 = Koha::Holds->find( $reserveid3 ); |
| 295 |
my $hold3 = Koha::Holds->find( $reserveid3 ); |
295 |
is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" ); |
| 296 |
is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" ); |
296 |
ModReserve({ reserve_id => $reserveid1, rank => 'del' }); |
| 297 |
ModReserve({ reserve_id => $reserveid1, rank => 'del' }); |
297 |
ModReserve({ reserve_id => $reserveid2, rank => 'del' }); |
| 298 |
ModReserve({ reserve_id => $reserveid2, rank => 'del' }); |
298 |
is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" ); |
| 299 |
is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" ); |
|
|
| 300 |
} |
| 301 |
|
299 |
|
| 302 |
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); |
300 |
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); |
| 303 |
|
301 |
|
| 304 |
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); |
302 |
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber); |
| 305 |
CancelReserve({reserve_id => $reserveid3}); |
303 |
$hold = Koha::Holds->find( $reserveid3 ); |
|
|
304 |
$hold->cancel; |
| 306 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); |
305 |
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 ); |
| 307 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); |
306 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'OK', "Patron can reserve damaged item with AllowHoldsOnDamagedItems enabled" ); |
| 308 |
ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold can be trapped for damaged item with AllowHoldsOnDamagedItems enabled" ); |
|
|
| 309 |
|
307 |
|
| 310 |
$hold = Koha::Hold->new( |
308 |
$hold = Koha::Hold->new( |
| 311 |
{ |
309 |
{ |
|
Lines 336-380
AddReserve(
Link Here
|
| 336 |
my ($bibnum2, $title2, $bibitemnum2) = create_helper_biblio('CANNOT'); |
334 |
my ($bibnum2, $title2, $bibitemnum2) = create_helper_biblio('CANNOT'); |
| 337 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum2); |
335 |
my ($item_bibnum2, $item_bibitemnum2, $itemnumber2) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1, itype => 'CANNOT' } , $bibnum2); |
| 338 |
is( |
336 |
is( |
| 339 |
<<<<<<< HEAD |
337 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status}, 'tooManyReserves', |
| 340 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status}, 'tooManyReserves', |
|
|
| 341 |
======= |
| 342 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2), 'tooManyReserves', |
| 343 |
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved |
| 344 |
"cannot request item if policy that matches on item-level item type forbids it" |
338 |
"cannot request item if policy that matches on item-level item type forbids it" |
| 345 |
); |
339 |
); |
| 346 |
ModItem({ itype => 'CAN' }, $item_bibnum2, $itemnumber2); |
340 |
ModItem({ itype => 'CAN' }, $item_bibnum2, $itemnumber2); |
| 347 |
ok( |
341 |
ok( |
| 348 |
<<<<<<< HEAD |
342 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status} eq 'OK', |
| 349 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'OK', |
|
|
| 350 |
======= |
| 351 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2) eq 'OK', |
| 352 |
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved |
| 353 |
"can request item if policy that matches on item type allows it" |
343 |
"can request item if policy that matches on item type allows it" |
| 354 |
); |
344 |
); |
| 355 |
|
345 |
|
| 356 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
346 |
t::lib::Mocks::mock_preference('item-level_itypes', 0); |
| 357 |
<<<<<<< HEAD |
347 |
ModItem({ itype => undef }, $item_bibnum, $itemnumber2); |
| 358 |
ModItem({ itype => undef }, $item_bibnum, $itemnumber); |
|
|
| 359 |
ok( |
| 360 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber)->{status} eq 'tooManyReserves', |
| 361 |
======= |
| 362 |
ModItem({ itype => undef }, $item_bibnum2, $itemnumber2); |
| 363 |
is( |
348 |
is( |
| 364 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2), 'tooManyReserves', |
349 |
CanItemBeReserved( $borrowernumbers[0], $itemnumber2)->{status}, 'tooManyReserves', |
| 365 |
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved |
|
|
| 366 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
350 |
"cannot request item if policy that matches on bib-level item type forbids it (bug 9532)" |
| 367 |
); |
351 |
); |
| 368 |
|
352 |
|
| 369 |
is(CanBookBeReserved($borrowernumbers[0], $bibnum), 'OK'); |
353 |
is(CanBookBeReserved($borrowernumbers[0], $biblio->biblionumber)->{status}, 'OK'); |
| 370 |
|
354 |
|
| 371 |
C4::Context->set_preference('maxreserves', 1); |
355 |
C4::Context->set_preference('maxreserves', 1); |
| 372 |
is(CanBookBeReserved($borrowernumbers[0], $biblionumber), 'tooManyReserves'); |
356 |
is(CanBookBeReserved($borrowernumbers[0], $biblio->biblionumber)->{status}, 'tooManyReserves'); |
| 373 |
|
357 |
|
| 374 |
C4::Context->set_preference('maxreserves', 0); |
358 |
C4::Context->set_preference('maxreserves', 0); |
| 375 |
t::lib::Mocks::mock_preference('IndependentBranches', 1); |
359 |
t::lib::Mocks::mock_preference('IndependentBranches', 1); |
| 376 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 0); |
360 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 0); |
| 377 |
ok(CanBookBeReserved($borrowernumbers[0], $foreign_bibnum) eq 'none_available'); |
361 |
ok(CanBookBeReserved($borrowernumbers[0], $foreign_biblio->biblionumber)->{status} eq 'none_available'); |
|
|
362 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
| 363 |
t::lib::Mocks::mock_preference('canreservefromotherbranches', 1); |
| 378 |
|
364 |
|
| 379 |
# Test branch item rules |
365 |
# Test branch item rules |
| 380 |
|
366 |
|
|
Lines 443-464
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status},
Link Here
|
| 443 |
|
429 |
|
| 444 |
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, ); |
430 |
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $biblio->biblionumber, '', 1, ); |
| 445 |
|
431 |
|
| 446 |
<<<<<<< HEAD |
|
|
| 447 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
432 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
| 448 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
|
|
| 449 |
======= |
| 450 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), |
| 451 |
'tooManyHoldsForThisRecord', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
433 |
'tooManyHoldsForThisRecord', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
| 452 |
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved |
|
|
| 453 |
|
434 |
|
| 454 |
#results should be the same for both ReservesControlBranch settings |
435 |
#results should be the same for both ReservesControlBranch settings |
| 455 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); |
436 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHomeLibrary' ); |
| 456 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
437 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber )->{status}, |
| 457 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
438 |
'tooManyHoldsForThisRecord', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
| 458 |
#reset for further tests |
439 |
#reset for further tests |
| 459 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); |
440 |
t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); |
| 460 |
|
441 |
|
| 461 |
<<<<<<< HEAD |
|
|
| 462 |
subtest 'Test max_holds per library/patron category' => sub { |
442 |
subtest 'Test max_holds per library/patron category' => sub { |
| 463 |
plan tests => 6; |
443 |
plan tests => 6; |
| 464 |
|
444 |
|
|
Lines 709-715
subtest 'CanItemBeReserved / holds_per_day tests' => sub {
Link Here
|
| 709 |
|
689 |
|
| 710 |
$schema->storage->txn_rollback; |
690 |
$schema->storage->txn_rollback; |
| 711 |
}; |
691 |
}; |
| 712 |
======= |
692 |
|
| 713 |
# Helper method to set up a Biblio. |
693 |
# Helper method to set up a Biblio. |
| 714 |
sub create_helper_biblio { |
694 |
sub create_helper_biblio { |
| 715 |
my $itemtype = shift; |
695 |
my $itemtype = shift; |
|
Lines 731-734
sub create_helper_biblio {
Link Here
|
| 731 |
|
711 |
|
| 732 |
return AddBiblio($bib, ''); |
712 |
return AddBiblio($bib, ''); |
| 733 |
} |
713 |
} |
| 734 |
>>>>>>> Bug 11999: Add two checks in CanBookBeReserved and CanItemBeReserved |
|
|
| 735 |
- |