From c83af1051f32a358fc172379ab1e95436810b871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Fri, 18 Dec 2020 12:22:46 +0200 Subject: [PATCH] Bug 27259: Test HomeOrHoldingBranch usage in TooMany() This shows that HomeOrHoldingBranch syspref is incorrectly not used by TooMany() when it decides which circ rule to use. Run "prove t/db_dependent/Circulation/TooMany.t" to notice the tests now fail. --- t/db_dependent/Circulation/TooMany.t | 73 +++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t index d1663d98a3..1a4af10fb2 100755 --- a/t/db_dependent/Circulation/TooMany.t +++ b/t/db_dependent/Circulation/TooMany.t @@ -15,7 +15,7 @@ # with Koha; if not, see . use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use C4::Context; use C4::Members; @@ -52,6 +52,10 @@ my $branch = $builder->build({ source => 'Branch', }); +my $branch2 = $builder->build({ + source => 'Branch', +}); + my $category = $builder->build({ source => 'Category', }); @@ -583,6 +587,8 @@ subtest 'General vs specific rules limit quantity correctly' => sub { } ); + t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch'); + is( C4::Circulation::TooMany( $patron, $branch_item ), undef, @@ -655,7 +661,6 @@ subtest 'General vs specific rules limit quantity correctly' => sub { 'We are only allowed one for general rule, and have checked out two at this branch' ); - my $branch2 = $builder->build({source => 'Branch',}); t::lib::Mocks::mock_userenv({ branchcode => $branch2->{branchcode} }); is_deeply( C4::Circulation::TooMany( $patron, $item_2 ), @@ -977,6 +982,70 @@ subtest 'itemtype group tests' => sub { teardown(); }; +subtest 'HomeOrHoldingBranch is used' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference( 'CircControl', 'ItemHomeLibrary' ); + + my $item_1 = $builder->build_sample_item( + { + homebranch => $branch->{branchcode}, + holdingbranch => $branch2->{branchcode}, + } + ); + + Koha::CirculationRules->set_rules( + { + branchcode => $branch->{branchcode}, + categorycode => undef, + itemtype => undef, + rules => { + maxissueqty => 0, + } + } + ); + + Koha::CirculationRules->set_rules( + { + branchcode => $branch2->{branchcode}, + categorycode => undef, + itemtype => undef, + rules => { + maxissueqty => 1, + } + } + ); + + t::lib::Mocks::mock_userenv({ branchcode => $branch2->{branchcode} }); + my $issue = C4::Circulation::AddIssue( $patron, $item_1->barcode, dt_from_string() ); + + t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch'); + + is_deeply( + C4::Circulation::TooMany( $patron, $item_1 ), + { + reason => 'TOO_MANY_CHECKOUTS', + max_allowed => 0, + count => 1, + }, + 'We are allowed zero issues from the homebranch specifically' + ); + + t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch'); + + is_deeply( + C4::Circulation::TooMany( $patron, $item_1 ), + { + reason => 'TOO_MANY_CHECKOUTS', + max_allowed => 1, + count => 1, + }, + 'We are allowed one issue from the holdingbranch specifically' + ); + + teardown(); +}; + $schema->storage->txn_rollback; sub teardown { -- 2.11.0