Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 43; |
22 |
use Test::More tests => 44; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
Lines 1284-1289
subtest 'search_patrons_to_anonymise' => sub {
Link Here
|
1284 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
1284 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
1285 |
}; |
1285 |
}; |
1286 |
|
1286 |
|
|
|
1287 |
subtest 'anonymize items_last_borrower' => sub { |
1288 |
plan tests => 2; |
1289 |
|
1290 |
my $anonymous = $builder->build_object( { class => 'Koha::Patrons', }, ); |
1291 |
|
1292 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->borrowernumber ); |
1293 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', 1 ); |
1294 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrower', 1 ); |
1295 |
|
1296 |
subtest 'anonymize items_last_borrower by days' => sub { |
1297 |
plan tests => 4; |
1298 |
|
1299 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrowerDays', 5 ); |
1300 |
|
1301 |
my $patron = $builder->build_object( |
1302 |
{ |
1303 |
class => 'Koha::Patrons', |
1304 |
value => { privacy => 1, } |
1305 |
} |
1306 |
); |
1307 |
my $item_1 = $builder->build_sample_item; |
1308 |
my $issue_1 = $builder->build_object( |
1309 |
{ |
1310 |
class => 'Koha::Checkouts', |
1311 |
value => { |
1312 |
borrowernumber => $patron->borrowernumber, |
1313 |
itemnumber => $item_1->itemnumber, |
1314 |
}, |
1315 |
} |
1316 |
); |
1317 |
my $item_2 = $builder->build_sample_item; |
1318 |
my $issue_2 = $builder->build_object( |
1319 |
{ |
1320 |
class => 'Koha::Checkouts', |
1321 |
value => { |
1322 |
borrowernumber => $patron->borrowernumber, |
1323 |
itemnumber => $item_2->itemnumber, |
1324 |
}, |
1325 |
} |
1326 |
); |
1327 |
|
1328 |
my $dbh = C4::Context->dbh; |
1329 |
my ($returned_1) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string ); |
1330 |
my ($returned_2) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string ); |
1331 |
is( $returned_1 && $returned_2, 1, 'The items should have been returned' ); |
1332 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber = ?|); |
1333 |
$stu->execute( DateTime->today( time_zone => C4::Context->tz() )->add( days => -6 ), $item_2->itemnumber ); |
1334 |
|
1335 |
my $nb_rows = Koha::Patrons->anonymize_last_borrowers(); |
1336 |
is( $nb_rows, 1, 'anonymize_last_borrowers should have returned the number of last borrowers anonymized' ); |
1337 |
|
1338 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1339 |
$sth->execute( $item_1->itemnumber ); |
1340 |
my ($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
1341 |
is( |
1342 |
$borrowernumber_used_to_anonymize, $patron->borrowernumber, |
1343 |
'Last borrower less than 5 days old are not anonymized' |
1344 |
); |
1345 |
$sth->execute( $item_2->itemnumber ); |
1346 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
1347 |
is( |
1348 |
$borrowernumber_used_to_anonymize, $anonymous->borrowernumber, |
1349 |
'Last borrower older than 5 days are anonymized' |
1350 |
); |
1351 |
|
1352 |
}; |
1353 |
|
1354 |
subtest 'withrawn, lost and damaged items' => sub { |
1355 |
plan tests => 6; |
1356 |
|
1357 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrowerDays', 0 ); |
1358 |
|
1359 |
my $patron = $builder->build_object( |
1360 |
{ |
1361 |
class => 'Koha::Patrons', |
1362 |
value => { privacy => 1, } |
1363 |
} |
1364 |
); |
1365 |
my $item_1 = $builder->build_sample_item; |
1366 |
my $issue_1 = $builder->build_object( |
1367 |
{ |
1368 |
class => 'Koha::Checkouts', |
1369 |
value => { |
1370 |
borrowernumber => $patron->borrowernumber, |
1371 |
itemnumber => $item_1->itemnumber, |
1372 |
}, |
1373 |
} |
1374 |
); |
1375 |
my $item_2 = $builder->build_sample_item; |
1376 |
my $issue_2 = $builder->build_object( |
1377 |
{ |
1378 |
class => 'Koha::Checkouts', |
1379 |
value => { |
1380 |
borrowernumber => $patron->borrowernumber, |
1381 |
itemnumber => $item_2->itemnumber, |
1382 |
}, |
1383 |
} |
1384 |
); |
1385 |
my $item_3 = $builder->build_sample_item; |
1386 |
my $issue_3 = $builder->build_object( |
1387 |
{ |
1388 |
class => 'Koha::Checkouts', |
1389 |
value => { |
1390 |
borrowernumber => $patron->borrowernumber, |
1391 |
itemnumber => $item_3->itemnumber, |
1392 |
}, |
1393 |
} |
1394 |
); |
1395 |
my $item_4 = $builder->build_sample_item; |
1396 |
my $issue_4 = $builder->build_object( |
1397 |
{ |
1398 |
class => 'Koha::Checkouts', |
1399 |
value => { |
1400 |
borrowernumber => $patron->borrowernumber, |
1401 |
itemnumber => $item_4->itemnumber, |
1402 |
}, |
1403 |
} |
1404 |
); |
1405 |
|
1406 |
my ($returned_1) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1407 |
my ($returned_2) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1408 |
my ($returned_3) = C4::Circulation::AddReturn( $item_3->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1409 |
my ($returned_4) = C4::Circulation::AddReturn( $item_4->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1410 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
1411 |
$item_1->withdrawn(1)->store; |
1412 |
$item_2->itemlost(1)->store; |
1413 |
$item_3->damaged(1)->store; |
1414 |
|
1415 |
my $dbh = C4::Context->dbh; |
1416 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber in (?, ?, ?, ?)|); |
1417 |
$stu->execute( |
1418 |
DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 ), $item_1->itemnumber, |
1419 |
$item_2->itemnumber, $item_3->itemnumber, $item_4->itemnumber |
1420 |
); |
1421 |
|
1422 |
my $nb_rows = Koha::Patrons->anonymize_last_borrowers(); |
1423 |
is( $nb_rows, 1, 'anonymise_last_borrowers should have returned the number of last borrowers anonymized' ); |
1424 |
|
1425 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1426 |
$sth->execute( $item_1->itemnumber ); |
1427 |
my ($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
1428 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'withrawn items should not be anonymized' ); |
1429 |
$sth->execute( $item_2->itemnumber ); |
1430 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
1431 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'lost items should not be anonymized' ); |
1432 |
$sth->execute( $item_3->itemnumber ); |
1433 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
1434 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'damaged items should not be anonymized' ); |
1435 |
$sth->execute( $item_4->itemnumber ); |
1436 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
1437 |
is( |
1438 |
$borrowernumber_used_to_anonymize, $anonymous->borrowernumber, |
1439 |
'not withdrawn, lost or damaged items are anonymized' |
1440 |
); |
1441 |
|
1442 |
}; |
1443 |
|
1444 |
}; |
1445 |
|
1287 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
1446 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
1288 |
plan tests => 3; |
1447 |
plan tests => 3; |
1289 |
|
1448 |
|
1290 |
- |
|
|