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

(-)a/t/db_dependent/Circulation.t (-30 / +93 lines)
Lines 279-285 Koha::CirculationRules->set_rules( Link Here
279
            lengthunit      => 'days',
279
            lengthunit      => 'days',
280
            renewalsallowed => 1,
280
            renewalsallowed => 1,
281
            renewalperiod   => 7,
281
            renewalperiod   => 7,
282
            norenewalbefore => undef,
282
            norenewalbefore     => undef,
283
            noautorenewalbefore => undef,
283
            auto_renew      => 0,
284
            auto_renew      => 0,
284
            fine            => .10,
285
            fine            => .10,
285
            chargeperiod    => 1,
286
            chargeperiod    => 1,
Lines 426-432 subtest "GetIssuingCharges tests" => sub { Link Here
426
427
427
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
428
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
428
subtest "CanBookBeRenewed tests" => sub {
429
subtest "CanBookBeRenewed tests" => sub {
429
    plan tests => 104;
430
    plan tests => 112;
430
431
431
    C4::Context->set_preference('ItemsDeniedRenewal','');
432
    C4::Context->set_preference('ItemsDeniedRenewal','');
432
    # Generate test biblio
433
    # Generate test biblio
Lines 830-836 subtest "CanBookBeRenewed tests" => sub { Link Here
830
831
831
    # Bug 14101
832
    # Bug 14101
832
    # Test automatic renewal before value for "norenewalbefore" in policy is set
833
    # Test automatic renewal before value for "norenewalbefore" in policy is set
833
    # In this case automatic renewal is not permitted prior to due date
834
    # In this case automatic renewal should still be permitted
834
    my $item_4 = $builder->build_sample_item(
835
    my $item_4 = $builder->build_sample_item(
835
        {
836
        {
836
            biblionumber     => $biblio->biblionumber,
837
            biblionumber     => $biblio->biblionumber,
Lines 844-853 subtest "CanBookBeRenewed tests" => sub { Link Here
844
    my $info;
845
    my $info;
845
    ( $renewokay, $error, $info ) =
846
    ( $renewokay, $error, $info ) =
846
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
847
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
847
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
848
    is( $info->{soonest_renew_date}, undef, "soonest_renew_date is not returned because this issue can be renewed" );
848
    is( $error, 'auto_too_soon',
849
    is( $renewokay, 1, 'Bug 25393: Can do a manual renew, even if renewal is automatic and premature' );
849
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
850
    is(
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
        $error, 'auto_renew',
852
        'Bug 25393: Can do a manual renew, even if renewal is automatic and premature, norenewalbefore = undef -> manual renewals are allowed at any time'
853
    );
854
855
    my ( $renewokay_cron, $error_cron, $info_cron ) =
856
        CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
857
    is(
858
        $info_cron->{soonest_renew_date}, dt_from_string( $auto_renew_issue->date_due ),
859
        "Due date is returned as earliest renewal date when the CanBookBeRenewed check is done by cron and error is 'auto_too_soon'"
860
    );
851
    AddReserve(
861
    AddReserve(
852
        {
862
        {
853
            branchcode       => $branch,
863
            branchcode       => $branch,
Lines 907-922 subtest "CanBookBeRenewed tests" => sub { Link Here
907
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
917
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
908
    is( $info->{soonest_renew_date}, dt_from_string($issue_1->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
918
    is( $info->{soonest_renew_date}, dt_from_string($issue_1->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
909
919
910
    # Bug 14101
920
    # Bug 25393
911
    # Test premature automatic renewal
921
    # Test premature automatic renewal
922
    Koha::CirculationRules->set_rule(
923
        {
924
            categorycode => undef,
925
            branchcode   => undef,
926
            itemtype     => undef,
927
            rule_name    => 'noautorenewalbefore',
928
            rule_value   => '7',
929
        }
930
    );
931
912
    ( $renewokay, $error, $info ) =
932
    ( $renewokay, $error, $info ) =
913
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
933
    CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
914
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
934
    is( $renewokay, 0, 'Bug 25393: Cannot renew, renewal is premature' );
915
    is( $error, 'auto_too_soon',
935
    is( $error, 'too_soon',
916
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
936
        'Bug 25393: Cannot renew, renewal is premature (returned code is too_soon)'
917
    );
937
    );
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'");
938
    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
939
940
    ( $renewokay_cron, $error_cron, $info_cron ) =
941
        CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
942
    is(
943
        $error_cron, 'auto_too_soon',
944
        'Bug 25393: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
945
    );
920
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
946
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
921
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
947
    ( $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' );
948
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
Lines 930-938 subtest "CanBookBeRenewed tests" => sub { Link Here
930
    Koha::Cache::Memory::Lite->flush();
956
    Koha::Cache::Memory::Lite->flush();
931
    ( $renewokay, $error, $info ) =
957
    ( $renewokay, $error, $info ) =
932
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
958
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
933
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
959
    is( $renewokay, 0, 'Bug 25393: Cannot manual renew, renewal is too soon' );
960
    is( $error, 'too_soon',
961
        'Bug 25393: Cannot manual renew, renewal is too soon, even though it\'s also scheduled for auto renewal'
962
    );
963
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
964
965
    # Now we test for noautorenewalbefore if cron
966
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'noautorenewalbefore'});
967
    Koha::Cache::Memory::Lite->flush();
968
    ( $renewokay, $error, $info ) =
969
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
970
    is( $renewokay, 0, 'Bug 25393: Cannot auto renew, renewal is too soon' );
934
    is( $error, 'auto_too_soon',
971
    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)'
972
        'Bug 25393: Cannot auto renew, auto renewal is too soon'
936
    );
973
    );
937
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
974
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
938
975
Lines 949-966 subtest "CanBookBeRenewed tests" => sub { Link Here
949
    Koha::Cache::Memory::Lite->flush();
986
    Koha::Cache::Memory::Lite->flush();
950
    ( $renewokay, $error ) =
987
    ( $renewokay, $error ) =
951
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
988
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
952
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
989
    is( $renewokay, 1, 'Bug 25393: Can do a manual renew, even if renewal is automatic and premature' );
953
    is( $error, 'auto_renew',
990
    is( $error, 'auto_renew',
954
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
991
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
955
    );
992
    );
956
993
994
    # Now we test for noautorenewalbefore if cron
995
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'noautorenewalbefore'});
996
    Koha::Cache::Memory::Lite->flush();
997
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
998
    is( $renewokay, 1, 'Bug 25393: Can auto renew' );
999
    is( $error, 'auto_renew', 'Bug 25393: Can auto renew' );
1000
    is( $info->{soonest_renew_date}, undef, "soonest_renew_date is not returned because this issue can be renewed" );
1001
957
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
1002
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
958
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
1003
    ( $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' );
1004
    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;
1005
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
961
1006
962
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
1007
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
963
        plan tests => 14;
1008
        plan tests => 16;
964
        my $item_to_auto_renew = $builder->build_sample_item(
1009
        my $item_to_auto_renew = $builder->build_sample_item(
965
            {
1010
            {
966
                biblionumber => $biblio->biblionumber,
1011
                biblionumber => $biblio->biblionumber,
Lines 1017-1024 subtest "CanBookBeRenewed tests" => sub { Link Here
1017
        );
1062
        );
1018
        ( $renewokay, $error ) =
1063
        ( $renewokay, $error ) =
1019
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1064
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1020
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1065
        is( $renewokay, 0, 'Do not renew, too_soon' );
1021
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
1066
        is( $error, 'too_soon', 'Cannot renew, too_soon - no_auto_renewal_after is defined(returned code is too_soon)' );
1067
1068
        # Now check for cron
1069
        Koha::CirculationRules->set_rules(
1070
            {
1071
                categorycode => undef,
1072
                branchcode   => undef,
1073
                itemtype     => undef,
1074
                rules        => {
1075
                    noautorenewalbefore   => '9',
1076
                    no_auto_renewal_after => '11',
1077
                }
1078
            }
1079
        );
1080
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue, undef, 1 );
1081
        is( $renewokay, 0, 'Do not renew, too_soon' );
1082
        is(
1083
            $error, 'auto_too_soon',
1084
            'Cannot renew, too_soon - no_auto_renewal_after is defined(returned code is too_soon)'
1085
        );
1022
1086
1023
        Koha::CirculationRules->set_rules(
1087
        Koha::CirculationRules->set_rules(
1024
            {
1088
            {
Lines 1033-1039 subtest "CanBookBeRenewed tests" => sub { Link Here
1033
        );
1097
        );
1034
        ( $renewokay, $error ) =
1098
        ( $renewokay, $error ) =
1035
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1099
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1036
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
1100
        is( $renewokay, 1,            'Renew, even if renewal is automatic' );
1037
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
1101
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
1038
1102
1039
        Koha::CirculationRules->set_rules(
1103
        Koha::CirculationRules->set_rules(
Lines 1084-1090 subtest "CanBookBeRenewed tests" => sub { Link Here
1084
        );
1148
        );
1085
        ( $renewokay, $error ) =
1149
        ( $renewokay, $error ) =
1086
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1150
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1087
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1151
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1088
        is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
1152
        is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
1089
    };
1153
    };
1090
1154
Lines 1128-1134 subtest "CanBookBeRenewed tests" => sub { Link Here
1128
        )->status('RETURNED')->store;
1192
        )->status('RETURNED')->store;
1129
        ( $renewokay, $error ) =
1193
        ( $renewokay, $error ) =
1130
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1194
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1131
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1195
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1132
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
1196
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
1133
1197
1134
        $account->add_debit(
1198
        $account->add_debit(
Lines 1142-1148 subtest "CanBookBeRenewed tests" => sub { Link Here
1142
        )->status('RETURNED')->store;
1206
        )->status('RETURNED')->store;
1143
        ( $renewokay, $error ) =
1207
        ( $renewokay, $error ) =
1144
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1208
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1145
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1209
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1146
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
1210
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
1147
1211
1148
        $account->add_debit(
1212
        $account->add_debit(
Lines 1169-1175 subtest "CanBookBeRenewed tests" => sub { Link Here
1169
        )->store;
1233
        )->store;
1170
        ( $renewokay, $error ) =
1234
        ( $renewokay, $error ) =
1171
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1235
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1172
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1236
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1173
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
1237
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
1174
1238
1175
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
1239
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
Lines 1212-1218 subtest "CanBookBeRenewed tests" => sub { Link Here
1212
        my $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1276
        my $issue = AddIssue( $expired_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1213
        ( $renewokay, $error ) =
1277
        ( $renewokay, $error ) =
1214
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1278
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1215
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1279
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1216
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1280
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1217
        Koha::Checkouts->find( $issue->issue_id )->delete;
1281
        Koha::Checkouts->find( $issue->issue_id )->delete;
1218
1282
Lines 1233-1239 subtest "CanBookBeRenewed tests" => sub { Link Here
1233
        $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1297
        $issue = AddIssue( $renewing_borrower_obj->unblessed, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1234
        ( $renewokay, $error ) =
1298
        ( $renewokay, $error ) =
1235
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1299
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1236
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1300
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1237
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1301
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1238
        $issue->delete;
1302
        $issue->delete;
1239
    };
1303
    };
Lines 5848-5862 subtest "GetSoonestRenewDate tests" => sub { Link Here
5848
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
5912
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
5849
    $issue->auto_renew(1)->store;
5913
    $issue->auto_renew(1)->store;
5850
    is(
5914
    is(
5851
        GetSoonestRenewDate( $patron, $issue ),
5915
        GetSoonestRenewDate( $patron, $issue, 1 ),
5852
        $datedue->clone->truncate( to => 'day' ),
5916
        $datedue->clone->truncate( to => 'day' ),
5853
        'Checkouts with auto-renewal can be renewed earliest on due date if no renewalbefore'
5917
        'Checkouts with auto-renewal can be renewed earliest on due date if noautorenewalbefore'
5854
    );
5918
    );
5855
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact' );
5919
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact' );
5856
    is(
5920
    is(
5857
        GetSoonestRenewDate( $patron, $issue ),
5921
        GetSoonestRenewDate( $patron, $issue, 1 ),
5858
        $datedue,
5922
        $datedue,
5859
        'Checkouts with auto-renewal can be renewed earliest on due date if no renewalbefore'
5923
        'Checkouts with auto-renewal can be renewed earliest on due date if noautorenewalbefore'
5860
    );
5924
    );
5861
};
5925
};
5862
5926
5863
- 

Return to bug 25393