|
Lines 1286-1291
subtest 'search_patrons_to_anonymise' => sub {
Link Here
|
| 1286 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
1286 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
| 1287 |
}; |
1287 |
}; |
| 1288 |
|
1288 |
|
|
|
1289 |
subtest 'anonymise items_last_borrower' => sub { |
| 1290 |
plan tests => 1; |
| 1291 |
|
| 1292 |
# TODO create a subroutine in t::lib::Mocks |
| 1293 |
my $anonymous = $builder->build( { source => 'Borrower', }, ); |
| 1294 |
|
| 1295 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
| 1296 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
| 1297 |
|
| 1298 |
subtest 'withrawn, lost and damaged items' => sub { |
| 1299 |
plan tests => 5; |
| 1300 |
|
| 1301 |
my $patron = $builder->build( |
| 1302 |
{ source => 'Borrower', |
| 1303 |
value => { privacy => 1, } |
| 1304 |
} |
| 1305 |
); |
| 1306 |
my $item_1 = $builder->build_object( |
| 1307 |
{ class => 'Koha::Items', |
| 1308 |
value => { |
| 1309 |
itemlost => 0, |
| 1310 |
withdrawn => 0, |
| 1311 |
damaged => 0, |
| 1312 |
}, |
| 1313 |
} |
| 1314 |
); |
| 1315 |
my $issue_1 = $builder->build( |
| 1316 |
{ source => 'Issue', |
| 1317 |
value => { |
| 1318 |
borrowernumber => $patron->{borrowernumber}, |
| 1319 |
itemnumber => $item_1->itemnumber, |
| 1320 |
}, |
| 1321 |
} |
| 1322 |
); |
| 1323 |
my $item_2 = $builder->build_object( |
| 1324 |
{ class => 'Koha::Items', |
| 1325 |
value => { |
| 1326 |
itemlost => 0, |
| 1327 |
withdrawn => 0, |
| 1328 |
damaged => 0, |
| 1329 |
}, |
| 1330 |
} |
| 1331 |
); |
| 1332 |
my $issue_2 = $builder->build( |
| 1333 |
{ source => 'Issue', |
| 1334 |
value => { |
| 1335 |
borrowernumber => $patron->{borrowernumber}, |
| 1336 |
itemnumber => $item_2->itemnumber, |
| 1337 |
}, |
| 1338 |
} |
| 1339 |
); |
| 1340 |
my $item_3 = $builder->build_object( |
| 1341 |
{ class => 'Koha::Items', |
| 1342 |
value => { |
| 1343 |
itemlost => 0, |
| 1344 |
withdrawn => 0, |
| 1345 |
damaged => 0, |
| 1346 |
}, |
| 1347 |
} |
| 1348 |
); |
| 1349 |
my $issue_3 = $builder->build( |
| 1350 |
{ source => 'Issue', |
| 1351 |
value => { |
| 1352 |
borrowernumber => $patron->{borrowernumber}, |
| 1353 |
itemnumber => $item_3->itemnumber, |
| 1354 |
}, |
| 1355 |
} |
| 1356 |
); |
| 1357 |
my $item_4 = $builder->build_object( |
| 1358 |
{ class => 'Koha::Items', |
| 1359 |
value => { |
| 1360 |
itemlost => 0, |
| 1361 |
withdrawn => 0, |
| 1362 |
damaged => 0, |
| 1363 |
}, |
| 1364 |
} |
| 1365 |
); |
| 1366 |
my $issue_4 = $builder->build( |
| 1367 |
{ source => 'Issue', |
| 1368 |
value => { |
| 1369 |
borrowernumber => $patron->{borrowernumber}, |
| 1370 |
itemnumber => $item_4->itemnumber, |
| 1371 |
}, |
| 1372 |
} |
| 1373 |
); |
| 1374 |
|
| 1375 |
my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1376 |
my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1377 |
my ( $returned_3, undef, undef ) = C4::Circulation::AddReturn( $item_3->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1378 |
my ( $returned_4, undef, undef ) = C4::Circulation::AddReturn( $item_4->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1379 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
| 1380 |
$item_1->withdrawn(1)->store; |
| 1381 |
$item_2->itemlost(1)->store; |
| 1382 |
$item_3->damaged(1)->store; |
| 1383 |
|
| 1384 |
Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-12' } )->anonymise_issue_history(); |
| 1385 |
|
| 1386 |
my $dbh = C4::Context->dbh; |
| 1387 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
| 1388 |
$sth->execute($item_1->itemnumber); |
| 1389 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1390 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'withrawn items should not be anonymised' ); |
| 1391 |
$sth->execute($item_2->itemnumber); |
| 1392 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1393 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'lost items should not be anonymised' ); |
| 1394 |
$sth->execute($item_3->itemnumber); |
| 1395 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1396 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'damaged items should not be anonymised' ); |
| 1397 |
$sth->execute($item_4->itemnumber); |
| 1398 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1399 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'not withdrawn, lost or damaged items are anonymised' ); |
| 1400 |
|
| 1401 |
}; |
| 1402 |
|
| 1403 |
}; |
| 1404 |
|
| 1289 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
1405 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
| 1290 |
plan tests => 3; |
1406 |
plan tests => 3; |
| 1291 |
|
1407 |
|
| 1292 |
- |
|
|