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

(-)a/Koha/Patron.pm (-1 / +2 lines)
Lines 295-303 sub is_going_to_expired { Link Here
295
295
296
    my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0;
296
    my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0;
297
297
298
    return 0 unless $delay;
298
    return 0 unless $self->dateexpiry;
299
    return 0 unless $self->dateexpiry;
299
    return 0 if $self->dateexpiry eq '0000-00-00';
300
    return 0 if $self->dateexpiry eq '0000-00-00';
300
    return 1 if dt_from_string( $self->dateexpiry )->add( days => $delay ) < dt_from_string;
301
    return 1 if dt_from_string( $self->dateexpiry )->add( days => -$delay ) < dt_from_string;
301
    return 0;
302
    return 0;
302
}
303
}
303
304
(-)a/t/db_dependent/Koha/Patrons.t (-8 / +6 lines)
Lines 195-224 subtest 'is_going_to_expired' => sub { Link Here
195
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today');
195
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today');
196
196
197
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
197
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
198
    my $dt_from_string = dt_from_string;
198
    $patron->dateexpiry( dt_from_string )->store;
199
    $patron->dateexpiry( $dt_from_string )->store;
200
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
199
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
201
200
202
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
201
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
203
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
202
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
204
    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');
203
    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');
205
204
206
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
205
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
207
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
206
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
208
    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');
207
    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');
209
208
210
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
209
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
211
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
210
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
212
    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');
211
    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');
213
    $patron->delete;
212
    $patron->delete;
214
213
215
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
214
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
216
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
215
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
217
    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');
216
    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');
218
217
219
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
218
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
220
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
219
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
221
    is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days before and pref is 20');
220
    is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20');
222
221
223
    $patron->delete;
222
    $patron->delete;
224
};
223
};
225
- 

Return to bug 17583