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

(-)a/t/db_dependent/Circulation.t (-21 / +20 lines)
Lines 840-853 subtest "CanBookBeRenewed tests" => sub { Link Here
840
        }
840
        }
841
    );
841
    );
842
842
843
    my $issue_4 = AddIssue( $renewing_borrower_obj->unblessed, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } );
843
    my $auto_renew_issue = AddIssue( $renewing_borrower_obj->unblessed, $item_4->barcode, undef, undef, undef, undef, { auto_renew => 1 } );
844
    my $info;
844
    my $info;
845
    ( $renewokay, $error, $info ) =
845
    ( $renewokay, $error, $info ) =
846
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
846
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
847
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
847
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
848
    is( $error, 'auto_too_soon',
848
    is( $error, 'auto_too_soon',
849
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
849
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
850
    is( $info->{soonest_renew_date} , dt_from_string($issue_4->date_due), "Due date is returned as earliest renewal date when error is 'auto_too_soon'" );
850
    is( $info->{soonest_renew_date} , dt_from_string($auto_renew_issue->date_due), "Due date is returned as earliest renewal date when error is 'auto_too_soon'" );
851
    AddReserve(
851
    AddReserve(
852
        {
852
        {
853
            branchcode       => $branch,
853
            branchcode       => $branch,
Lines 863-891 subtest "CanBookBeRenewed tests" => sub { Link Here
863
            found            => $found
863
            found            => $found
864
        }
864
        }
865
    );
865
    );
866
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
866
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
867
    is( $renewokay, 0, 'Still should not be able to renew' );
867
    is( $renewokay, 0, 'Still should not be able to renew' );
868
    is( $error, 'on_reserve', 'returned code is on_reserve, reserve checked when not checking for cron' );
868
    is( $error, 'on_reserve', 'returned code is on_reserve, reserve checked when not checking for cron' );
869
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4, undef, 1 );
869
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
870
    is( $renewokay, 0, 'Still should not be able to renew' );
870
    is( $renewokay, 0, 'Still should not be able to renew' );
871
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' );
871
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' );
872
    is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due), "Due date is returned as earliest renewal date when error is 'auto_too_soon'" );
872
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Due date is returned as earliest renewal date when error is 'auto_too_soon'" );
873
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4, 1 );
873
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, 1 );
874
    is( $renewokay, 0, 'Still should not be able to renew' );
874
    is( $renewokay, 0, 'Still should not be able to renew' );
875
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
875
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
876
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4, 1, 1 );
876
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, 1, 1 );
877
    is( $renewokay, 0, 'Still should not be able to renew' );
877
    is( $renewokay, 0, 'Still should not be able to renew' );
878
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
878
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
879
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
879
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
880
    Koha::Cache::Memory::Lite->flush();
880
    Koha::Cache::Memory::Lite->flush();
881
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4, 1 );
881
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, 1 );
882
    is( $renewokay, 0, 'Still should not be able to renew' );
882
    is( $renewokay, 0, 'Still should not be able to renew' );
883
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
883
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_renew only happens if not on reserve' );
884
    ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber);
884
    ModReserveCancelAll($item_4->itemnumber, $reserving_borrowernumber);
885
885
886
    $renewing_borrower_obj = Koha::Patrons->find($renewing_borrower_obj->borrowernumber);
886
    $renewing_borrower_obj = Koha::Patrons->find($renewing_borrower_obj->borrowernumber);
887
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
887
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
888
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
888
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
889
    is( $renewokay, 1, 'No renewal before is undef, but patron opted out of auto_renewal' );
889
    is( $renewokay, 1, 'No renewal before is undef, but patron opted out of auto_renewal' );
890
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
890
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
891
891
Lines 910-927 subtest "CanBookBeRenewed tests" => sub { Link Here
910
    # Bug 14101
910
    # Bug 14101
911
    # Test premature automatic renewal
911
    # Test premature automatic renewal
912
    ( $renewokay, $error, $info ) =
912
    ( $renewokay, $error, $info ) =
913
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
913
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
914
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
914
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
915
    is( $error, 'auto_too_soon',
915
    is( $error, 'auto_too_soon',
916
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
916
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
917
    );
917
    );
918
    is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'auto_too_soon'");
918
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'auto_too_soon'");
919
919
920
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
920
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
921
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
921
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
922
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
922
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
923
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
923
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
924
    is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
924
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
925
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
925
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
926
926
927
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
927
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
Lines 929-946 subtest "CanBookBeRenewed tests" => sub { Link Here
929
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
929
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'norenewalbefore'});
930
    Koha::Cache::Memory::Lite->flush();
930
    Koha::Cache::Memory::Lite->flush();
931
    ( $renewokay, $error, $info ) =
931
    ( $renewokay, $error, $info ) =
932
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
932
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
933
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
933
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
934
    is( $error, 'auto_too_soon',
934
    is( $error, 'auto_too_soon',
935
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
935
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
936
    );
936
    );
937
    is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
937
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
938
938
939
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
939
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
940
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
940
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
941
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
941
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
942
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
942
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
943
    is( $info->{soonest_renew_date}, dt_from_string($issue_4->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
943
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
944
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
944
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
945
945
946
    # Change policy so that loans can be renewed 99 days prior to the due date
946
    # Change policy so that loans can be renewed 99 days prior to the due date
Lines 948-961 subtest "CanBookBeRenewed tests" => sub { Link Here
948
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
948
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'norenewalbefore'});
949
    Koha::Cache::Memory::Lite->flush();
949
    Koha::Cache::Memory::Lite->flush();
950
    ( $renewokay, $error ) =
950
    ( $renewokay, $error ) =
951
      CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
951
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
952
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
952
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
953
    is( $error, 'auto_renew',
953
    is( $error, 'auto_renew',
954
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
954
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
955
    );
955
    );
956
956
957
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
957
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
958
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue_4 );
958
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
959
    is( $renewokay, 1, 'No renewal before is 99, patron opted out of auto_renewal so can renew' );
959
    is( $renewokay, 1, 'No renewal before is 99, patron opted out of auto_renewal so can renew' );
960
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
960
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
961
961
962
- 

Return to bug 25393