|
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 18-23
use Koha::DateUtils qw( dt_from_string output_pref );
Link Here
|
| 18 |
use Koha::Biblios; |
18 |
use Koha::Biblios; |
| 19 |
use Koha::Holds; |
19 |
use Koha::Holds; |
| 20 |
use Koha::Patrons; |
20 |
use Koha::Patrons; |
|
|
21 |
use Koha::CirculationRules; |
| 21 |
|
22 |
|
| 22 |
BEGIN { |
23 |
BEGIN { |
| 23 |
use FindBin; |
24 |
use FindBin; |
|
Lines 411-416
my $res_id = AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, );
Link Here
|
| 411 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), |
412 |
is( CanItemBeReserved( $borrowernumbers[0], $itemnumber ), |
| 412 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
413 |
'tooManyReserves', 'Patron cannot reserve item with hold limit of 1, 1 bib level hold placed' ); |
| 413 |
|
414 |
|
|
|
415 |
subtest 'Test max_holds per library/patron category' => sub { |
| 416 |
plan tests => 6; |
| 417 |
|
| 418 |
$dbh->do('DELETE FROM reserves'); |
| 419 |
$dbh->do('DELETE FROM issuingrules'); |
| 420 |
$dbh->do('DELETE FROM circulation_rules'); |
| 421 |
|
| 422 |
( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST'); |
| 423 |
( $item_bibnum, $item_bibitemnum, $itemnumber ) = |
| 424 |
AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, |
| 425 |
$bibnum ); |
| 426 |
$dbh->do( |
| 427 |
q{ |
| 428 |
INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record) |
| 429 |
VALUES (?, ?, ?, ?, ?) |
| 430 |
}, |
| 431 |
{}, |
| 432 |
'*', '*', 'TEST', 99, 99 |
| 433 |
); |
| 434 |
AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); |
| 435 |
AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); |
| 436 |
AddReserve( $branch_1, $borrowernumbers[0], $bibnum, '', 1, ); |
| 437 |
|
| 438 |
my $count = |
| 439 |
Koha::Holds->search( { borrowernumber => $borrowernumbers[0] } )->count(); |
| 440 |
is( $count, 3, 'Patron now has 3 holds' ); |
| 441 |
|
| 442 |
my $ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
| 443 |
is( $ret, 'OK', 'Patron can place hold with no borrower circ rules' ); |
| 444 |
|
| 445 |
my $rule_all = Koha::CirculationRules->set_rule( |
| 446 |
{ |
| 447 |
categorycode => $category->{categorycode}, |
| 448 |
branchcode => undef, |
| 449 |
itemtype => undef, |
| 450 |
rule_name => 'max_holds', |
| 451 |
rule_value => 3, |
| 452 |
} |
| 453 |
); |
| 454 |
|
| 455 |
my $rule_branch = Koha::CirculationRules->set_rule( |
| 456 |
{ |
| 457 |
branchcode => $branch_1, |
| 458 |
categorycode => $category->{categorycode}, |
| 459 |
itemtype => undef, |
| 460 |
rule_name => 'max_holds', |
| 461 |
rule_value => 5, |
| 462 |
} |
| 463 |
); |
| 464 |
|
| 465 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
| 466 |
is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 3' ); |
| 467 |
|
| 468 |
$rule_branch->delete(); |
| 469 |
|
| 470 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
| 471 |
is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a category rule of 3' ); |
| 472 |
|
| 473 |
$rule_all->delete(); |
| 474 |
$rule_branch->rule_value(3); |
| 475 |
$rule_branch->store(); |
| 476 |
|
| 477 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
| 478 |
is( $ret, 'tooManyReserves', 'Patron cannot place hold with only a branch/category rule of 3' ); |
| 479 |
|
| 480 |
$rule_branch->rule_value(5); |
| 481 |
$rule_branch->update(); |
| 482 |
$rule_branch->rule_value(5); |
| 483 |
$rule_branch->store(); |
| 484 |
|
| 485 |
$ret = CanItemBeReserved( $borrowernumbers[0], $itemnumber ); |
| 486 |
is( $ret, 'OK', 'Patron can place hold with branch/category rule of 5, category rule of 5' ); |
| 487 |
}; |
| 414 |
|
488 |
|
| 415 |
# Helper method to set up a Biblio. |
489 |
# Helper method to set up a Biblio. |
| 416 |
sub create_helper_biblio { |
490 |
sub create_helper_biblio { |
| 417 |
- |
|
|