|
Lines 15-21
Link Here
|
| 15 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
15 |
# with Koha; if not, see <http://www.gnu.org/licenses>. |
| 16 |
|
16 |
|
| 17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
| 18 |
use Test::More tests => 7; |
18 |
use Test::More tests => 8; |
| 19 |
use C4::Context; |
19 |
use C4::Context; |
| 20 |
|
20 |
|
| 21 |
use C4::Members; |
21 |
use C4::Members; |
|
Lines 469-474
subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub {
Link Here
|
| 469 |
teardown(); |
469 |
teardown(); |
| 470 |
}; |
470 |
}; |
| 471 |
|
471 |
|
|
|
472 |
subtest 'General vs specific rules limit quantity correctly' => sub { |
| 473 |
plan tests => 9; |
| 474 |
|
| 475 |
t::lib::Mocks::mock_preference('CircControl', 'ItemHomeLibrary'); |
| 476 |
my $branch = $builder->build({source => 'Branch',}); |
| 477 |
my $category = $builder->build({source => 'Category',}); |
| 478 |
my $itemtype = $builder->build({ |
| 479 |
source => 'Itemtype', |
| 480 |
value => { |
| 481 |
rentalcharge => 0, |
| 482 |
rentalcharge_daily => 0, |
| 483 |
rentalcharge_hourly => 0, |
| 484 |
notforloan => 0, |
| 485 |
} |
| 486 |
}); |
| 487 |
my $patron = $builder->build({ |
| 488 |
source => 'Borrower', |
| 489 |
value => { |
| 490 |
categorycode => $category->{categorycode}, |
| 491 |
branchcode => $branch->{branchcode}, |
| 492 |
} |
| 493 |
}); |
| 494 |
|
| 495 |
# Set up an issuing rule |
| 496 |
my $rule = $builder->build({ |
| 497 |
source => 'Issuingrule', |
| 498 |
value => { |
| 499 |
categorycode => '*', |
| 500 |
itemtype => $itemtype->{itemtype}, |
| 501 |
branchcode => '*', |
| 502 |
issuelength => 1, |
| 503 |
firstremind => 1, # 1 day of grace |
| 504 |
finedays => 2, # 2 days of fine per day of overdue |
| 505 |
lengthunit => 'days', |
| 506 |
} |
| 507 |
}); |
| 508 |
|
| 509 |
# Set an All->All for an itemtype |
| 510 |
Koha::CirculationRules->set_rules( |
| 511 |
{ |
| 512 |
branchcode => '*', |
| 513 |
categorycode => '*', |
| 514 |
itemtype => $itemtype->{itemtype}, |
| 515 |
rules => { |
| 516 |
maxissueqty => 1, |
| 517 |
maxonsiteissueqty => 1, |
| 518 |
} |
| 519 |
} |
| 520 |
); |
| 521 |
|
| 522 |
# Create an item |
| 523 |
my $item = $builder->build_sample_item({ |
| 524 |
itype => $itemtype->{itemtype} |
| 525 |
}); |
| 526 |
my $branch_item = $builder->build_sample_item({ |
| 527 |
itype => $itemtype->{itemtype}, |
| 528 |
homebranch => $branch->{branchcode}, |
| 529 |
holdingbranch => $branch->{branchcode} |
| 530 |
}); |
| 531 |
|
| 532 |
|
| 533 |
t::lib::Mocks::mock_userenv({ branchcode => $branch->{branchcode} }); |
| 534 |
my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string() ); |
| 535 |
# We checkout one item |
| 536 |
is_deeply( |
| 537 |
C4::Circulation::TooMany( $patron, $branch_item->biblionumber, $branch_item->unblessed ), |
| 538 |
{ |
| 539 |
reason => 'TOO_MANY_CHECKOUTS', |
| 540 |
count => 1, |
| 541 |
max_allowed => 1, |
| 542 |
}, |
| 543 |
'We are only allowed one, and we have one' |
| 544 |
); |
| 545 |
|
| 546 |
|
| 547 |
# Set a branch specific rule |
| 548 |
Koha::CirculationRules->set_rules( |
| 549 |
{ |
| 550 |
branchcode => $branch->{branchcode}, |
| 551 |
categorycode => $category->{categorycode}, |
| 552 |
itemtype => $itemtype->{itemtype}, |
| 553 |
rules => { |
| 554 |
maxissueqty => 1, |
| 555 |
maxonsiteissueqty => 1, |
| 556 |
} |
| 557 |
} |
| 558 |
); |
| 559 |
|
| 560 |
is( |
| 561 |
C4::Circulation::TooMany( $patron, $branch_item->biblionumber, $branch_item->unblessed ), |
| 562 |
undef, |
| 563 |
'We are allowed one from the branch specifically now' |
| 564 |
); |
| 565 |
|
| 566 |
# If circcontrol is PatronLibrary we count all the patron's loan, regardless of branch |
| 567 |
t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary'); |
| 568 |
is_deeply( |
| 569 |
C4::Circulation::TooMany( $patron, $branch_item->biblionumber, $branch_item->unblessed ), |
| 570 |
{ |
| 571 |
reason => 'TOO_MANY_CHECKOUTS', |
| 572 |
count => 1, |
| 573 |
max_allowed => 1, |
| 574 |
}, |
| 575 |
'We are allowed one from the branch specifically, but have one' |
| 576 |
); |
| 577 |
t::lib::Mocks::mock_preference('CircControl', 'ItemHomeLibrary'); |
| 578 |
|
| 579 |
$issue = C4::Circulation::AddIssue( $patron, $branch_item->barcode, dt_from_string() ); |
| 580 |
# We issue that one |
| 581 |
# And make another |
| 582 |
my $branch_item_2 = $builder->build_sample_item({ |
| 583 |
itype => $itemtype->{itemtype}, |
| 584 |
homebranch => $branch->{branchcode}, |
| 585 |
holdingbranch => $branch->{branchcode} |
| 586 |
}); |
| 587 |
is_deeply( |
| 588 |
C4::Circulation::TooMany( $patron, $branch_item_2->biblionumber, $branch_item_2->unblessed ), |
| 589 |
{ |
| 590 |
reason => 'TOO_MANY_CHECKOUTS', |
| 591 |
count => 1, |
| 592 |
max_allowed => 1, |
| 593 |
}, |
| 594 |
'We are only allowed one from that branch, and have one' |
| 595 |
); |
| 596 |
|
| 597 |
# Now we make anothe from a different branch |
| 598 |
my $item_2 = $builder->build_sample_item({ |
| 599 |
itype => $itemtype->{itemtype}, |
| 600 |
}); |
| 601 |
is_deeply( |
| 602 |
C4::Circulation::TooMany( $patron, $item_2->biblionumber, $item_2->unblessed ), |
| 603 |
{ |
| 604 |
reason => 'TOO_MANY_CHECKOUTS', |
| 605 |
count => 2, |
| 606 |
max_allowed => 1, |
| 607 |
}, |
| 608 |
'We are only allowed one for general rule, and have two' |
| 609 |
); |
| 610 |
t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary'); |
| 611 |
is_deeply( |
| 612 |
C4::Circulation::TooMany( $patron, $item_2->biblionumber, $item_2->unblessed ), |
| 613 |
{ |
| 614 |
reason => 'TOO_MANY_CHECKOUTS', |
| 615 |
count => 2, |
| 616 |
max_allowed => 1, |
| 617 |
}, |
| 618 |
'We are only allowed one for general rule, and have two' |
| 619 |
); |
| 620 |
|
| 621 |
t::lib::Mocks::mock_preference('CircControl', 'PickupLibrary'); |
| 622 |
is_deeply( |
| 623 |
C4::Circulation::TooMany( $patron, $item_2->biblionumber, $item_2->unblessed ), |
| 624 |
{ |
| 625 |
reason => 'TOO_MANY_CHECKOUTS', |
| 626 |
count => 2, |
| 627 |
max_allowed => 1, |
| 628 |
}, |
| 629 |
'We are only allowed one for general rule, and have checked out two at this branch' |
| 630 |
); |
| 631 |
|
| 632 |
my $branch2 = $builder->build({source => 'Branch',}); |
| 633 |
t::lib::Mocks::mock_userenv({ branchcode => $branch2->{branchcode} }); |
| 634 |
is_deeply( |
| 635 |
C4::Circulation::TooMany( $patron, $item_2->biblionumber, $item_2->unblessed ), |
| 636 |
{ |
| 637 |
reason => 'TOO_MANY_CHECKOUTS', |
| 638 |
count => 2, |
| 639 |
max_allowed => 1, |
| 640 |
}, |
| 641 |
'We are only allowed one for general rule, and have two total (no rule for specific branch)' |
| 642 |
); |
| 643 |
# Set a branch specific rule for new branch |
| 644 |
Koha::CirculationRules->set_rules( |
| 645 |
{ |
| 646 |
branchcode => $branch2->{branchcode}, |
| 647 |
categorycode => $category->{categorycode}, |
| 648 |
itemtype => $itemtype->{itemtype}, |
| 649 |
rules => { |
| 650 |
maxissueqty => 1, |
| 651 |
maxonsiteissueqty => 1, |
| 652 |
} |
| 653 |
} |
| 654 |
); |
| 655 |
|
| 656 |
is( |
| 657 |
C4::Circulation::TooMany( $patron, $branch_item->biblionumber, $branch_item->unblessed ), |
| 658 |
undef, |
| 659 |
'We are allowed one from the branch specifically now' |
| 660 |
); |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
}; |
| 665 |
|
| 472 |
$schema->storage->txn_rollback; |
666 |
$schema->storage->txn_rollback; |
| 473 |
|
667 |
|
| 474 |
sub teardown { |
668 |
sub teardown { |
| 475 |
- |
|
|