View | Details | Raw Unified | Return to bug 14395
Collapse All | Expand All

(-)a/t/db_dependent/Circulation.t (-12 / +29 lines)
Lines 27-33 use C4::Overdues qw(UpdateFine); Link Here
27
use Koha::DateUtils;
27
use Koha::DateUtils;
28
use Koha::Database;
28
use Koha::Database;
29
29
30
use Test::More tests => 73;
30
use Test::More tests => 74;
31
31
32
BEGIN {
32
BEGIN {
33
    use_ok('C4::Circulation');
33
    use_ok('C4::Circulation');
Lines 376-382 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
376
    $reserveid = C4::Reserves::GetReserveId({ biblionumber => $biblionumber, itemnumber => $itemnumber, borrowernumber => $reserving_borrowernumber});
376
    $reserveid = C4::Reserves::GetReserveId({ biblionumber => $biblionumber, itemnumber => $itemnumber, borrowernumber => $reserving_borrowernumber});
377
    CancelReserve({ reserve_id => $reserveid });
377
    CancelReserve({ reserve_id => $reserveid });
378
378
379
    # Bug 14101
379
    # Test automatic renewal before value for "norenewalbefore" in policy is set
380
    # Test automatic renewal before value for "norenewalbefore" in policy is set
381
    # In this case automatic renewal is not permitted prior to due date
380
    my $barcode4 = '11235813';
382
    my $barcode4 = '11235813';
381
    my ( $item_bibnum4, $item_bibitemnum4, $itemnumber4 ) = AddItem(
383
    my ( $item_bibnum4, $item_bibitemnum4, $itemnumber4 ) = AddItem(
382
        {
384
        {
Lines 388-418 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
388
        $biblionumber
390
        $biblionumber
389
    );
391
    );
390
392
391
    AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef, { auto_renew => 1 } );
393
    AddIssue( $renewing_borrower, $barcode4, undef, undef, undef, undef,
394
        { auto_renew => 1 } );
392
    ( $renewokay, $error ) =
395
    ( $renewokay, $error ) =
393
      CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
396
      CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
394
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
397
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
395
    is( $error, 'auto_too_soon',
398
    is( $error, 'auto_too_soon',
396
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
399
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
397
400
398
    # set policy to require that loans cannot be
401
    # Bug 7413
399
    # renewed until seven days prior to the due date
402
    # Test premature manual renewal
400
    $dbh->do('UPDATE issuingrules SET norenewalbefore = 7');
403
    $dbh->do('UPDATE issuingrules SET norenewalbefore = 7');
404
401
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber);
405
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber);
402
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
406
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
403
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
407
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
408
409
    # Bug 14395
410
    # Test 'exact time' setting for syspref NoRenewalbeforePrecision
411
    C4::Context->set_preference( 'NoRenewalBeforePrecision', 'exact_time' );
412
    is(
413
        GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ),
414
        $datedue->clone->add( days => -7 ),
415
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
416
    );
417
418
    # Bug 14395
419
    # Test 'date' setting for syspref NoRenewalbeforePrecision
420
    C4::Context->set_preference( 'NoRenewalBeforePrecision', 'date' );
404
    is(
421
    is(
405
        GetSoonestRenewDate($renewing_borrowernumber, $itemnumber),
422
        GetSoonestRenewDate( $renewing_borrowernumber, $itemnumber ),
406
        $datedue->clone->add(days => -7),
423
        $datedue->clone->add( days => -7 )->truncate( to => 'day' ),
407
        'Bug 7413: Renewals permitted 7 days before due date, as expected',
424
        'Bug 14395: Renewals permitted 7 days before due date, as expected'
408
    );
425
    );
409
426
410
    # Test automatic renewal again
427
    # Bug 14101
428
    # Test premature automatic renewal
411
    ( $renewokay, $error ) =
429
    ( $renewokay, $error ) =
412
      CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
430
      CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
413
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
431
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
414
    is( $error, 'auto_too_soon',
432
    is( $error, 'auto_too_soon',
415
'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
433
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
416
    );
434
    );
417
435
418
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
436
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
Lines 422-428 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
422
      CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
440
      CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
423
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
441
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
424
    is( $error, 'auto_too_soon',
442
    is( $error, 'auto_too_soon',
425
'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
443
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
426
    );
444
    );
427
445
428
    # Change policy so that loans can be renewed 99 days prior to the due date
446
    # Change policy so that loans can be renewed 99 days prior to the due date
Lines 432-438 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
432
      CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
450
      CanBookBeRenewed( $renewing_borrowernumber, $itemnumber4 );
433
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
451
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
434
    is( $error, 'auto_renew',
452
    is( $error, 'auto_renew',
435
'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
453
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
436
    );
454
    );
437
455
438
    # Too many renewals
456
    # Too many renewals
439
- 

Return to bug 14395