Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 50; |
20 |
use Test::More tests => 53; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Exception; |
22 |
use Test::Exception; |
23 |
|
23 |
|
Lines 213-218
my $borrower1 = $builder->build({
Link Here
|
213 |
categorycode=>'STAFFER', |
213 |
categorycode=>'STAFFER', |
214 |
branchcode => $library3->{branchcode}, |
214 |
branchcode => $library3->{branchcode}, |
215 |
dateexpiry => '2015-01-01', |
215 |
dateexpiry => '2015-01-01', |
|
|
216 |
flags => undef, |
216 |
}, |
217 |
}, |
217 |
}); |
218 |
}); |
218 |
my $bor1inlist = $borrower1->{borrowernumber}; |
219 |
my $bor1inlist = $borrower1->{borrowernumber}; |
Lines 222-227
my $borrower2 = $builder->build({
Link Here
|
222 |
categorycode=>'STAFFER', |
223 |
categorycode=>'STAFFER', |
223 |
branchcode => $library3->{branchcode}, |
224 |
branchcode => $library3->{branchcode}, |
224 |
dateexpiry => '2015-01-01', |
225 |
dateexpiry => '2015-01-01', |
|
|
226 |
flags => undef, |
225 |
}, |
227 |
}, |
226 |
}); |
228 |
}); |
227 |
|
229 |
|
Lines 231-236
my $guarantee = $builder->build({
Link Here
|
231 |
categorycode=>'KIDclamp', |
233 |
categorycode=>'KIDclamp', |
232 |
branchcode => $library3->{branchcode}, |
234 |
branchcode => $library3->{branchcode}, |
233 |
dateexpiry => '2015-01-01', |
235 |
dateexpiry => '2015-01-01', |
|
|
236 |
flags => undef, |
234 |
}, |
237 |
}, |
235 |
}); |
238 |
}); |
236 |
|
239 |
|
Lines 318-339
is( scalar(@$patstodel),2,'Borrowers without issues deleted by last issue date')
Link Here
|
318 |
|
321 |
|
319 |
# Test GetBorrowersToExpunge and TrackLastPatronActivity |
322 |
# Test GetBorrowersToExpunge and TrackLastPatronActivity |
320 |
$dbh->do(q|UPDATE borrowers SET lastseen=NULL|); |
323 |
$dbh->do(q|UPDATE borrowers SET lastseen=NULL|); |
321 |
$builder->build({ source => 'Borrower', value => { lastseen => '2016-01-01 01:01:01', categorycode => 'CIVILIAN' } } ); |
324 |
$builder->build({ |
322 |
$builder->build({ source => 'Borrower', value => { lastseen => '2016-02-02 02:02:02', categorycode => 'CIVILIAN' } } ); |
325 |
source => 'Borrower', |
323 |
$builder->build({ source => 'Borrower', value => { lastseen => '2016-03-03 03:03:03', categorycode => 'CIVILIAN' } } ); |
326 |
value => { |
|
|
327 |
lastseen => '2016-01-01 01:01:01', |
328 |
categorycode => 'CIVILIAN', |
329 |
flags => undef, |
330 |
} |
331 |
}); |
332 |
$builder->build({ |
333 |
source => 'Borrower', |
334 |
value => { |
335 |
lastseen => '2016-02-02 02:02:02', |
336 |
categorycode => 'CIVILIAN', |
337 |
flags => undef, |
338 |
} |
339 |
}); |
340 |
$builder->build({ |
341 |
source => 'Borrower', |
342 |
value => { |
343 |
lastseen => '2016-03-03 03:03:03', |
344 |
categorycode => 'CIVILIAN', |
345 |
flags => undef, |
346 |
} |
347 |
}); |
324 |
$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' }); |
348 |
$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' }); |
325 |
is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' ); |
349 |
is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' ); |
326 |
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' }); |
350 |
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' }); |
327 |
is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' ); |
351 |
is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' ); |
328 |
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' }); |
352 |
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' }); |
329 |
is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' ); |
353 |
is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' ); |
330 |
my $patron2 = $builder->build({ source => 'Borrower', value => { lastseen => undef } }); |
354 |
my $patron2 = $builder->build({ |
|
|
355 |
source => 'Borrower', |
356 |
value => { |
357 |
lastseen => undef, |
358 |
flags => undef, |
359 |
} |
360 |
}); |
331 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
361 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
332 |
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login; |
362 |
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login; |
333 |
is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should not be changed' ); |
363 |
is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should not be changed' ); |
334 |
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 }); |
364 |
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 }); |
335 |
isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should be changed now' ); |
365 |
isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should be changed now' ); |
336 |
|
366 |
|
|
|
367 |
# Test GetBorrowersToExpunge and regular patron with permission |
368 |
$builder->build({ |
369 |
source => 'Category', |
370 |
value => { |
371 |
categorycode => 'SMALLSTAFF', |
372 |
description => 'Small staff', |
373 |
category_type => 'A', |
374 |
}, |
375 |
}); |
376 |
$borrowernumber = Koha::Patron->new({ |
377 |
categorycode => 'SMALLSTAFF', |
378 |
branchcode => $library2->{branchcode}, |
379 |
flags => undef, |
380 |
})->store->borrowernumber; |
381 |
$patron = Koha::Patrons->find( $borrowernumber ); |
382 |
$patstodel = GetBorrowersToExpunge( {category_code => 'SMALLSTAFF' } ); |
383 |
is( scalar @$patstodel, 1, 'Regular patron with flags=undef can be deleted' ); |
384 |
$patron->set({ flags => 0 })->store; |
385 |
$patstodel = GetBorrowersToExpunge( {category_code => 'SMALLSTAFF' } ); |
386 |
is( scalar @$patstodel, 1, 'Regular patron with flags=0 can be deleted' ); |
387 |
$patron->set({ flags => 4 })->store; |
388 |
$patstodel = GetBorrowersToExpunge( {category_code => 'SMALLSTAFF' } ); |
389 |
is( scalar @$patstodel, 0, 'Regular patron with flags>0 can not be deleted' ); |
390 |
|
337 |
# Regression tests for BZ13502 |
391 |
# Regression tests for BZ13502 |
338 |
## Remove all entries with userid='' (should be only 1 max) |
392 |
## Remove all entries with userid='' (should be only 1 max) |
339 |
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|); |
393 |
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|); |
340 |
- |
|
|