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

(-)a/Koha/Patron.pm (-1 / +2 lines)
Lines 308-316 sub is_going_to_expired { Link Here
308
308
309
    my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0;
309
    my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0;
310
310
311
    return 0 unless $delay;
311
    return 0 unless $self->dateexpiry;
312
    return 0 unless $self->dateexpiry;
312
    return 0 if $self->dateexpiry eq '0000-00-00';
313
    return 0 if $self->dateexpiry eq '0000-00-00';
313
    return 1 if dt_from_string( $self->dateexpiry )->add( days => $delay ) < dt_from_string;
314
    return 1 if dt_from_string( $self->dateexpiry )->add( days => -$delay ) < dt_from_string;
314
    return 0;
315
    return 0;
315
}
316
}
316
317
(-)a/t/db_dependent/Koha/Patrons.t (-8 / +6 lines)
Lines 202-231 subtest 'is_going_to_expired' => sub { Link Here
202
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today');
202
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today');
203
203
204
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
204
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
205
    my $dt_from_string = dt_from_string;
205
    $patron->dateexpiry( dt_from_string )->store;
206
    $patron->dateexpiry( $dt_from_string )->store;
207
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
206
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
208
207
209
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
208
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
210
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
209
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
211
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days before and pref is 10');
210
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days ahead and pref is 10');
212
211
213
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
212
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
214
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
213
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
215
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days before and pref is 0');
214
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 0');
216
215
217
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
216
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
218
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
217
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
219
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days before and pref is 10');
218
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 10');
220
    $patron->delete;
219
    $patron->delete;
221
220
222
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
221
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
223
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
222
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
224
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days before and pref is 10');
223
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days ahead and pref is 10');
225
224
226
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
225
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
227
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
226
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
228
    is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days before and pref is 20');
227
    is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20');
229
228
230
    $patron->delete;
229
    $patron->delete;
231
};
230
};
232
- 

Return to bug 17583