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 1285-1300
subtest 'search_patrons_to_anonymise' => sub {
Link Here
|
1285 |
}; |
1285 |
}; |
1286 |
|
1286 |
|
1287 |
subtest 'anonymise items_last_borrower' => sub { |
1287 |
subtest 'anonymise items_last_borrower' => sub { |
1288 |
plan tests => 1; |
1288 |
plan tests => 2; |
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); |
1295 |
|
1296 |
subtest 'anonymise items_last_borrower by days' => sub { |
1297 |
plan tests => 4; |
1298 |
|
1299 |
t::lib::Mocks::mock_preference('AnonymiseLastBorrowerDays', 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->anonymise_last_borrowers(); |
1336 |
is( $nb_rows, 1, 'anonymise_issue_history should have returned the number of last borrowers anonymised'); |
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_anonymised) = $sth->fetchrow_array; |
1341 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'Last borrower younger than 5 days are not anonymised' ); |
1342 |
$sth->execute($item_2->itemnumber); |
1343 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1344 |
is( $borrowernumber_used_to_anonymised, $anonymous->borrowernumber, 'Last borrower older than 5 days are anonymised' ); |
1345 |
|
1346 |
}; |
1294 |
|
1347 |
|
1295 |
subtest 'withrawn, lost and damaged items' => sub { |
1348 |
subtest 'withrawn, lost and damaged items' => sub { |
1296 |
plan tests => 6; |
1349 |
plan tests => 6; |
1297 |
|
1350 |
|
|
|
1351 |
t::lib::Mocks::mock_preference('AnonymiseLastBorrowerDays', 0); |
1352 |
|
1298 |
my $patron = $builder->build_object( |
1353 |
my $patron = $builder->build_object( |
1299 |
{ |
1354 |
{ |
1300 |
class => 'Koha::Patrons', |
1355 |
class => 'Koha::Patrons', |
Lines 1351-1360
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1351 |
$item_2->itemlost(1)->store; |
1406 |
$item_2->itemlost(1)->store; |
1352 |
$item_3->damaged(1)->store; |
1407 |
$item_3->damaged(1)->store; |
1353 |
|
1408 |
|
1354 |
my $nb_rows = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-12' } )->anonymise_issue_history(); |
|
|
1355 |
is( $nb_rows, 4, 'anonymise_issue_history should have returned the number of checkouts anonymised'); |
1356 |
|
1357 |
my $dbh = C4::Context->dbh; |
1409 |
my $dbh = C4::Context->dbh; |
|
|
1410 |
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); |
1412 |
|
1413 |
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'); |
1415 |
|
1358 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1416 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1359 |
$sth->execute($item_1->itemnumber); |
1417 |
$sth->execute($item_1->itemnumber); |
1360 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1418 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1361 |
- |
|
|