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

(-)a/t/db_dependent/Members.t (-6 / +59 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 47;
20
use Test::More tests => 50;
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 306-327 is( scalar(@$patstodel),2,'Borrowers without issues deleted by last issue date') Link Here
306
309
307
# Test GetBorrowersToExpunge and TrackLastPatronActivity
310
# Test GetBorrowersToExpunge and TrackLastPatronActivity
308
$dbh->do(q|UPDATE borrowers SET lastseen=NULL|);
311
$dbh->do(q|UPDATE borrowers SET lastseen=NULL|);
309
$builder->build({ source => 'Borrower', value => { lastseen => '2016-01-01 01:01:01', categorycode => 'CIVILIAN' } } );
312
$builder->build({ 
310
$builder->build({ source => 'Borrower', value => { lastseen => '2016-02-02 02:02:02', categorycode => 'CIVILIAN' } } );
313
    source => 'Borrower',
311
$builder->build({ source => 'Borrower', value => { lastseen => '2016-03-03 03:03:03', categorycode => 'CIVILIAN' } } );
314
    value => {
315
        lastseen => '2016-01-01 01:01:01',
316
        categorycode => 'CIVILIAN',
317
        flags => undef,
318
    }
319
});
320
$builder->build({
321
    source => 'Borrower',
322
    value => {
323
        lastseen => '2016-02-02 02:02:02',
324
        categorycode => 'CIVILIAN',
325
        flags => undef,
326
    }
327
});
328
$builder->build({
329
    source => 'Borrower',
330
    value => {
331
        lastseen => '2016-03-03 03:03:03',
332
        categorycode => 'CIVILIAN',
333
        flags => undef,
334
    }
335
});
312
$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' });
336
$patstodel = GetBorrowersToExpunge( { last_seen => '1999-12-12' });
313
is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' );
337
is( scalar @$patstodel, 0, 'TrackLastPatronActivity - 0 patrons must be deleted' );
314
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' });
338
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-02-15' });
315
is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' );
339
is( scalar @$patstodel, 2, 'TrackLastPatronActivity - 2 patrons must be deleted' );
316
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' });
340
$patstodel = GetBorrowersToExpunge( { last_seen => '2016-04-04' });
317
is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' );
341
is( scalar @$patstodel, 3, 'TrackLastPatronActivity - 3 patrons must be deleted' );
318
my $patron2 = $builder->build({ source => 'Borrower', value => { lastseen => undef } });
342
my $patron2 = $builder->build({
343
    source => 'Borrower',
344
    value => {
345
        lastseen => undef,
346
        flags => undef,
347
    }
348
});
319
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' );
349
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' );
320
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login;
350
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login;
321
is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should not be changed' );
351
is( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should not be changed' );
322
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 });
352
Koha::Patrons->find( $patron2->{borrowernumber} )->track_login({ force => 1 });
323
isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should be changed now' );
353
isnt( Koha::Patrons->find( $patron2->{borrowernumber} )->lastseen, undef, 'Lastseen should be changed now' );
324
354
355
# Test GetBorrowersToExpunge and regular patron with permission
356
$builder->build({
357
        source => 'Category',
358
        value => {
359
            categorycode         => 'SMALLSTAFF',
360
            description          => 'Small staff',
361
            category_type        => 'A',
362
        },
363
});
364
$borrowernumber = Koha::Patron->new({
365
    categorycode => 'SMALLSTAFF',
366
    branchcode => $library2->{branchcode},
367
    flags => undef,
368
})->store->borrowernumber;
369
$patron = Koha::Patrons->find( $borrowernumber );
370
$patstodel = GetBorrowersToExpunge( {category_code => 'SMALLSTAFF' } );
371
is( scalar @$patstodel, 1, 'Regular patron with flags=undef can be deleted' );
372
$patron->set({ flags => 0 })->store;
373
$patstodel = GetBorrowersToExpunge( {category_code => 'SMALLSTAFF' } );
374
is( scalar @$patstodel, 1, 'Regular patron with flags=0 can be deleted' );
375
$patron->set({ flags => 4 })->store;
376
$patstodel = GetBorrowersToExpunge( {category_code => 'SMALLSTAFF' } );
377
is( scalar @$patstodel, 0, 'Regular patron with flags>0 can not be deleted' );
378
325
# Regression tests for BZ13502
379
# Regression tests for BZ13502
326
## Remove all entries with userid='' (should be only 1 max)
380
## Remove all entries with userid='' (should be only 1 max)
327
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
381
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
328
- 

Return to bug 26517