From 396a9f6a20df7cfbf7c5d5316537e22a00a45f65 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 28 Mar 2017 12:45:43 -0300 Subject: [PATCH] Bug 18139: Adapt tests --- C4/Circulation.pm | 2 +- t/db_dependent/Circulation/TooMany.t | 47 ++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index e59a559..92e8499 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -561,7 +561,7 @@ sub TooMany { } if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) { - return { reason => 'NO_RULE_DEFINED', max_allowed => 0, issuing_rule => $issuing_rule }; + return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; } # OK, the patron can issue !!! diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t index 428c08b..94faa48 100644 --- a/t/db_dependent/Circulation/TooMany.t +++ b/t/db_dependent/Circulation/TooMany.t @@ -106,7 +106,7 @@ subtest 'no rules exist' => sub { subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { plan tests => 4; - my $issuingrule = $builder->build({ + my $issuing_rule = $builder->build({ source => 'Issuingrule', value => { branchcode => $branch->{branchcode}, @@ -116,6 +116,14 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { maxonsiteissueqty => 0, }, }); + $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( + { + categorycode => $patron->{categorycode}, + itemtype => $item->{itype}, + branchcode => C4::Circulation::_GetCircControlBranch( $item, $patron ), + } + ); + my $t = $issuing_rule->maxonsiteissueqty; # FIXME we need to fetch to populate $expected->{issuing_rule}{_columns} t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); is_deeply( C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ), @@ -123,6 +131,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { reason => 'TOO_MANY_CHECKOUTS', count => 0, max_allowed => 0, + issuing_rule => $issuing_rule, }, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); @@ -132,6 +141,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 0, max_allowed => 0, + issuing_rule => $issuing_rule, }, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); @@ -143,6 +153,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { reason => 'TOO_MANY_CHECKOUTS', count => 0, max_allowed => 0, + issuing_rule => $issuing_rule, }, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); @@ -152,6 +163,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 0, max_allowed => 0, + issuing_rule => $issuing_rule, }, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); @@ -161,7 +173,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { plan tests => 4; - my $issuingrule = $builder->build({ + my $issuing_rule = $builder->build({ source => 'Issuingrule', value => { branchcode => $branch->{branchcode}, @@ -200,7 +212,7 @@ subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { plan tests => 5; - my $issuingrule = $builder->build({ + my $issuing_rule = $builder->build({ source => 'Issuingrule', value => { branchcode => $branch->{branchcode}, @@ -210,6 +222,15 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { maxonsiteissueqty => 1, }, }); + $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( + { + categorycode => $patron->{categorycode}, + itemtype => $item->{itype}, + branchcode => C4::Circulation::_GetCircControlBranch( $item, $patron ), + issuing_rule => $issuing_rule, + } + ); + my $t = $issuing_rule->maxonsiteissueqty; # FIXME we need to fetch to populate $expected->{issuing_rule}{_columns} my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() ); like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); @@ -221,6 +242,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { reason => 'TOO_MANY_CHECKOUTS', count => 1, max_allowed => 1, + issuing_rule => $issuing_rule, }, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); @@ -237,6 +259,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { reason => 'TOO_MANY_CHECKOUTS', count => 1, max_allowed => 1, + issuing_rule => $issuing_rule, }, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); @@ -246,6 +269,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { reason => 'TOO_MANY_CHECKOUTS', count => 1, max_allowed => 1, + issuing_rule => $issuing_rule, }, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); @@ -255,7 +279,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { plan tests => 5; - my $issuingrule = $builder->build({ + my $issuing_rule = $builder->build({ source => 'Issuingrule', value => { branchcode => $branch->{branchcode}, @@ -266,6 +290,16 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { }, }); + $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( + { + categorycode => $patron->{categorycode}, + itemtype => $item->{itype}, + branchcode => C4::Circulation::_GetCircControlBranch( $item, $patron ), + issuing_rule => $issuing_rule, + } + ); + my $t = $issuing_rule->maxonsiteissueqty; # FIXME we need to fetch to populate $expected->{issuing_rule}{_columns} + my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } ); like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); @@ -281,6 +315,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 1, max_allowed => 1, + issuing_rule => $issuing_rule, }, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); @@ -292,6 +327,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { reason => 'TOO_MANY_CHECKOUTS', count => 1, max_allowed => 1, + issuing_rule => $issuing_rule, }, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); @@ -301,6 +337,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 1, max_allowed => 1, + issuing_rule => $issuing_rule, }, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); @@ -313,7 +350,7 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm plan tests => 10; - my $issuingrule = $builder->build({ + my $issuing_rule = $builder->build({ source => 'BranchBorrowerCircRule', value => { branchcode => $branch->{branchcode}, -- 2.9.3