From 85d3052605c558d1b4058635d3aec234fc9349c0 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 5 Aug 2013 15:26:56 -0300 Subject: [PATCH] Bug 10663: tests for CanBookBeRenewed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Initial work on unit tests for CanBookBeRenewed. More scenarios are needed. Also made Circulation.t use autocommit=0. Sponsored-by: Universidad Nacional de Córdoba Signed-off-by: Katrin Fischer Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton (cherry picked from commit dc469424c8bcf952cb64f5c9dc2cdc53772d8ca5) Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Circulation.t | 129 +++++++++++++++++++++++++++++++++-- 1 file changed, 122 insertions(+), 7 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 31e5960184..b1b4b11341 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -1,21 +1,36 @@ #!/usr/bin/perl -use Test::More tests => 16; +use Modern::Perl; + +use DateTime; +use C4::Biblio; +use C4::Branch; +use C4::Items; +use C4::Members; +use C4::Reserves; + +use Test::More tests => 20; BEGIN { use_ok('C4::Circulation'); } +my $dbh = C4::Context->dbh; + +# Start transaction +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + my $CircControl = C4::Context->preference('CircControl'); my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch'); my $item = { - homebranch => 'ItemHomeBranch', - holdingbranch => 'ItemHoldingBranch' + homebranch => 'MPL', + holdingbranch => 'MPL' }; my $borrower = { - branchcode => 'BorrowerBranch' + branchcode => 'MPL' }; # No userenv, PickupLibrary @@ -59,8 +74,8 @@ is( diag('Now, set a userenv'); C4::Context->_new_userenv('xxx'); -C4::Context::set_userenv(0,0,0,'firstname','surname', 'CurrentBranch', 'CurrentBranchName', '', '', ''); -is(C4::Context->userenv->{branch}, 'CurrentBranch', 'userenv set'); +C4::Context::set_userenv(0,0,0,'firstname','surname', 'MPL', 'Midway Public Library', '', '', ''); +is(C4::Context->userenv->{branch}, 'MPL', 'userenv set'); # Userenv set, PickupLibrary C4::Context->set_preference('CircControl', 'PickupLibrary'); @@ -71,7 +86,7 @@ is( ); is( C4::Circulation::_GetCircControlBranch($item, $borrower), - 'CurrentBranch', + 'MPL', '_GetCircControlBranch returned current branch' ); @@ -125,3 +140,103 @@ ok( $new_count == $original_count + 1, 'ProcessOfflinePayment makes payment cor C4::Context->dbh->do("DELETE FROM accountlines WHERE borrowernumber IN ( SELECT borrowernumber FROM borrowers WHERE cardnumber = '99999999999' )"); C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'"); + +{ + # CanBookBeRenewed tests + + # Generate test biblio + my $biblio = MARC::Record->new(); + my $title = 'Silence in the library'; + $biblio->append_fields( + MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), + MARC::Field->new('245', ' ', ' ', a => $title), + ); + + my ($biblionumber, $biblioitemnumber); + ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, ''); + + my $barcode = 'R00000342'; + my $branch = 'MPL'; + + my ($item_bibnum, $item_bibitemnum, $itemnumber) = + AddItem({ homebranch => $branch, + holdingbranch => $branch, + barcode => $barcode } , $biblionumber); + + # Create a borrower + my %renewing_borrower_data = ( + firstname => 'Renewal', + surname => 'John', + categorycode => 'S', + branchcode => $branch, + ); + + my %reserving_borrower_data = ( + firstname => 'Reservation', + surname => 'Katrin', + categorycode => 'S', + branchcode => $branch, + ); + + my $renewing_borrowernumber = AddMember(%renewing_borrower_data); + my $reserving_borrowernumber = AddMember(%reserving_borrower_data); + + my $renewing_borrower = GetMember( borrowernumber => $renewing_borrowernumber ); + + my $constraint = 'a'; + my $bibitems = ''; + my $priority = '1'; + my $resdate = undef; + my $expdate = undef; + my $notes = ''; + my $checkitem = undef; + my $found = undef; + + my $now = DateTime->now(); + my $cancelreserve = 1; + + AddIssue( $renewing_borrower, $barcode, $now, $cancelreserve, $now ); + +# my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber); +# is( $renewokay, 1, 'Can renew, book not reserved'); + + diag("Biblio-level reserve, renewal test"); + AddReserve( + $branch, $reserving_borrowernumber, $biblionumber, + $constraint, $bibitems, $priority, $resdate, $expdate, $notes, + $title, $checkitem, $found + ); + + my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber); + + is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved'); + is( $error, 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve'); + + CancelReserve({ + biblionumber => $biblionumber, + borrowernumber => $reserving_borrowernumber, + }); + + + diag("Item-level reserve, renewal test"); + AddReserve( + $branch, $reserving_borrowernumber, $biblionumber, + $constraint, $bibitems, $priority, $resdate, $expdate, $notes, + $title, $itemnumber, $found + ); + + ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber); + + is( $renewokay, 0, '(Bug 10663) Cannot renew, item reserved'); + is( $error, 'on_reserve', '(Bug 10663) Cannot renew, item reserved (returned error is on_reserve'); + + CancelReserve({ + biblionumber => $biblionumber, + borrowernumber => $reserving_borrowernumber, + itemnumber => $itemnumber + }); + +} + + +$dbh->rollback; -- 2.39.5