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

(-)a/Koha/Patron.pm (-1 / +1 lines)
Lines 298-304 sub is_going_to_expired { Link Here
298
    return 0 unless $delay;
298
    return 0 unless $delay;
299
    return 0 unless $self->dateexpiry;
299
    return 0 unless $self->dateexpiry;
300
    return 0 if $self->dateexpiry eq '0000-00-00';
300
    return 0 if $self->dateexpiry eq '0000-00-00';
301
    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->truncate( to => 'day' );
302
    return 0;
302
    return 0;
303
}
303
}
304
304
(-)a/t/db_dependent/Koha/Patrons.t (-10 / +9 lines)
Lines 187-222 subtest 'is_going_to_expired' => sub { Link Here
187
    plan tests => 9;
187
    plan tests => 9;
188
    my $patron = $builder->build({ source => 'Borrower' });
188
    my $patron = $builder->build({ source => 'Borrower' });
189
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
189
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
190
    $patron->dateexpiry( undef )->store;
190
    $patron->dateexpiry( undef )->store->discard_changes;
191
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
191
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
192
    $patron->dateexpiry( '0000-00-00' )->store;
192
    $patron->dateexpiry( '0000-00-00' )->store->discard_changes;
193
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
193
    is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
194
    $patron->dateexpiry( dt_from_string )->store;
194
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
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
    $patron->dateexpiry( dt_from_string )->store;
198
    $patron->dateexpiry( dt_from_string )->store->discard_changes;
199
    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');
200
200
201
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
201
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
202
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
202
    $patron->dateexpiry( dt_from_string->add( days => 11 ) )->store->discard_changes;
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');
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');
204
204
205
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
205
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
206
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
206
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
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');
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');
208
208
209
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
209
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
210
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
210
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
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');
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');
212
    $patron->delete;
212
    $patron->delete;
213
213
214
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
214
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
215
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
215
    $patron->dateexpiry( dt_from_string->add( days => 20 ) )->store->discard_changes;
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');
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');
217
217
218
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
218
    t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
219
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
219
    $patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
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');
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');
221
221
222
    $patron->delete;
222
    $patron->delete;
223
- 

Return to bug 17583