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

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

Return to bug 14395