Lines 191-226
subtest 'is_going_to_expired' => sub {
Link Here
|
191 |
plan tests => 9; |
191 |
plan tests => 9; |
192 |
my $patron = $builder->build({ source => 'Borrower' }); |
192 |
my $patron = $builder->build({ source => 'Borrower' }); |
193 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
193 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
194 |
$patron->dateexpiry( undef )->store; |
194 |
$patron->dateexpiry( undef )->store->discard_changes; |
195 |
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set'); |
195 |
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set'); |
196 |
$patron->dateexpiry( '0000-00-00' )->store; |
196 |
$patron->dateexpiry( '0000-00-00' )->store->discard_changes; |
197 |
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00'); |
197 |
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00'); |
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'); |
199 |
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today'); |
200 |
|
200 |
|
201 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
201 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
202 |
$patron->dateexpiry( dt_from_string )->store; |
202 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
203 |
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0'); |
203 |
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0'); |
204 |
|
204 |
|
205 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
205 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
206 |
$patron->dateexpiry( dt_from_string->add( days => 11 ) )->store; |
206 |
$patron->dateexpiry( dt_from_string->add( days => 11 ) )->store->discard_changes; |
207 |
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'); |
207 |
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'); |
208 |
|
208 |
|
209 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
209 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
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 0'); |
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 0'); |
212 |
|
212 |
|
213 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
213 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
214 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store; |
214 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes; |
215 |
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'); |
215 |
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'); |
216 |
$patron->delete; |
216 |
$patron->delete; |
217 |
|
217 |
|
218 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
218 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
219 |
$patron->dateexpiry( dt_from_string->add( days => 20 ) )->store; |
219 |
$patron->dateexpiry( dt_from_string->add( days => 20 ) )->store->discard_changes; |
220 |
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'); |
220 |
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'); |
221 |
|
221 |
|
222 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20); |
222 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20); |
223 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store; |
223 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes; |
224 |
is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20'); |
224 |
is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20'); |
225 |
|
225 |
|
226 |
$patron->delete; |
226 |
$patron->delete; |
227 |
- |
|
|