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

(-)a/t/db_dependent/Circulation.t (-30 / +93 lines)
Lines 283-289 Koha::CirculationRules->set_rules( Link Here
283
            lengthunit      => 'days',
283
            lengthunit      => 'days',
284
            renewalsallowed => 1,
284
            renewalsallowed => 1,
285
            renewalperiod   => 7,
285
            renewalperiod   => 7,
286
            norenewalbefore => undef,
286
            norenewalbefore     => undef,
287
            noautorenewalbefore => undef,
287
            auto_renew      => 0,
288
            auto_renew      => 0,
288
            fine            => .10,
289
            fine            => .10,
289
            chargeperiod    => 1,
290
            chargeperiod    => 1,
Lines 430-436 subtest "GetIssuingCharges tests" => sub { Link Here
430
431
431
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
432
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
432
subtest "CanBookBeRenewed tests" => sub {
433
subtest "CanBookBeRenewed tests" => sub {
433
    plan tests => 104;
434
    plan tests => 112;
434
435
435
    C4::Context->set_preference('ItemsDeniedRenewal','');
436
    C4::Context->set_preference('ItemsDeniedRenewal','');
436
    # Generate test biblio
437
    # Generate test biblio
Lines 834-840 subtest "CanBookBeRenewed tests" => sub { Link Here
834
835
835
    # Bug 14101
836
    # Bug 14101
836
    # Test automatic renewal before value for "norenewalbefore" in policy is set
837
    # Test automatic renewal before value for "norenewalbefore" in policy is set
837
    # In this case automatic renewal is not permitted prior to due date
838
    # In this case automatic renewal should still be permitted
838
    my $item_4 = $builder->build_sample_item(
839
    my $item_4 = $builder->build_sample_item(
839
        {
840
        {
840
            biblionumber     => $biblio->biblionumber,
841
            biblionumber     => $biblio->biblionumber,
Lines 848-857 subtest "CanBookBeRenewed tests" => sub { Link Here
848
    my $info;
849
    my $info;
849
    ( $renewokay, $error, $info ) =
850
    ( $renewokay, $error, $info ) =
850
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
851
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
851
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
852
    is( $info->{soonest_renew_date}, undef, "soonest_renew_date is not returned because this issue can be renewed" );
852
    is( $error, 'auto_too_soon',
853
    is( $renewokay, 1, 'Bug 25393: Can do a manual renew, even if renewal is automatic and premature' );
853
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
854
    is(
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
        $error, 'auto_renew',
856
        'Bug 25393: Can do a manual renew, even if renewal is automatic and premature, norenewalbefore = undef -> manual renewals are allowed at any time'
857
    );
858
859
    my ( $renewokay_cron, $error_cron, $info_cron ) =
860
        CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
861
    is(
862
        $info_cron->{soonest_renew_date}, dt_from_string( $auto_renew_issue->date_due ),
863
        "Due date is returned as earliest renewal date when the CanBookBeRenewed check is done by cron and error is 'auto_too_soon'"
864
    );
855
    AddReserve(
865
    AddReserve(
856
        {
866
        {
857
            branchcode       => $branch,
867
            branchcode       => $branch,
Lines 911-926 subtest "CanBookBeRenewed tests" => sub { Link Here
911
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
921
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
912
    is( $info->{soonest_renew_date}, dt_from_string($issue_1->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
922
    is( $info->{soonest_renew_date}, dt_from_string($issue_1->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
913
923
914
    # Bug 14101
924
    # Bug 25393
915
    # Test premature automatic renewal
925
    # Test premature automatic renewal
926
    Koha::CirculationRules->set_rule(
927
        {
928
            categorycode => undef,
929
            branchcode   => undef,
930
            itemtype     => undef,
931
            rule_name    => 'noautorenewalbefore',
932
            rule_value   => '7',
933
        }
934
    );
935
916
    ( $renewokay, $error, $info ) =
936
    ( $renewokay, $error, $info ) =
917
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
937
    CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
918
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
938
    is( $renewokay, 0, 'Bug 25393: Cannot renew, renewal is premature' );
919
    is( $error, 'auto_too_soon',
939
    is( $error, 'too_soon',
920
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
940
        'Bug 25393: Cannot renew, renewal is premature (returned code is too_soon)'
921
    );
941
    );
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'");
942
    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
943
944
    ( $renewokay_cron, $error_cron, $info_cron ) =
945
        CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
946
    is(
947
        $error_cron, 'auto_too_soon',
948
        'Bug 25393: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
949
    );
924
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
950
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
925
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
951
    ( $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' );
952
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
Lines 934-942 subtest "CanBookBeRenewed tests" => sub { Link Here
934
    Koha::Cache::Memory::Lite->flush();
960
    Koha::Cache::Memory::Lite->flush();
935
    ( $renewokay, $error, $info ) =
961
    ( $renewokay, $error, $info ) =
936
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
962
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
937
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
963
    is( $renewokay, 0, 'Bug 25393: Cannot manual renew, renewal is too soon' );
964
    is( $error, 'too_soon',
965
        'Bug 25393: Cannot manual renew, renewal is too soon, even though it\'s also scheduled for auto renewal'
966
    );
967
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
968
969
    # Now we test for noautorenewalbefore if cron
970
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '0' WHERE rule_name = 'noautorenewalbefore'});
971
    Koha::Cache::Memory::Lite->flush();
972
    ( $renewokay, $error, $info ) =
973
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
974
    is( $renewokay, 0, 'Bug 25393: Cannot auto renew, renewal is too soon' );
938
    is( $error, 'auto_too_soon',
975
    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)'
976
        'Bug 25393: Cannot auto renew, auto renewal is too soon'
940
    );
977
    );
941
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
978
    is( $info->{soonest_renew_date}, dt_from_string($auto_renew_issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
942
979
Lines 953-970 subtest "CanBookBeRenewed tests" => sub { Link Here
953
    Koha::Cache::Memory::Lite->flush();
990
    Koha::Cache::Memory::Lite->flush();
954
    ( $renewokay, $error ) =
991
    ( $renewokay, $error ) =
955
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
992
      CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
956
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic' );
993
    is( $renewokay, 1, 'Bug 25393: Can do a manual renew, even if renewal is automatic and premature' );
957
    is( $error, 'auto_renew',
994
    is( $error, 'auto_renew',
958
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
995
        'Bug 14101: Cannot renew, renewal is automatic (returned code is auto_renew)'
959
    );
996
    );
960
997
998
    # Now we test for noautorenewalbefore if cron
999
    $dbh->do(q{UPDATE circulation_rules SET rule_value = '99' WHERE rule_name = 'noautorenewalbefore'});
1000
    Koha::Cache::Memory::Lite->flush();
1001
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue, undef, 1 );
1002
    is( $renewokay, 1, 'Bug 25393: Can auto renew' );
1003
    is( $error, 'auto_renew', 'Bug 25393: Can auto renew' );
1004
    is( $info->{soonest_renew_date}, undef, "soonest_renew_date is not returned because this issue can be renewed" );
1005
961
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
1006
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
962
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $auto_renew_issue );
1007
    ( $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' );
1008
    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;
1009
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
965
1010
966
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
1011
    subtest "too_late_renewal / no_auto_renewal_after" => sub {
967
        plan tests => 14;
1012
        plan tests => 16;
968
        my $item_to_auto_renew = $builder->build_sample_item(
1013
        my $item_to_auto_renew = $builder->build_sample_item(
969
            {
1014
            {
970
                biblionumber => $biblio->biblionumber,
1015
                biblionumber => $biblio->biblionumber,
Lines 1021-1028 subtest "CanBookBeRenewed tests" => sub { Link Here
1021
        );
1066
        );
1022
        ( $renewokay, $error ) =
1067
        ( $renewokay, $error ) =
1023
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1068
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1024
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1069
        is( $renewokay, 0, 'Do not renew, too_soon' );
1025
        is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - no_auto_renewal_after is defined(returned code is auto_too_soon)' );
1070
        is( $error, 'too_soon', 'Cannot renew, too_soon - no_auto_renewal_after is defined(returned code is too_soon)' );
1071
1072
        # Now check for cron
1073
        Koha::CirculationRules->set_rules(
1074
            {
1075
                categorycode => undef,
1076
                branchcode   => undef,
1077
                itemtype     => undef,
1078
                rules        => {
1079
                    noautorenewalbefore   => '9',
1080
                    no_auto_renewal_after => '11',
1081
                }
1082
            }
1083
        );
1084
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue, undef, 1 );
1085
        is( $renewokay, 0, 'Do not renew, too_soon' );
1086
        is(
1087
            $error, 'auto_too_soon',
1088
            'Cannot renew, too_soon - no_auto_renewal_after is defined(returned code is too_soon)'
1089
        );
1026
1090
1027
        Koha::CirculationRules->set_rules(
1091
        Koha::CirculationRules->set_rules(
1028
            {
1092
            {
Lines 1037-1043 subtest "CanBookBeRenewed tests" => sub { Link Here
1037
        );
1101
        );
1038
        ( $renewokay, $error ) =
1102
        ( $renewokay, $error ) =
1039
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1103
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1040
        is( $renewokay, 0,            'Do not renew, renewal is automatic' );
1104
        is( $renewokay, 1,            'Renew, even if renewal is automatic' );
1041
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
1105
        is( $error,     'auto_renew', 'Cannot renew, renew is automatic' );
1042
1106
1043
        Koha::CirculationRules->set_rules(
1107
        Koha::CirculationRules->set_rules(
Lines 1088-1094 subtest "CanBookBeRenewed tests" => sub { Link Here
1088
        );
1152
        );
1089
        ( $renewokay, $error ) =
1153
        ( $renewokay, $error ) =
1090
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1154
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1091
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1155
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1092
        is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
1156
        is( $error, 'auto_renew', 'Cannot renew, renew is automatic' );
1093
    };
1157
    };
1094
1158
Lines 1132-1138 subtest "CanBookBeRenewed tests" => sub { Link Here
1132
        )->status('RETURNED')->store;
1196
        )->status('RETURNED')->store;
1133
        ( $renewokay, $error ) =
1197
        ( $renewokay, $error ) =
1134
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1198
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1135
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1199
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1136
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
1200
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 5' );
1137
1201
1138
        $account->add_debit(
1202
        $account->add_debit(
Lines 1146-1152 subtest "CanBookBeRenewed tests" => sub { Link Here
1146
        )->status('RETURNED')->store;
1210
        )->status('RETURNED')->store;
1147
        ( $renewokay, $error ) =
1211
        ( $renewokay, $error ) =
1148
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1212
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1149
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1213
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1150
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
1214
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, patron has 10' );
1151
1215
1152
        $account->add_debit(
1216
        $account->add_debit(
Lines 1173-1179 subtest "CanBookBeRenewed tests" => sub { Link Here
1173
        )->store;
1237
        )->store;
1174
        ( $renewokay, $error ) =
1238
        ( $renewokay, $error ) =
1175
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1239
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1176
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1240
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1177
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
1241
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
1178
1242
1179
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
1243
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
Lines 1216-1222 subtest "CanBookBeRenewed tests" => sub { Link Here
1216
        my $issue = AddIssue( $expired_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1280
        my $issue = AddIssue( $expired_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1217
        ( $renewokay, $error ) =
1281
        ( $renewokay, $error ) =
1218
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1282
          CanBookBeRenewed( $expired_borrower_obj, $issue );
1219
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1283
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1220
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1284
        is( $error, 'auto_renew', 'Can auto renew, patron is expired but BlockExpiredPatronOpacActions=0' );
1221
        Koha::Checkouts->find( $issue->issue_id )->delete;
1285
        Koha::Checkouts->find( $issue->issue_id )->delete;
1222
1286
Lines 1237-1243 subtest "CanBookBeRenewed tests" => sub { Link Here
1237
        $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1301
        $issue = AddIssue( $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
1238
        ( $renewokay, $error ) =
1302
        ( $renewokay, $error ) =
1239
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1303
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1240
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1304
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1241
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1305
        is( $error, 'auto_renew', 'Can auto renew, BlockExpiredPatronOpacActions=1 but patron is not expired' );
1242
        $issue->delete;
1306
        $issue->delete;
1243
    };
1307
    };
Lines 5861-5875 subtest "GetSoonestRenewDate tests" => sub { Link Here
5861
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
5925
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
5862
    $issue->auto_renew(1)->store;
5926
    $issue->auto_renew(1)->store;
5863
    is(
5927
    is(
5864
        GetSoonestRenewDate( $patron, $issue ),
5928
        GetSoonestRenewDate( $patron, $issue, 1 ),
5865
        $datedue->clone->truncate( to => 'day' ),
5929
        $datedue->clone->truncate( to => 'day' ),
5866
        'Checkouts with auto-renewal can be renewed earliest on due date if no renewalbefore'
5930
        'Checkouts with auto-renewal can be renewed earliest on due date if noautorenewalbefore'
5867
    );
5931
    );
5868
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact' );
5932
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'exact' );
5869
    is(
5933
    is(
5870
        GetSoonestRenewDate( $patron, $issue ),
5934
        GetSoonestRenewDate( $patron, $issue, 1 ),
5871
        $datedue,
5935
        $datedue,
5872
        'Checkouts with auto-renewal can be renewed earliest on due date if no renewalbefore'
5936
        'Checkouts with auto-renewal can be renewed earliest on due date if noautorenewalbefore'
5873
    );
5937
    );
5874
5938
5875
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
5939
    t::lib::Mocks::mock_preference( 'NoRenewalBeforePrecision', 'date' );
5876
- 

Return to bug 25393