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

(-)a/Koha/Patron.pm (-1 / +1 lines)
Lines 311-317 sub is_going_to_expired { Link Here
311
    return 0 unless $delay;
311
    return 0 unless $delay;
312
    return 0 unless $self->dateexpiry;
312
    return 0 unless $self->dateexpiry;
313
    return 0 if $self->dateexpiry eq '0000-00-00';
313
    return 0 if $self->dateexpiry eq '0000-00-00';
314
    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->truncate( to => 'day' );
315
    return 0;
315
    return 0;
316
}
316
}
317
317
(-)a/t/db_dependent/Koha/Patrons.t (-10 / +9 lines)
Lines 194-229 subtest 'is_going_to_expired' => sub { Link Here
194
    plan tests => 9;
194
    plan tests => 9;
195
    my $patron = $builder->build({ source => 'Borrower' });
195
    my $patron = $builder->build({ source => 'Borrower' });
196
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
196
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
197
    $patron->dateexpiry( undef )->store;
197
    $patron->dateexpiry( undef )->store->discard_changes;
198
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
198
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
199
    $patron->dateexpiry( '0000-00-00' )->store;
199
    $patron->dateexpiry( '0000-00-00' )->store->discard_changes;
200
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
200
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
201
    $patron->dateexpiry( dt_from_string )->store;
201
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
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
    $patron->dateexpiry( dt_from_string )->store;
205
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
206
    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');
207
207
208
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
208
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
209
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
209
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store->discard_changes;
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');
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');
211
211
212
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
212
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
213
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
213
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
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');
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');
215
215
216
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
216
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
217
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
217
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
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');
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');
219
    $patron->delete;
219
    $patron->delete;
220
220
221
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
221
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
222
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
222
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store->discard_changes;
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');
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');
224
224
225
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
225
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
226
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
226
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
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');
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');
228
228
229
    $patron->delete;
229
    $patron->delete;
230
- 

Return to bug 17583