From 95f14fa5b2de8d043e6ca4c648f6e4e535ebc99c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Mei=C3=9Fner?= Date: Mon, 27 Jul 2015 15:18:53 +0200 Subject: [PATCH] Bug 14395: Unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes test cases that broke because of the changes introduced by bugs 14101 and 14395. Also adds new test cases. To test: 1) prove t/db_dependent/Circulation.t Sponsored-by: Hochschule für Gesundheit (hsg), Germany --- t/db_dependent/Circulation.t | 57 +++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 30a5fe7..b9b3700 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 => 64; BEGIN { use_ok('C4::Circulation'); @@ -377,7 +377,9 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $reserveid = C4::Reserves::GetReserveId({ biblionumber => $biblionumber, itemnumber => $itemnumber, borrowernumber => $reserving_borrowernumber}); CancelReserve({ reserve_id => $reserveid }); + # Bug 14101 # Test automatic renewal before value for "norenewalbefore" in policy is set + # In this case automatic renewal is not permitted prior to due date my $barcode4 = '11235813'; my ( $item_bibnum4, $item_bibitemnum4, $itemnumber4 ) = AddItem( { @@ -389,33 +391,60 @@ C4::Context->dbh->do("DELETE FROM accountlines"); $biblionumber ); - AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } ); + AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, + { auto_renew => 1 } ); ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 ); - is( $renewokay, 0, 'Cannot renew, renewal is automatic' ); - is( $error, 'auto_renew', - 'Cannot renew, renewal is automatic (returned code is auto_renew)' ); + is( $renewokay, 0, 'Cannot renew, renewal is automatic and premature' ); + is( $error, 'auto_too_soon', + 'Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)' + ); - # set policy to require that loans cannot be - # renewed until seven days prior to the due date + # Bug 7413 + # Test premature manual renewal $dbh->do('UPDATE issuingrules SET norenewalbefore = 7'); - ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber); - is( $renewokay, 0, 'Cannot renew, renewal is premature'); - is( $error, 'too_soon', 'Cannot renew, renewal is premature (returned code is too_soon)'); + ( $renewokay, $error ) = + CanBookBeRenewed( $renewing_borrowernumber, $itemnumber ); + is( $renewokay, 0, 'Cannot renew, renewal is premature' ); + is( $error, 'too_soon', + 'Cannot renew, renewal is premature (returned code is too_soon)' ); + + # Bug 14395 + # Test 'exact time' setting for syspref NoRenewalbeforePrecision + C4::Context->set_preference( 'NoRenewalBeforePrecision', 'exact_time' ); + is( + GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ), + $datedue->clone->add( days => -7 ), + 'renewals permitted 7 days before due date, as expected', + ); + + # Bug 14395 + # Test 'date' setting for syspref NoRenewalbeforePrecision + C4::Context->set_preference( 'NoRenewalBeforePrecision', 'date' ); is( - GetSoonestRenewDate($renewing_borrowernumber, $itemnumber), - $datedue->clone->add(days => -7), + GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ), + $datedue->clone->add( days => -7 )->truncate( to => 'day' ), 'renewals permitted 7 days before due date, as expected', ); - # Test automatic renewal again + # Bug 11577 + # Test premature automatic renewal ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 ); is( $renewokay, 0, 'Cannot renew, renewal is automatic and premature' ); is( $error, 'auto_too_soon', -'Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)' + 'Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)' ); + # Bug 11577 + # Test automatic renewal + $dbh->do('UPDATE issuingrules SET norenewalbefore = 50'); + ( $renewokay, $error ) = + CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 ); + is( $renewokay, 0, 'Cannot renew, renewal is automatic' ); + is( $error, 'auto_renew', + 'Cannot renew, renewal is automatic (returned code is auto_renew)' ); + # Too many renewals # set policy to forbid renewals -- 1.7.10.4