Lines 7-15
use t::lib::TestBuilder;
Link Here
|
7 |
|
7 |
|
8 |
use C4::Context; |
8 |
use C4::Context; |
9 |
|
9 |
|
10 |
use Test::More tests => 56; |
10 |
use Test::More tests => 57; |
11 |
use MARC::Record; |
11 |
use MARC::Record; |
12 |
use Koha::Patrons; |
|
|
13 |
use C4::Items; |
12 |
use C4::Items; |
14 |
use C4::Biblio; |
13 |
use C4::Biblio; |
15 |
use C4::Reserves; |
14 |
use C4::Reserves; |
Lines 19-26
use Koha::Database;
Link Here
|
19 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
18 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
20 |
use Koha::Biblios; |
19 |
use Koha::Biblios; |
21 |
use Koha::Holds; |
20 |
use Koha::Holds; |
|
|
21 |
use Koha::IssuingRules; |
22 |
use Koha::Items; |
22 |
use Koha::Items; |
23 |
use Koha::Libraries; |
23 |
use Koha::Libraries; |
|
|
24 |
use Koha::Patrons; |
24 |
|
25 |
|
25 |
BEGIN { |
26 |
BEGIN { |
26 |
use FindBin; |
27 |
use FindBin; |
Lines 511-516
subtest 'Pickup location availability tests' => sub {
Link Here
|
511 |
'libraryNotFound', 'Cannot set unknown library as pickup location'); |
512 |
'libraryNotFound', 'Cannot set unknown library as pickup location'); |
512 |
}; |
513 |
}; |
513 |
|
514 |
|
|
|
515 |
$schema->storage->txn_rollback; |
516 |
|
517 |
subtest 'CanItemBeReserved / holds_per_day tests' => sub { |
518 |
|
519 |
plan tests => 9; |
520 |
|
521 |
$schema->storage->txn_begin; |
522 |
|
523 |
Koha::Holds->search->delete; |
524 |
$dbh->do('DELETE FROM issues'); |
525 |
Koha::Items->search->delete; |
526 |
Koha::Biblios->search->delete; |
527 |
|
528 |
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
529 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
530 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
531 |
|
532 |
# Create 3 biblios with items |
533 |
my ($bibnum_1) = create_helper_biblio( $itemtype->itemtype ); |
534 |
my ( undef, undef, $itemnumber_1 ) = AddItem( |
535 |
{ homebranch => $library->branchcode, |
536 |
holdingbranch => $library->branchcode |
537 |
}, |
538 |
$bibnum |
539 |
); |
540 |
my ($bibnum_2) = create_helper_biblio( $itemtype->itemtype ); |
541 |
my ( undef, undef, $itemnumber_2 ) = AddItem( |
542 |
{ homebranch => $library->branchcode, |
543 |
holdingbranch => $library->branchcode |
544 |
}, |
545 |
$bibnum_2 |
546 |
); |
547 |
my ($bibnum_3) = create_helper_biblio( $itemtype->itemtype ); |
548 |
my ( undef, undef, $itemnumber_3 ) = AddItem( |
549 |
{ homebranch => $library->branchcode, |
550 |
holdingbranch => $library->branchcode |
551 |
}, |
552 |
$bibnum_3 |
553 |
); |
554 |
|
555 |
Koha::IssuingRules->search->delete; |
556 |
my $issuingrule = Koha::IssuingRule->new( |
557 |
{ categorycode => '*', |
558 |
branchcode => '*', |
559 |
itemtype => $itemtype->itemtype, |
560 |
reservesallowed => 1, |
561 |
holds_per_record => 99, |
562 |
holds_per_day => 2 |
563 |
} |
564 |
)->store; |
565 |
|
566 |
is_deeply( |
567 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ), |
568 |
{ status => 'OK' }, |
569 |
'Patron can reserve item with hold limit of 1, no holds placed' |
570 |
); |
571 |
|
572 |
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, ); |
573 |
|
574 |
is_deeply( |
575 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_1 ), |
576 |
{ status => 'tooManyReserves', limit => 1 }, |
577 |
'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' |
578 |
); |
579 |
|
580 |
# Raise reservesallowed to avoid tooManyReserves from it |
581 |
$issuingrule->set( { reservesallowed => 3 } )->store; |
582 |
|
583 |
is_deeply( |
584 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
585 |
{ status => 'OK' }, |
586 |
'Patron can reserve item with 2 reserves daily cap' |
587 |
); |
588 |
|
589 |
# Add a second reserve |
590 |
my $res_id = AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, ); |
591 |
is_deeply( |
592 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
593 |
{ status => 'tooManyReservesToday', limit => 2 }, |
594 |
'Patron cannot a third item with 2 reserves daily cap' |
595 |
); |
596 |
|
597 |
# Update last hold so reservedate is in the past, so 2 holds, but different day |
598 |
$hold = Koha::Holds->find($res_id); |
599 |
my $yesterday = dt_from_string() - DateTime::Duration->new( days => 1 ); |
600 |
$hold->reservedate($yesterday)->store; |
601 |
|
602 |
is_deeply( |
603 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
604 |
{ status => 'OK' }, |
605 |
'Patron can reserve item with 2 bib level hold placed on different days, 2 reserves daily cap' |
606 |
); |
607 |
|
608 |
# Set holds_per_day to 0 |
609 |
$issuingrule->set( { holds_per_day => 0 } )->store; |
610 |
|
611 |
# Delete existing holds |
612 |
Koha::Holds->search->delete; |
613 |
is_deeply( |
614 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
615 |
{ status => 'tooManyReservesToday', limit => 0 }, |
616 |
'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)' |
617 |
); |
618 |
|
619 |
$issuingrule->set( { holds_per_day => undef } )->store; |
620 |
Koha::Holds->search->delete; |
621 |
is_deeply( |
622 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ), |
623 |
{ status => 'OK' }, |
624 |
'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)' |
625 |
); |
626 |
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_1, '', 1, ); |
627 |
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_2, '', 1, ); |
628 |
is_deeply( |
629 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ), |
630 |
{ status => 'OK' }, |
631 |
'Patron can reserve if holds_per_day is undef (i.e. undef is unlimited daily cap)' |
632 |
); |
633 |
AddReserve( $library->branchcode, $patron->borrowernumber, $bibnum_3, '', 1, ); |
634 |
is_deeply( |
635 |
CanItemBeReserved( $patron->borrowernumber, $itemnumber_3 ), |
636 |
{ status => 'tooManyReserves', limit => 3 }, |
637 |
'Unlimited daily holds, but reached reservesallowed' |
638 |
); |
639 |
|
640 |
$schema->storage->txn_rollback; |
641 |
}; |
642 |
|
643 |
|
514 |
# Helper method to set up a Biblio. |
644 |
# Helper method to set up a Biblio. |
515 |
sub create_helper_biblio { |
645 |
sub create_helper_biblio { |
516 |
my $itemtype = shift; |
646 |
my $itemtype = shift; |
517 |
- |
|
|