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

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

Return to bug 25393