From 299e13b0866533d98728070e933ecf97afb6463c Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 20 Aug 2015 06:46:51 -0400 Subject: [PATCH] Bug 14337 - Add Unit Tests --- t/db_dependent/Circulation.t | 86 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 83 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 30a5fe7..70945f0 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -27,7 +27,7 @@ use C4::Overdues qw(UpdateFine); use Koha::DateUtils; use Koha::Database; -use Test::More tests => 61; +use Test::More tests => 65; BEGIN { use_ok('C4::Circulation'); @@ -37,8 +37,8 @@ my $dbh = C4::Context->dbh; my $schema = Koha::Database->new()->schema(); # Start transaction -$dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; +$schema->storage->txn_begin(); # Start with a clean slate $dbh->do('DELETE FROM issues'); @@ -594,6 +594,86 @@ C4::Context->dbh->do("DELETE FROM accountlines"); is ( $count, 0, "Calling UpdateFine on non-existant fine with an amount of 0 does not result in an empty fine" ); } -$dbh->rollback; +{ + $dbh->do('DELETE FROM issues'); + $dbh->do('DELETE FROM items'); + $dbh->do('DELETE FROM issuingrules'); + $dbh->do( + q{ + INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod, + norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) + }, + {}, + '*', '*', '*', 25, + 20, 14, 'days', + 1, 7, + '', 0, + .10, 1 + ); + my $biblio = MARC::Record->new(); + my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' ); + + my $barcode1 = '1234'; + my ( undef, undef, $itemnumber1 ) = AddItem( + { + homebranch => 'MPL', + holdingbranch => 'MPL', + barcode => $barcode1, + }, + $biblionumber + ); + my $barcode2 = '4321'; + my ( undef, undef, $itemnumber2 ) = AddItem( + { + homebranch => 'MPL', + holdingbranch => 'MPL', + barcode => $barcode2, + }, + $biblionumber + ); + + my $borrowernumber1 = AddMember( + firstname => 'Kyle', + surname => 'Hall', + categorycode => 'S', + branchcode => 'MPL', + ); + my $borrowernumber2 = AddMember( + firstname => 'Chelsea', + surname => 'Hall', + categorycode => 'S', + branchcode => 'MPL', + ); + + my $borrower1 = GetMember( borrowernumber => $borrowernumber1 ); + my $borrower2 = GetMember( borrowernumber => $borrowernumber2 ); + + my $issue = AddIssue( $borrower1, $barcode1 ); + + my ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 ); + is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with no hold on the record' ); + + AddReserve( + 'MPL', $borrowernumber2, $biblionumber, + 'a', '', 1, undef, undef, '', + undef, undef, undef + ); + + ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 ); + is( $renewokay, 0, 'Bug 14337 - Verify the borrower cannot renew with a hold on the record' ); + + C4::Context->dbh->do("UPDATE issuingrules SET onshelfholds = 1"); + C4::Context->set_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); + + ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 ); + is( $renewokay, 1, 'Bug 14337 - Verify the borrower can renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled' ); + + # Setting item not checked out to be not for loan but holdable + ModItem({ notforloan => -1 }, $biblionumber, $itemnumber2); + + ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $itemnumber1 ); + is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' ); +} +$schema->storage->txn_rollback(); 1; -- 1.7.2.5