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

(-)a/t/db_dependent/Members.t (-2 / +129 lines)
Lines 17-27 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 59;
20
use Test::More tests => 76;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Data::Dumper;
22
use Data::Dumper;
23
use C4::Context;
23
use C4::Context;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::List::Patron;
26
25
27
26
use t::lib::Mocks;
28
use t::lib::Mocks;
27
use t::lib::TestBuilder;
29
use t::lib::TestBuilder;
Lines 229-234 $borrowernumber = AddMember( %data ); Link Here
229
$borrower = GetMember( borrowernumber => $borrowernumber );
231
$borrower = GetMember( borrowernumber => $borrowernumber );
230
is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given userid' );
232
is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given userid' );
231
233
234
#Regression tests for bug 10612
235
my $library3 = $builder->build({
236
    source => 'Branch',
237
});
238
$builder->build({
239
        source => 'Category',
240
        value => {
241
            categorycode         => 'STAFFER',
242
            description          => 'Staff dont batch del',
243
            category_type        => 'S',
244
        },
245
});
246
247
$builder->build({
248
        source => 'Category',
249
        value => {
250
            categorycode         => 'CIVILIAN',
251
            description          => 'Civilian batch del',
252
            category_type        => 'A',
253
        },
254
});
255
256
$builder->build({
257
        source => 'Category',
258
        value => {
259
            categorycode         => 'KIDclamp',
260
            description          => 'Kid to be guaranteed',
261
            category_type        => 'C',
262
        },
263
});
264
265
#$builder->clear( { source => 'Borrower' } );
266
my $borrower1 = $builder->build({
267
        source => 'Borrower',
268
        value  => {
269
            categorycode=>'STAFFER',
270
            branchcode => $library3->{branchcode},
271
            dateexpiry => '2015-01-01',
272
        },
273
});
274
my $bor1inlist = $borrower1->{borrowernumber};
275
my $borrower2 = $builder->build({
276
        source => 'Borrower',
277
        value  => {
278
            categorycode=>'STAFFER',
279
            branchcode => $library3->{branchcode},
280
            dateexpiry => '2015-01-01',
281
        },
282
});
283
284
my $guarantee = $builder->build({
285
        source => 'Borrower',
286
        value  => {
287
            categorycode=>'KIDclamp',
288
            branchcode => $library3->{branchcode},
289
            dateexpiry => '2015-01-01',
290
        },
291
});
292
293
my $bor2inlist = $borrower2->{borrowernumber};
294
295
$builder->build({
296
        source => 'OldIssue',
297
        value  => {
298
            borrowernumber => $bor2inlist,
299
            timestamp => '2016-01-01',
300
        },
301
});
302
303
my $owner = AddMember (categorycode => 'STAFFER', branchcode => $library2->{branchcode} );
304
my $list1 = AddPatronList( { name => 'Test List 1', owner => $owner } );
305
my @listpatrons = ($bor1inlist, $bor2inlist);
306
AddPatronsToList(  { list => $list1, borrowernumbers => \@listpatrons });
307
my $patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id() } );
308
is( scalar(@$patstodel),0,'No staff deleted from list of all staff');
309
ModMember( borrowernumber => $bor2inlist, categorycode => 'CIVILIAN' );
310
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
311
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted from list');
312
$patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
313
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by branchcode and list');
314
$patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02', patron_list_id => $list1->patron_list_id() } );
315
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by expirationdate and list');
316
$patstodel = GetBorrowersToExpunge( {not_borrowered_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
317
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Staff patron not deleted by last issue date');
318
319
ModMember( borrowernumber => $bor1inlist, categorycode => 'CIVILIAN' );
320
ModMember( borrowernumber => $guarantee->{borrowernumber} ,guarantorid=>$bor1inlist );
321
322
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
323
ok( scalar(@$patstodel)== 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted from list');
324
$patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
325
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by branchcode and list');
326
$patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02', patron_list_id => $list1->patron_list_id() } );
327
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by expirationdate and list');
328
$patstodel = GetBorrowersToExpunge( {not_borrowered_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
329
ok( scalar(@$patstodel) == 1 && $patstodel->[0]->{'borrowernumber'} eq $bor2inlist,'Guarantor patron not deleted by last issue date');
330
ModMember( borrowernumber => $guarantee->{borrowernumber}, guarantorid=>'' );
331
332
$builder->build({
333
        source => 'Issue',
334
        value  => {
335
            borrowernumber => $bor2inlist,
336
        },
337
});
338
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
339
is( scalar(@$patstodel),1,'Borrower with issue not deleted from list');
340
$patstodel = GetBorrowersToExpunge( {branchcode => $library3->{branchcode},patron_list_id => $list1->patron_list_id() } );
341
is( scalar(@$patstodel),1,'Borrower with issue not deleted by branchcode and list');
342
$patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } );
343
is( scalar(@$patstodel),1,'Borrower with issue not deleted by category_code and list');
344
$patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } );
345
is( scalar(@$patstodel),1,'Borrower with issue not deleted by expiration_date and list');
346
$builder->clear( { source => 'Issue' } );
347
$patstodel = GetBorrowersToExpunge( {patron_list_id => $list1->patron_list_id()} );
348
ok( scalar(@$patstodel)== 2,'Borrowers without issue deleted from list');
349
$patstodel = GetBorrowersToExpunge( {category_code => 'CIVILIAN',patron_list_id => $list1->patron_list_id() } );
350
is( scalar(@$patstodel),2,'Borrowers without issues deleted by category_code and list');
351
$patstodel = GetBorrowersToExpunge( {expired_before => '2015-01-02',patron_list_id => $list1->patron_list_id() } );
352
is( scalar(@$patstodel),2,'Borrowers without issues deleted by expiration_date and list');
353
$patstodel = GetBorrowersToExpunge( {not_borrowered_since => '2016-01-02', patron_list_id => $list1->patron_list_id() } );
354
is( scalar(@$patstodel),2,'Borrowers without issues deleted by last issue date');
355
356
357
358
359
232
# Regression tests for BZ13502
360
# Regression tests for BZ13502
233
## Remove all entries with userid='' (should be only 1 max)
361
## Remove all entries with userid='' (should be only 1 max)
234
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
362
$dbh->do(q|DELETE FROM borrowers WHERE userid = ''|);
235
- 

Return to bug 10612