From 38615abdcc005b3c9e701b169b176a42328e6ee3 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 8 Jan 2020 12:30:41 +0000 Subject: [PATCH] Bug 21946: Update unit tests to pass under ES --- t/db_dependent/Circulation/TooMany.t | 93 ++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 51 deletions(-) diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t index 0065f0df0a..afde31274b 100644 --- a/t/db_dependent/Circulation/TooMany.t +++ b/t/db_dependent/Circulation/TooMany.t @@ -65,23 +65,14 @@ my $patron = $builder->build({ }, }); -my $biblio = $builder->build({ - source => 'Biblio', - value => { - branchcode => $branch->{branchcode}, - }, -}); -my $item = $builder->build({ - source => 'Item', - value => { - biblionumber => $biblio->{biblionumber}, - homebranch => $branch->{branchcode}, - holdingbranch => $branch->{branchcode}, - }, +my $biblio = $builder->build_sample_biblio({ branchcode => $branch->{branchcode} }); +my $item = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + homebranch => $branch->{branchcode}, + holdingbranch => $branch->{branchcode}, }); my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} ); -my $item_object = Koha::Items->find( $item->{itemnumber} ); t::lib::Mocks::mock_userenv( { patron => $patron_object }); # TooMany return ($current_loan_count, $max_loans_allowed) or undef @@ -91,12 +82,12 @@ t::lib::Mocks::mock_userenv( { patron => $patron_object }); subtest 'no rules exist' => sub { plan tests => 2; is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'NO_RULE_DEFINED', max_allowed => 0 }, 'CO should not be allowed, in any cases' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'NO_RULE_DEFINED', max_allowed => 0 }, 'OSCO should not be allowed, in any cases' ); @@ -117,7 +108,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 0, @@ -126,7 +117,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 0, @@ -137,7 +128,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 0, @@ -146,7 +137,7 @@ subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 0, @@ -173,10 +164,10 @@ subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub { }, ); - my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() ); + my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string() ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -185,14 +176,14 @@ subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), undef, 'OSCO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -201,7 +192,7 @@ subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -229,24 +220,24 @@ subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); is( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), undef, 'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), undef, 'OSCO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); is( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), undef, 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), undef, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); @@ -268,12 +259,12 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { } ); - my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() ); + my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string() ); 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, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -282,14 +273,14 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), undef, 'OSCO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -298,7 +289,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -324,17 +315,17 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { } ); - my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } ); + 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' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); is( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), undef, 'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 1, @@ -345,7 +336,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -354,7 +345,7 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 1, @@ -383,12 +374,12 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { } ); - my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef ); + my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string(), undef, undef, undef ); 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, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -397,14 +388,14 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { 'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), undef, 'OSCO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -413,7 +404,7 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -424,17 +415,17 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { teardown(); - $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } ); + $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' ); t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); is( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), undef, 'CO should be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 0' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 1, @@ -445,7 +436,7 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 1); is_deeply( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), { reason => 'TOO_MANY_CHECKOUTS', count => 1, @@ -454,7 +445,7 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { 'CO should not be allowed if ConsiderOnSiteCheckoutsAsNormalCheckouts == 1' ); is_deeply( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), { reason => 'TOO_MANY_ONSITE_CHECKOUTS', count => 1, @@ -687,13 +678,13 @@ subtest 'empty string means unlimited' => sub { }, ); is( - C4::Circulation::TooMany( $patron, $item_object ), + C4::Circulation::TooMany( $patron, $item ), undef, 'maxissueqty="" should mean unlimited' ); is( - C4::Circulation::TooMany( $patron, $item_object, { onsite_checkout => 1 } ), + C4::Circulation::TooMany( $patron, $item, { onsite_checkout => 1 } ), undef, 'maxonsiteissueqty="" should mean unlimited' ); -- 2.11.0