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