From 05c54ac7a430e44875838cfe7c2f316f6b42235a Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@kylehall.info>
Date: Fri, 17 Feb 2017 10:07:07 -0500
Subject: [PATCH] Bug 18139 - Prep unit tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Eric Gosselin <eric.gosselin@inlibro.com>

Signed-off-by: Marc Véron <veron@veron.ch>
---
 t/db_dependent/Circulation/TooMany.t | 247 +++++++++++++----------------------
 1 file changed, 88 insertions(+), 159 deletions(-)

diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t
index 428c08b..1013dd3 100644
--- a/t/db_dependent/Circulation/TooMany.t
+++ b/t/db_dependent/Circulation/TooMany.t
@@ -91,21 +91,18 @@ C4::Context->set_userenv($patron->{borrowernumber}, $patron->{userid}, 'usercnum
 # OSCO: On-site checkout
 
 subtest 'no rules exist' => sub {
-    plan tests => 2;
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        { reason => 'NO_RULE_DEFINED', max_allowed => 0 },
-        'CO should not be allowed, in any cases'
-    );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        { reason => 'NO_RULE_DEFINED', max_allowed => 0 },
-        'OSCO should not be allowed, in any cases'
-    );
+    plan tests => 4;
+    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' );
+
+    $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' );
 };
 
 subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
-    plan tests => 4;
+    plan tests => 12;
     my $issuingrule = $builder->build({
         source => 'Issuingrule',
         value => {
@@ -117,44 +114,27 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub {
         },
     });
     t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 0,
-            max_allowed => 0,
-        },
-        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
-    );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        {
-            reason => 'TOO_MANY_ONSITE_CHECKOUTS',
-            count => 0,
-            max_allowed => 0,
-        },
-        'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
-    );
+    my $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}, 0, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' );
+    is( $too_many->{max_allowed}, 0, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' );
+
+    $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' );
 
     t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1);
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 0,
-            max_allowed => 0,
-        },
-        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1'
-    );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        {
-            reason => 'TOO_MANY_ONSITE_CHECKOUTS',
-            count => 0,
-            max_allowed => 0,
-        },
-        'OSCO should not be allowed if 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}, 0, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' );
+    is( $too_many->{max_allowed}, 0, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' );
+
+    $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' );
 
     teardown();
 };
@@ -199,7 +179,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;
+    plan tests => 11;
     my $issuingrule = $builder->build({
         source => 'Issuingrule',
         value => {
@@ -215,15 +195,11 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
     like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
 
     t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
-    );
+    my $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(
         C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
         undef,
@@ -231,30 +207,22 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub {
     );
 
     t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1);
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1'
-    );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'OSCO should not be allowed if 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' );
+
+    $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' );
 
     teardown();
 };
 
 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
-    plan tests => 5;
+    plan tests => 11;
     my $issuingrule = $builder->build({
         source => 'Issuingrule',
         value => {
@@ -275,35 +243,22 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub {
         undef,
         'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
     );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        {
-            reason => 'TOO_MANY_ONSITE_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
-    );
+
+    my $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' );
 
     t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1);
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1'
-    );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        {
-            reason => 'TOO_MANY_ONSITE_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'OSCO should not be allowed if 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' );
+
+    $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' );
 
     teardown();
 };
@@ -312,7 +267,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 => 10;
+    plan tests => 22;
     my $issuingrule = $builder->build({
         source => 'BranchBorrowerCircRule',
         value => {
@@ -327,15 +282,11 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub {
     like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' );
 
     t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0);
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
-    );
+    my $too_many = C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item );
+    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(
         C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
         undef,
@@ -343,24 +294,15 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub {
     );
 
     t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1);
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1'
-    );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'OSCO should not be allowed if 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' );
+
+    $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' );
 
     teardown();
 
@@ -373,35 +315,22 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub {
         undef,
         'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
     );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        {
-            reason => 'TOO_MANY_ONSITE_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0'
-    );
+
+    $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' );
 
     t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1);
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ),
-        {
-            reason => 'TOO_MANY_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1'
-    );
-    is_deeply(
-        C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item, { onsite_checkout => 1 } ),
-        {
-            reason => 'TOO_MANY_ONSITE_CHECKOUTS',
-            count => 1,
-            max_allowed => 1,
-        },
-        'OSCO should not be allowed if 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' );
+
+    $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' );
 
     teardown();
 };
-- 
2.1.4