Bugzilla – Attachment 88538 Details for
Bug 22759
Circulation rules for maxissueqty are applied per branch even for defaults
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22759: Unit tests
Bug-22759-Unit-tests.patch (text/plain), 7.44 KB, created by
Liz Rea
on 2019-04-23 16:40:42 UTC
(
hide
)
Description:
Bug 22759: Unit tests
Filename:
MIME Type:
Creator:
Liz Rea
Created:
2019-04-23 16:40:42 UTC
Size:
7.44 KB
patch
obsolete
>From d7c439b680cf5bdd26b664ce41e8790dce07aa5f Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 23 Apr 2019 16:17:20 +0000 >Subject: [PATCH] Bug 22759: Unit tests > >To test: >1 - Apply only this patch >2 - prove -v t/db_dependent/Circulation/TooMany.t >3 - It fails >4 - Apply second path >5 - repeat >6 - All green! > >Signed-off-by: Liz Rea <wizzyrea@gmail.com> >--- > t/db_dependent/Circulation/TooMany.t | 196 ++++++++++++++++++++++++++++++++++- > 1 file changed, 195 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t >index 47263a9865..1f1c6a7ee0 100644 >--- a/t/db_dependent/Circulation/TooMany.t >+++ b/t/db_dependent/Circulation/TooMany.t >@@ -15,7 +15,7 @@ > # with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 7; >+use Test::More tests => 8; > use C4::Context; > > use C4::Members; >@@ -469,6 +469,200 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { > teardown(); > }; > >+subtest 'General vs specific rules limit quantity correctly' => sub { >+ plan tests => 9; >+ >+ t::lib::Mocks::mock_preference('CircControl', 'ItemHomeLibrary'); >+ my $branch = $builder->build({source => 'Branch',}); >+ my $category = $builder->build({source => 'Category',}); >+ my $itemtype = $builder->build({ >+ source => 'Itemtype', >+ value => { >+ rentalcharge => 0, >+ rentalcharge_daily => 0, >+ rentalcharge_hourly => 0, >+ notforloan => 0, >+ } >+ }); >+ my $patron = $builder->build({ >+ source => 'Borrower', >+ value => { >+ categorycode => $category->{categorycode}, >+ branchcode => $branch->{branchcode}, >+ } >+ }); >+ >+ # Set up an issuing rule >+ my $rule = $builder->build({ >+ source => 'Issuingrule', >+ value => { >+ categorycode => '*', >+ itemtype => $itemtype->{itemtype}, >+ branchcode => '*', >+ issuelength => 1, >+ firstremind => 1, # 1 day of grace >+ finedays => 2, # 2 days of fine per day of overdue >+ lengthunit => 'days', >+ } >+ }); >+ >+ # Set an All->All for an itemtype >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => '*', >+ categorycode => '*', >+ itemtype => $itemtype->{itemtype}, >+ rules => { >+ maxissueqty => 1, >+ maxonsiteissueqty => 1, >+ } >+ } >+ ); >+ >+ # Create an item >+ my $item = $builder->build_sample_item({ >+ itype => $itemtype->{itemtype} >+ }); >+ my $branch_item = $builder->build_sample_item({ >+ itype => $itemtype->{itemtype}, >+ homebranch => $branch->{branchcode}, >+ holdingbranch => $branch->{branchcode} >+ }); >+ >+ >+ t::lib::Mocks::mock_userenv({ branchcode => $branch->{branchcode} }); >+ my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string() ); >+ # We checkout one item >+ is_deeply( >+ C4::Circulation::TooMany( $patron, $branch_item->biblionumber, $branch_item->unblessed ), >+ { >+ reason => 'TOO_MANY_CHECKOUTS', >+ count => 1, >+ max_allowed => 1, >+ }, >+ 'We are only allowed one, and we have one' >+ ); >+ >+ >+ # Set a branch specific rule >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch->{branchcode}, >+ categorycode => $category->{categorycode}, >+ itemtype => $itemtype->{itemtype}, >+ rules => { >+ maxissueqty => 1, >+ maxonsiteissueqty => 1, >+ } >+ } >+ ); >+ >+ is( >+ C4::Circulation::TooMany( $patron, $branch_item->biblionumber, $branch_item->unblessed ), >+ undef, >+ 'We are allowed one from the branch specifically now' >+ ); >+ >+ # If circcontrol is PatronLibrary we count all the patron's loan, regardless of branch >+ t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary'); >+ is_deeply( >+ C4::Circulation::TooMany( $patron, $branch_item->biblionumber, $branch_item->unblessed ), >+ { >+ reason => 'TOO_MANY_CHECKOUTS', >+ count => 1, >+ max_allowed => 1, >+ }, >+ 'We are allowed one from the branch specifically, but have one' >+ ); >+ t::lib::Mocks::mock_preference('CircControl', 'ItemHomeLibrary'); >+ >+ $issue = C4::Circulation::AddIssue( $patron, $branch_item->barcode, dt_from_string() ); >+ # We issue that one >+ # And make another >+ my $branch_item_2 = $builder->build_sample_item({ >+ itype => $itemtype->{itemtype}, >+ homebranch => $branch->{branchcode}, >+ holdingbranch => $branch->{branchcode} >+ }); >+ is_deeply( >+ C4::Circulation::TooMany( $patron, $branch_item_2->biblionumber, $branch_item_2->unblessed ), >+ { >+ reason => 'TOO_MANY_CHECKOUTS', >+ count => 1, >+ max_allowed => 1, >+ }, >+ 'We are only allowed one from that branch, and have one' >+ ); >+ >+ # Now we make anothe from a different branch >+ my $item_2 = $builder->build_sample_item({ >+ itype => $itemtype->{itemtype}, >+ }); >+ is_deeply( >+ C4::Circulation::TooMany( $patron, $item_2->biblionumber, $item_2->unblessed ), >+ { >+ reason => 'TOO_MANY_CHECKOUTS', >+ count => 2, >+ max_allowed => 1, >+ }, >+ 'We are only allowed one for general rule, and have two' >+ ); >+ t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary'); >+ is_deeply( >+ C4::Circulation::TooMany( $patron, $item_2->biblionumber, $item_2->unblessed ), >+ { >+ reason => 'TOO_MANY_CHECKOUTS', >+ count => 2, >+ max_allowed => 1, >+ }, >+ 'We are only allowed one for general rule, and have two' >+ ); >+ >+ t::lib::Mocks::mock_preference('CircControl', 'PickupLibrary'); >+ is_deeply( >+ C4::Circulation::TooMany( $patron, $item_2->biblionumber, $item_2->unblessed ), >+ { >+ reason => 'TOO_MANY_CHECKOUTS', >+ count => 2, >+ max_allowed => 1, >+ }, >+ '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->biblionumber, $item_2->unblessed ), >+ { >+ reason => 'TOO_MANY_CHECKOUTS', >+ count => 2, >+ max_allowed => 1, >+ }, >+ 'We are only allowed one for general rule, and have two total (no rule for specific branch)' >+ ); >+ # Set a branch specific rule for new branch >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch2->{branchcode}, >+ categorycode => $category->{categorycode}, >+ itemtype => $itemtype->{itemtype}, >+ rules => { >+ maxissueqty => 1, >+ maxonsiteissueqty => 1, >+ } >+ } >+ ); >+ >+ is( >+ C4::Circulation::TooMany( $patron, $branch_item->biblionumber, $branch_item->unblessed ), >+ undef, >+ 'We are allowed one from the branch specifically now' >+ ); >+ >+ >+ >+}; >+ > $schema->storage->txn_rollback; > > sub teardown { >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22759
:
88530
|
88531
|
88538
|
88540
|
88565
|
88566