From 48acc32ae89f24da37edf7c50c166d00ff0a4293 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 1 Apr 2015 15:05:36 +0200 Subject: [PATCH] Bug 8236: Tests for Renewing policy in overdue or restriction case - Add tests in t/db_dependent/Circulation.t Signed-off-by: Kyle M Hall --- t/db_dependent/Circulation.t | 82 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 30a5fe7..a88a680 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 => 70 ; BEGIN { use_ok('C4::Circulation'); @@ -234,6 +234,9 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $biblionumber ); + + + # Create borrowers my %renewing_borrower_data = ( firstname => 'John', @@ -256,11 +259,21 @@ C4::Context->dbh->do("DELETE FROM accountlines"); branchcode => $branch, ); + my %restricted_borrower_data = ( + firstname => 'Alice', + surname => 'Reservation', + categorycode => 'S', + debarred => '3228-01-01', + branchcode => $branch, + ); + my $renewing_borrowernumber = AddMember(%renewing_borrower_data); my $reserving_borrowernumber = AddMember(%reserving_borrower_data); my $hold_waiting_borrowernumber = AddMember(%hold_waiting_borrower_data); + my $restricted_borrowernumber = AddMember(%restricted_borrower_data); my $renewing_borrower = GetMember( borrowernumber => $renewing_borrowernumber ); + my $restricted_borrower = GetMember( borrowernumber => $restricted_borrowernumber ); my $constraint = 'a'; my $bibitems = ''; @@ -279,6 +292,7 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $datedue = dt_from_string( $issue->date_due() ); is (defined $issue2, 1, "Item 2 checked out, due date: " . $issue2->date_due()); + my $borrowing_borrowernumber = GetItemIssue($itemnumber)->{borrowernumber}; is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}"); @@ -374,6 +388,62 @@ C4::Context->dbh->do("DELETE FROM accountlines"); # FIXME: Add more for itemtype not for loan etc. + # Restricted users cannot renew when RestrictionBlockRenewing is enabled + my $barcode5 = 'R00000347'; + my ( $item_bibnum5, $item_bibitemnum5, $itemnumber5 ) = AddItem( + { + homebranch => $branch, + holdingbranch => $branch, + barcode => $barcode5, + replacementprice => 23.00 + }, + $biblionumber + ); + my $datedue5 = AddIssue($restricted_borrower, $barcode5); + is (defined $datedue5, 1, "Item with date due checked out, due date: $datedue5"); + + C4::Context->set_preference('RestrictionBlockRenewing','1'); + ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber2); + is( $renewokay, 1, '(Bug 8236), Can renew, user is not restricted'); + ( $renewokay, $error ) = CanBookBeRenewed($restricted_borrowernumber, $itemnumber5); + is( $renewokay, 0, '(Bug 8236), Cannot renew, user is restricted'); + + # Users cannot renew an overdue item + my $barcode6 = 'R00000348'; + my ( $item_bibnum6, $item_bibitemnum6, $itemnumber6 ) = AddItem( + { + homebranch => $branch, + holdingbranch => $branch, + barcode => $barcode6, + replacementprice => 23.00 + }, + $biblionumber + ); + + my $barcode7 = 'R00000349'; + my ( $item_bibnum7, $item_bibitemnum7, $itemnumber7 ) = AddItem( + { + homebranch => $branch, + holdingbranch => $branch, + barcode => $barcode7, + replacementprice => 23.00 + }, + $biblionumber + ); + my $datedue6 = AddIssue( $renewing_borrower, $barcode6); + is (defined $datedue6, 1, "Item 2 checked out, due date: $datedue6"); + + my $passeddatedue1 = AddIssue($renewing_borrower, $barcode7, DateTime->from_epoch(epoch => 1)); + is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: $passeddatedue1"); + + + C4::Context->set_preference('OverduesBlockRenewing','blockitem'); + ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber6); + is( $renewokay, 1, '(Bug 8236), Can renew, this item is not overdue'); + ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber7); + is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue'); + + $reserveid = C4::Reserves::GetReserveId({ biblionumber => $biblionumber, itemnumber => $itemnumber, borrowernumber => $reserving_borrowernumber}); CancelReserve({ reserve_id => $reserveid }); @@ -469,7 +539,15 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $future->add( days => 7 ); my $units = C4::Overdues::get_chargeable_units('days', $future, $now, 'MPL'); ok( $units == 0, '_get_chargeable_units returns 0 for items not past due date (Bug 12596)' ); -} + + # Users cannot renew any item if there is an overdue item + C4::Context->set_preference('OverduesBlockRenewing','block'); + ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber6); + is( $renewokay, 0, '(Bug 8236), Cannot renew, one of the items is overdue'); + ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber7); + is( $renewokay, 0, '(Bug 8236), Cannot renew, one of the items is overdue'); + + } { # GetUpcomingDueIssues tests -- 1.7.10.4