From 5a2b378be1fd245d5df990fa1ff4b4341d99e153 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 24 May 2017 08:50:16 -0400 Subject: [PATCH] Bug 15494 - Unit tests prove t/db_dependent/Circulation.t --- t/db_dependent/Circulation.t | 109 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 17752bd..dba1997 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 103; +use Test::More tests => 104; use DateTime; @@ -208,7 +208,7 @@ C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'"); C4::Context->dbh->do("DELETE FROM accountlines"); { # CanBookBeRenewed tests - + t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' ); #Ensure pref doesn't affect current tests # Generate test biblio my $biblio = MARC::Record->new(); my $title = 'Silence in the library'; @@ -1873,6 +1873,111 @@ subtest 'CanBookBeIssued | is_overdue' => sub { my ($issuingimpossible, $needsconfirmation) = CanBookBeIssued($patron,$item->{barcode},$ten_days_go, undef, undef, undef); is( $needsconfirmation->{RENEW_ISSUE}, 1, "This is a renewal"); is( $needsconfirmation->{TOO_MANY}, undef, "Not too many, is a renewal"); +}; + +subtest 'ItemsDeniedRenewal preference' => sub { + plan tests => 14; + + t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', '' ); + + $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', + 10, 7, + undef, 0, + .10, 1 + ); + + my $deny_book = $builder->build_object({ class => 'Koha::Items', value => { + withdrawn => 1, + itype => 'HIDE', + location => 'PROC' + } + }); + my $allow_book = $builder->build_object({ class => 'Koha::Items', value => { + withdrawn => 0, + itype => 'NOHIDE', + location => 'NOPROC' + } + }); + + my $idr_borrower = $builder->build_object({ class => 'Koha::Patrons'}); + + my $deny_issue = $builder->build_object({ class => 'Koha::Checkouts', value => { + returndate => undef, + renewals => 0, + auto_renew => 0, + borrowernumber => $idr_borrower->borrowernumber, + itemnumber => $deny_book->itemnumber, + onsite_checkout => 0, + } + }); + my $allow_issue = $builder->build_object({ class => 'Koha::Checkouts', value => { + returndate => undef, + renewals => 0, + auto_renew => 0, + borrowernumber => $idr_borrower->borrowernumber, + itemnumber => $allow_book->itemnumber, + onsite_checkout => 0, + } + }); + + my $idr_rules; + + my ( $idr_mayrenew, $idr_error ) = + CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); + is( $idr_mayrenew, 1, 'Renewal allowed when no rules' ); + is( $idr_error, undef, 'Renewal allowed when no rules' ); + + $idr_rules=" + withdrawn: [1]"; + + t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); + ( $idr_mayrenew, $idr_error ) = + CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); + is( $idr_mayrenew, 0, 'Renewal blocked when 1 rules (withdrawn)' ); + is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 1 rule (withdrawn)' ); + ( $idr_mayrenew, $idr_error ) = + CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); + is( $idr_mayrenew, 1, 'Renewal allowed when 1 rules not matched (withdrawn)' ); + is( $idr_error, undef, 'Renewal allowed when 1 rules not matched (withdrawn)' ); + + $idr_rules=" + withdrawn: [1] + itype: [HIDE,INVISILE]"; + + t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); + ( $idr_mayrenew, $idr_error ) = + CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); + is( $idr_mayrenew, 0, 'Renewal blocked when 2 rules matched (withdrawn, itype)' ); + is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 2 rules matched (withdrawn,itype)' ); + ( $idr_mayrenew, $idr_error ) = + CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); + is( $idr_mayrenew, 1, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); + is( $idr_error, undef, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); + + $idr_rules=" + withdrawn: [1] + itype: [HIDE,INVISIBLE] + location: [PROC]"; + + t::lib::Mocks::mock_preference( 'ItemsDeniedRenewal', $idr_rules ); + ( $idr_mayrenew, $idr_error ) = + CanBookBeRenewed( $idr_borrower->borrowernumber, $deny_issue->itemnumber ); + is( $idr_mayrenew, 0, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' ); + is( $idr_error, 'item_denied_renewal', 'Renewal blocked when 3 rules matched (withdrawn,itype, location)' ); + ( $idr_mayrenew, $idr_error ) = + CanBookBeRenewed( $idr_borrower->borrowernumber, $allow_issue->itemnumber ); + is( $idr_mayrenew, 1, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); + is( $idr_error, undef, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); }; -- 2.1.4