From 0eba55e99382a811c7e1c03d632c97d8bd8d2f9a Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 17 Feb 2017 15:23:26 +0000 Subject: [PATCH] Bug 18139 - Add additional unit tests --- t/db_dependent/Circulation/TooMany.t | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t index 9c720db..dc55714 100644 --- a/t/db_dependent/Circulation/TooMany.t +++ b/t/db_dependent/Circulation/TooMany.t @@ -91,18 +91,20 @@ C4::Context->set_userenv($patron->{borrowernumber}, $patron->{userid}, 'usercnum # OSCO: On-site checkout subtest 'no rules exist' => sub { - plan tests => 4; + plan tests => 6; my $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ); is( $too_many->{reason}, 'NO_RULE_DEFINED', 'CO should not be allowed, in any cases' ); is( $too_many->{max_allowed}, 0, 'CO should not be allowed, in any cases' ); + is( $too_many->{issuing_rule}, undef, 'TooMany should return no issuing rule' ); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ); is( $too_many->{reason}, 'NO_RULE_DEFINED', 'CO should not be allowed, in any cases' ); is( $too_many->{max_allowed}, 0, 'CO should not be allowed, in any cases' ); + is( $too_many->{issuing_rule}, undef, 'TooMany should return no issuing rule' ); }; subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { - plan tests => 12; + plan tests => 16; my $issuingrule = $builder->build({ source => 'Issuingrule', value => { @@ -118,11 +120,13 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{count}, 0, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{max_allowed}, 0, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ); is( $too_many->{reason}, 'TOO_MANY_ONSITE_CHECKOUTS', 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{count}, 0, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{max_allowed}, 0, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); @@ -130,11 +134,13 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{count}, 0, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{max_allowed}, 0, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ); is( $too_many->{reason}, 'TOO_MANY_ONSITE_CHECKOUTS', 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{count}, 0, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{max_allowed}, 0, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); teardown(); }; @@ -179,7 +185,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 => 11; + plan tests => 14; my $issuingrule = $builder->build({ source => 'Issuingrule', value => { @@ -199,6 +205,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{count}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{max_allowed}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); is( C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ), @@ -212,17 +219,19 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{count}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{max_allowed}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ); is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{count}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{max_allowed}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); teardown(); }; subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { - plan tests => 11; + plan tests => 14; my $issuingrule = $builder->build({ source => 'Issuingrule', value => { @@ -248,17 +257,20 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { is( $too_many->{reason}, 'TOO_MANY_ONSITE_CHECKOUTS', 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{count}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{max_allowed}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ); is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{count}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{max_allowed}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ); is( $too_many->{reason}, 'TOO_MANY_ONSITE_CHECKOUTS', 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{count}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{max_allowed}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); + is( ref $too_many->{issuing_rule}, 'Koha::IssuingRule', 'TooMany should return an issuing rule' ); teardown(); }; @@ -267,7 +279,7 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { # Note: the same test coul be done for # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm - plan tests => 22; + plan tests => 28; my $issuingrule = $builder->build({ source => 'BranchBorrowerCircRule', value => { @@ -286,6 +298,7 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{count}, 1, 'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{max_allowed}, 1, 'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); + is( $too_many->{issuing_rule}, undef, 'TooMany should return no issuing rule' ); is( C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ), @@ -298,11 +311,13 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{count}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{max_allowed}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); + is( $too_many->{issuing_rule}, undef, 'TooMany should return no issuing rule' ); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ); is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{count}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{max_allowed}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); + is( $too_many->{issuing_rule}, undef, 'TooMany should return no issuing rule' ); teardown(); @@ -320,17 +335,20 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { is( $too_many->{reason}, 'TOO_MANY_ONSITE_CHECKOUTS', 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{count}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( $too_many->{max_allowed}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); + is( $too_many->{issuing_rule}, undef, 'TooMany should return no issuing rule' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ); is( $too_many->{reason}, 'TOO_MANY_CHECKOUTS', 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{count}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{max_allowed}, 1, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); + is( $too_many->{issuing_rule}, undef, 'TooMany should return no issuing rule' ); $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ); is( $too_many->{reason}, 'TOO_MANY_ONSITE_CHECKOUTS', 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{count}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( $too_many->{max_allowed}, 1, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); + is( $too_many->{issuing_rule}, undef, 'TooMany should return no issuing rule' ); teardown(); }; -- 2.1.4