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 => 54; |
10 |
use Test::More tests => 55; |
11 |
use MARC::Record; |
11 |
use MARC::Record; |
12 |
use C4::Biblio; |
12 |
use C4::Biblio; |
13 |
use C4::Items; |
13 |
use C4::Items; |
Lines 17-22
use Koha::Database;
Link Here
|
17 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
17 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
18 |
use Koha::Biblios; |
18 |
use Koha::Biblios; |
19 |
use Koha::Holds; |
19 |
use Koha::Holds; |
|
|
20 |
use Koha::IssuingRules; |
21 |
use Koha::Items; |
20 |
use Koha::Patrons; |
22 |
use Koha::Patrons; |
21 |
|
23 |
|
22 |
BEGIN { |
24 |
BEGIN { |
Lines 402-407
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
Link Here
|
402 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), |
404 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), |
403 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
405 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
404 |
|
406 |
|
|
|
407 |
$schema->storage->txn_rollback; |
408 |
|
409 |
subtest 'CanItemBeReserved / holds_per_day tests' => sub { |
410 |
|
411 |
plan tests => 9; |
412 |
|
413 |
$schema->storage->txn_begin; |
414 |
|
415 |
Koha::Holds->search->delete; |
416 |
$dbh->do('DELETE FROM issues'); |
417 |
Koha::Items->search->delete; |
418 |
Koha::Biblios->search->delete; |
419 |
|
420 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
421 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
422 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
423 |
# Create 3 biblios with items |
424 |
my ($bibnum_1) = create_helper_biblio( $itemtype->itemtype ); |
425 |
my ( undef, undef, $itemnumber_1 ) = AddItem( |
426 |
{ |
427 |
homebranch => $library->branchcode, |
428 |
holdingbranch => $library->branchcode |
429 |
}, |
430 |
$bibnum |
431 |
); |
432 |
my ($bibnum_2) = create_helper_biblio( $itemtype->itemtype ); |
433 |
my ( undef, undef, $itemnumber_2 ) = AddItem( |
434 |
{ |
435 |
homebranch => $library->branchcode, |
436 |
holdingbranch => $library->branchcode |
437 |
}, |
438 |
$bibnum_2 |
439 |
); |
440 |
my ($bibnum_3) = create_helper_biblio( $itemtype->itemtype ); |
441 |
my ( undef, undef, $itemnumber_3 ) = AddItem( |
442 |
{ |
443 |
homebranch => $library->branchcode, |
444 |
holdingbranch => $library->branchcode |
445 |
}, |
446 |
$bibnum_3 |
447 |
); |
448 |
|
449 |
Koha::IssuingRules->search->delete; |
450 |
my $issuingrule = Koha::IssuingRule->new({ |
451 |
categorycode => '*', |
452 |
branchcode => '*', |
453 |
itemtype => $itemtype->itemtype, |
454 |
reservesallowed => 1, |
455 |
holds_per_record => 99, |
456 |
holds_per_day => 2 })->store; |
457 |
|
458 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ), |
459 |
'OK', 'Patron can reserve item with hold limit of 1, no holds placed' ); |
460 |
|
461 |
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, ); |
462 |
|
463 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ), |
464 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
465 |
|
466 |
# Raise reservesallowed to avoid tooManyReserves from it |
467 |
$issuingrule->set({ reservesallowed => 3 })->store; |
468 |
|
469 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
470 |
'OK', 'Patron can reserve item with 2 reserves daily cap' ); |
471 |
|
472 |
# Add a second reserve |
473 |
my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, ); |
474 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
475 |
'tooManyReservesToday', 'Patron cannot a third item with 2 reserves daily cap' ); |
476 |
|
477 |
# Update last hold so reservedate is in the past, so 2 holds, but different day |
478 |
$hold = Koha::Holds->find( $res_id ); |
479 |
my $yesterday = dt_from_string() - DateTime::Duration->new( days => 1 ) ; |
480 |
$hold->reservedate( $yesterday )->store; |
481 |
|
482 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
483 |
'OK', 'Patron can reserve item with 2 bib level hold placed on different days, 2 reserves daily cap' ); |
484 |
|
485 |
# Set holds_per_day to 0 |
486 |
$issuingrule->set({ holds_per_day => 0 })->store; |
487 |
# Delete existing holds |
488 |
Koha::Holds->search->delete; |
489 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
490 |
'tooManyReservesToday', 'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)' ); |
491 |
|
492 |
$issuingrule->set({ holds_per_day => undef })->store; |
493 |
Koha::Holds->search->delete; |
494 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
495 |
'OK', 'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)' ); |
496 |
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, ); |
497 |
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, ); |
498 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ), |
499 |
'OK', 'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)' ); |
500 |
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_3, '', 1, ); |
501 |
is( CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ), |
502 |
'tooManyReserves', 'Unlimited daily holds, but reached reservesallowed' ); |
503 |
|
504 |
$schema->storage->txn_rollback; |
505 |
}; |
405 |
|
506 |
|
406 |
# Helper method to set up a Biblio. |
507 |
# Helper method to set up a Biblio. |
407 |
sub create_helper_biblio { |
508 |
sub create_helper_biblio { |
408 |
- |
|
|