|
Lines 18-24
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
use utf8; |
19 |
use utf8; |
| 20 |
|
20 |
|
| 21 |
use Test::More tests => 67; |
21 |
use Test::More tests => 68; |
| 22 |
use Test::Exception; |
22 |
use Test::Exception; |
| 23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
| 24 |
use Test::Deep qw( cmp_deeply ); |
24 |
use Test::Deep qw( cmp_deeply ); |
|
Lines 290-295
Koha::CirculationRules->set_rules(
Link Here
|
| 290 |
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers and items tests" => sub { |
290 |
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers and items tests" => sub { |
| 291 |
plan tests => 7; |
291 |
plan tests => 7; |
| 292 |
|
292 |
|
|
|
293 |
my $schema = Koha::Database->schema; |
| 294 |
$schema->storage->txn_begin; |
| 295 |
|
| 293 |
#Can only reserve from home branch |
296 |
#Can only reserve from home branch |
| 294 |
Koha::CirculationRules->set_rule( |
297 |
Koha::CirculationRules->set_rule( |
| 295 |
{ |
298 |
{ |
|
Lines 377-382
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple borrowers a
Link Here
|
| 377 |
( $renewokay, $error ) = CanBookBeRenewed($patron, $issue); |
380 |
( $renewokay, $error ) = CanBookBeRenewed($patron, $issue); |
| 378 |
is( $renewokay, 0, 'Cannot renew when there is an item specific hold'); |
381 |
is( $renewokay, 0, 'Cannot renew when there is an item specific hold'); |
| 379 |
is( $error, 'on_reserve', 'Cannot renew, only this item can fill the reserve'); |
382 |
is( $error, 'on_reserve', 'Cannot renew, only this item can fill the reserve'); |
|
|
383 |
$schema->storage->txn_rollback; |
| 384 |
}; |
| 385 |
|
| 386 |
subtest "CanBookBeRenewed AllowRenewalIfOtherItemsAvailable multiple branches (transfers are limited)" => sub { |
| 387 |
plan tests => 10; |
| 388 |
|
| 389 |
my $schema = Koha::Database->schema; |
| 390 |
$schema->storage->txn_begin; |
| 391 |
|
| 392 |
# Patrons from three different branches |
| 393 |
my $patron_borrower_1 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 394 |
my $patron_borrower_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 395 |
my $patron_hold = $builder->build_object({ class => 'Koha::Patrons' }); |
| 396 |
my $biblio = $builder->build_sample_biblio(); |
| 397 |
|
| 398 |
my $branch1 = $patron_borrower_1->branchcode; |
| 399 |
my $branch2 = $patron_borrower_2->branchcode; |
| 400 |
|
| 401 |
# Item at each patron branch |
| 402 |
my $item_1 = $builder->build_sample_item({ |
| 403 |
biblionumber => $biblio->biblionumber, |
| 404 |
homebranch => $branch1 |
| 405 |
}); |
| 406 |
my $item_2 = $builder->build_sample_item({ |
| 407 |
biblionumber => $biblio->biblionumber, |
| 408 |
homebranch => $branch2, |
| 409 |
itype => $item_1->effective_itemtype |
| 410 |
}); |
| 411 |
|
| 412 |
# checkout item_1 |
| 413 |
my $issue1 = AddIssue( $patron_borrower_1->unblessed, $item_1->barcode); |
| 414 |
my $datedue1 = dt_from_string( $issue1->date_due() ); |
| 415 |
is (defined $issue1->date_due(), 1, "Item 1 checked out, due date: " . $issue1->date_due() ); |
| 416 |
|
| 417 |
# checkout item_2 |
| 418 |
my $issue2 = AddIssue( $patron_borrower_2->unblessed, $item_2->barcode); |
| 419 |
my $datedue2 = dt_from_string( $issue2->date_due() ); |
| 420 |
is (defined $issue2->date_due(), 1, "Item 2 checked out, due date: " . $issue2->date_due() ); |
| 421 |
|
| 422 |
AddReserve( |
| 423 |
{ |
| 424 |
branchcode => $branch1, |
| 425 |
borrowernumber => $patron_hold->borrowernumber, |
| 426 |
biblionumber => $biblio->biblionumber, |
| 427 |
priority => 1, |
| 428 |
reservation_date => dt_from_string(), |
| 429 |
expiration_date => undef, |
| 430 |
itemnumber => $item_1->itemnumber, |
| 431 |
found => undef, |
| 432 |
} |
| 433 |
); |
| 434 |
|
| 435 |
my $AllowRenewalIfOtherItemsAvailable = C4::Context->preference('AllowRenewalIfOtherItemsAvailable'); |
| 436 |
my $UseBranchTransferLimits = C4::Context->preference('UseBranchTransferLimits'); |
| 437 |
my $BranchTransferLimitsType = C4::Context->preference('BranchTransferLimitsType'); |
| 438 |
|
| 439 |
warn $UseBranchTransferLimits; |
| 440 |
|
| 441 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); |
| 442 |
|
| 443 |
my ( $renewokay, $error ) = CanBookBeRenewed($patron_borrower_1->borrowernumber, $item_1->itemnumber); |
| 444 |
is( $renewokay, 0, 'Cannot renew item1, no other items available for hold'); |
| 445 |
is( $error, 'on_reserve', 'Cannot renew, reserved (returned error is on_reserve)'); |
| 446 |
|
| 447 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' ); |
| 448 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' ); |
| 449 |
|
| 450 |
( $renewokay, $error ) = CanBookBeRenewed($patron_borrower_2->borrowernumber, $item_2->itemnumber); |
| 451 |
is( $renewokay, 0, 'Cannot renew item2, no other items available for hold, transfers are not permitted'); |
| 452 |
is( $error, 'on_reserve', 'Cannot renew, reserved (returned error is on_reserve)'); |
| 453 |
|
| 454 |
my $limit = Koha::Item::Transfer::Limit->new( |
| 455 |
{ |
| 456 |
toBranch => $branch1, |
| 457 |
fromBranch => $branch2, |
| 458 |
itemtype => $item_1->effective_itemtype, |
| 459 |
})->store(); |
| 460 |
|
| 461 |
( $renewokay, $error ) = CanBookBeRenewed($patron_borrower_1->borrowernumber, $item_1->itemnumber); |
| 462 |
is( $renewokay, 0, 'Cannot renew item1, no other items available for hold'); |
| 463 |
is( $error, 'on_reserve', 'Cannot renew, reserved (returned error is on_reserve)'); |
| 464 |
|
| 465 |
( $renewokay, $error ) = CanBookBeRenewed($patron_borrower_2->borrowernumber, $item_2->itemnumber); |
| 466 |
is( $renewokay, 1, 'Can renew item2, it\'s on on different branch than hold, transfers are permitted between those two branches'); |
| 467 |
is( $error, undef, 'Can renew, no holds on the same branch'); |
| 468 |
|
| 469 |
t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', $AllowRenewalIfOtherItemsAvailable ); |
| 470 |
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', $UseBranchTransferLimits ); |
| 471 |
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', $BranchTransferLimitsType ); |
| 472 |
|
| 473 |
$schema->storage->txn_rollback; |
| 380 |
}; |
474 |
}; |
| 381 |
|
475 |
|
| 382 |
subtest "GetIssuingCharges tests" => sub { |
476 |
subtest "GetIssuingCharges tests" => sub { |
| 383 |
- |
|
|