Lines 1289-1302
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1289 |
|
1289 |
|
1290 |
my $anonymous = $builder->build_object( { class => 'Koha::Patrons', }, ); |
1290 |
my $anonymous = $builder->build_object( { class => 'Koha::Patrons', }, ); |
1291 |
|
1291 |
|
1292 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->borrowernumber ); |
1292 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->borrowernumber ); |
1293 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
1293 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', 1 ); |
1294 |
t::lib::Mocks::mock_preference('AnonymiseLastBorrower', 1); |
1294 |
t::lib::Mocks::mock_preference( 'AnonymiseLastBorrower', 1 ); |
1295 |
|
1295 |
|
1296 |
subtest 'anonymise items_last_borrower by days' => sub { |
1296 |
subtest 'anonymise items_last_borrower by days' => sub { |
1297 |
plan tests => 4; |
1297 |
plan tests => 4; |
1298 |
|
1298 |
|
1299 |
t::lib::Mocks::mock_preference('AnonymiseLastBorrowerDays', 5); |
1299 |
t::lib::Mocks::mock_preference( 'AnonymiseLastBorrowerDays', 5 ); |
1300 |
|
1300 |
|
1301 |
my $patron = $builder->build_object( |
1301 |
my $patron = $builder->build_object( |
1302 |
{ |
1302 |
{ |
Lines 1304-1310
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1304 |
value => { privacy => 1, } |
1304 |
value => { privacy => 1, } |
1305 |
} |
1305 |
} |
1306 |
); |
1306 |
); |
1307 |
my $item_1 = $builder->build_sample_item; |
1307 |
my $item_1 = $builder->build_sample_item; |
1308 |
my $issue_1 = $builder->build_object( |
1308 |
my $issue_1 = $builder->build_object( |
1309 |
{ |
1309 |
{ |
1310 |
class => 'Koha::Checkouts', |
1310 |
class => 'Koha::Checkouts', |
Lines 1314-1320
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1314 |
}, |
1314 |
}, |
1315 |
} |
1315 |
} |
1316 |
); |
1316 |
); |
1317 |
my $item_2 = $builder->build_sample_item; |
1317 |
my $item_2 = $builder->build_sample_item; |
1318 |
my $issue_2 = $builder->build_object( |
1318 |
my $issue_2 = $builder->build_object( |
1319 |
{ |
1319 |
{ |
1320 |
class => 'Koha::Checkouts', |
1320 |
class => 'Koha::Checkouts', |
Lines 1326-1354
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1326 |
); |
1326 |
); |
1327 |
|
1327 |
|
1328 |
my $dbh = C4::Context->dbh; |
1328 |
my $dbh = C4::Context->dbh; |
1329 |
my ( $returned_1 ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string ); |
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 ); |
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' ); |
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 = ?|); |
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); |
1333 |
$stu->execute( DateTime->today( time_zone => C4::Context->tz() )->add( days => -6 ), $item_2->itemnumber ); |
1334 |
|
1334 |
|
1335 |
my $nb_rows = Koha::Patrons->anonymise_last_borrowers(); |
1335 |
my $nb_rows = Koha::Patrons->anonymise_last_borrowers(); |
1336 |
is( $nb_rows, 1, 'anonymise_issue_history should have returned the number of last borrowers anonymised'); |
1336 |
is( $nb_rows, 1, 'anonymise_issue_history should have returned the number of last borrowers anonymised' ); |
1337 |
|
1337 |
|
1338 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1338 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1339 |
$sth->execute($item_1->itemnumber); |
1339 |
$sth->execute( $item_1->itemnumber ); |
1340 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1340 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1341 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'Last borrower younger than 5 days are not anonymised' ); |
1341 |
is( |
1342 |
$sth->execute($item_2->itemnumber); |
1342 |
$borrowernumber_used_to_anonymised, $patron->borrowernumber, |
|
|
1343 |
'Last borrower younger than 5 days are not anonymised' |
1344 |
); |
1345 |
$sth->execute( $item_2->itemnumber ); |
1343 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1346 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1344 |
is( $borrowernumber_used_to_anonymised, $anonymous->borrowernumber, 'Last borrower older than 5 days are anonymised' ); |
1347 |
is( |
|
|
1348 |
$borrowernumber_used_to_anonymised, $anonymous->borrowernumber, |
1349 |
'Last borrower older than 5 days are anonymised' |
1350 |
); |
1345 |
|
1351 |
|
1346 |
}; |
1352 |
}; |
1347 |
|
1353 |
|
1348 |
subtest 'withrawn, lost and damaged items' => sub { |
1354 |
subtest 'withrawn, lost and damaged items' => sub { |
1349 |
plan tests => 6; |
1355 |
plan tests => 6; |
1350 |
|
1356 |
|
1351 |
t::lib::Mocks::mock_preference('AnonymiseLastBorrowerDays', 0); |
1357 |
t::lib::Mocks::mock_preference( 'AnonymiseLastBorrowerDays', 0 ); |
1352 |
|
1358 |
|
1353 |
my $patron = $builder->build_object( |
1359 |
my $patron = $builder->build_object( |
1354 |
{ |
1360 |
{ |
Lines 1356-1362
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1356 |
value => { privacy => 1, } |
1362 |
value => { privacy => 1, } |
1357 |
} |
1363 |
} |
1358 |
); |
1364 |
); |
1359 |
my $item_1 = $builder->build_sample_item; |
1365 |
my $item_1 = $builder->build_sample_item; |
1360 |
my $issue_1 = $builder->build_object( |
1366 |
my $issue_1 = $builder->build_object( |
1361 |
{ |
1367 |
{ |
1362 |
class => 'Koha::Checkouts', |
1368 |
class => 'Koha::Checkouts', |
Lines 1366-1372
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1366 |
}, |
1372 |
}, |
1367 |
} |
1373 |
} |
1368 |
); |
1374 |
); |
1369 |
my $item_2 = $builder->build_sample_item; |
1375 |
my $item_2 = $builder->build_sample_item; |
1370 |
my $issue_2 = $builder->build_object( |
1376 |
my $issue_2 = $builder->build_object( |
1371 |
{ |
1377 |
{ |
1372 |
class => 'Koha::Checkouts', |
1378 |
class => 'Koha::Checkouts', |
Lines 1376-1382
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1376 |
}, |
1382 |
}, |
1377 |
} |
1383 |
} |
1378 |
); |
1384 |
); |
1379 |
my $item_3 = $builder->build_sample_item; |
1385 |
my $item_3 = $builder->build_sample_item; |
1380 |
my $issue_3 = $builder->build_object( |
1386 |
my $issue_3 = $builder->build_object( |
1381 |
{ |
1387 |
{ |
1382 |
class => 'Koha::Checkouts', |
1388 |
class => 'Koha::Checkouts', |
Lines 1386-1392
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1386 |
}, |
1392 |
}, |
1387 |
} |
1393 |
} |
1388 |
); |
1394 |
); |
1389 |
my $item_4 = $builder->build_sample_item; |
1395 |
my $item_4 = $builder->build_sample_item; |
1390 |
my $issue_4 = $builder->build_object( |
1396 |
my $issue_4 = $builder->build_object( |
1391 |
{ |
1397 |
{ |
1392 |
class => 'Koha::Checkouts', |
1398 |
class => 'Koha::Checkouts', |
Lines 1397-1406
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1397 |
} |
1403 |
} |
1398 |
); |
1404 |
); |
1399 |
|
1405 |
|
1400 |
my ( $returned_1 ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1406 |
my ($returned_1) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1401 |
my ( $returned_2 ) = C4::Circulation::AddReturn( $item_2->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') ); |
1402 |
my ( $returned_3 ) = C4::Circulation::AddReturn( $item_3->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') ); |
1403 |
my ( $returned_4 ) = C4::Circulation::AddReturn( $item_4->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') ); |
1404 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
1410 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
1405 |
$item_1->withdrawn(1)->store; |
1411 |
$item_1->withdrawn(1)->store; |
1406 |
$item_2->itemlost(1)->store; |
1412 |
$item_2->itemlost(1)->store; |
Lines 1408-1431
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1408 |
|
1414 |
|
1409 |
my $dbh = C4::Context->dbh; |
1415 |
my $dbh = C4::Context->dbh; |
1410 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber in (?, ?, ?, ?)|); |
1416 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber in (?, ?, ?, ?)|); |
1411 |
$stu->execute(DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ), $item_1->itemnumber,$item_2->itemnumber,$item_3->itemnumber,$item_4->itemnumber); |
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 |
); |
1412 |
|
1421 |
|
1413 |
my $nb_rows = Koha::Patrons->anonymise_last_borrowers(); |
1422 |
my $nb_rows = Koha::Patrons->anonymise_last_borrowers(); |
1414 |
is( $nb_rows, 1, 'anonymise_issue_history should have returned the number of last borrowers anonymised'); |
1423 |
is( $nb_rows, 1, 'anonymise_issue_history should have returned the number of last borrowers anonymised' ); |
1415 |
|
1424 |
|
1416 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1425 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1417 |
$sth->execute($item_1->itemnumber); |
1426 |
$sth->execute( $item_1->itemnumber ); |
1418 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1427 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1419 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'withrawn items should not be anonymised' ); |
1428 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'withrawn items should not be anonymised' ); |
1420 |
$sth->execute($item_2->itemnumber); |
1429 |
$sth->execute( $item_2->itemnumber ); |
1421 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1430 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1422 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'lost items should not be anonymised' ); |
1431 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'lost items should not be anonymised' ); |
1423 |
$sth->execute($item_3->itemnumber); |
1432 |
$sth->execute( $item_3->itemnumber ); |
1424 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1433 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1425 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'damaged items should not be anonymised' ); |
1434 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'damaged items should not be anonymised' ); |
1426 |
$sth->execute($item_4->itemnumber); |
1435 |
$sth->execute( $item_4->itemnumber ); |
1427 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1436 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1428 |
is( $borrowernumber_used_to_anonymised, $anonymous->borrowernumber, 'not withdrawn, lost or damaged items are anonymised' ); |
1437 |
is( |
|
|
1438 |
$borrowernumber_used_to_anonymised, $anonymous->borrowernumber, |
1439 |
'not withdrawn, lost or damaged items are anonymised' |
1440 |
); |
1429 |
|
1441 |
|
1430 |
}; |
1442 |
}; |
1431 |
|
1443 |
|
1432 |
- |
|
|