Lines 1211-1216
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
1211 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
1211 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
1212 |
}; |
1212 |
}; |
1213 |
|
1213 |
|
|
|
1214 |
subtest 'anonymise items_last_borrower' => sub { |
1215 |
plan tests => 1; |
1216 |
|
1217 |
# TODO create a subroutine in t::lib::Mocks |
1218 |
my $anonymous = $builder->build( { source => 'Borrower', }, ); |
1219 |
|
1220 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
1221 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
1222 |
|
1223 |
subtest 'withrawn, lost and damaged items' => sub { |
1224 |
plan tests => 5; |
1225 |
|
1226 |
my $patron = $builder->build( |
1227 |
{ source => 'Borrower', |
1228 |
value => { privacy => 1, } |
1229 |
} |
1230 |
); |
1231 |
my $item_1 = $builder->build_object( |
1232 |
{ class => 'Koha::Items', |
1233 |
value => { |
1234 |
itemlost => 0, |
1235 |
withdrawn => 0, |
1236 |
damaged => 0, |
1237 |
}, |
1238 |
} |
1239 |
); |
1240 |
my $issue_1 = $builder->build( |
1241 |
{ source => 'Issue', |
1242 |
value => { |
1243 |
borrowernumber => $patron->{borrowernumber}, |
1244 |
itemnumber => $item_1->itemnumber, |
1245 |
}, |
1246 |
} |
1247 |
); |
1248 |
my $item_2 = $builder->build_object( |
1249 |
{ class => 'Koha::Items', |
1250 |
value => { |
1251 |
itemlost => 0, |
1252 |
withdrawn => 0, |
1253 |
damaged => 0, |
1254 |
}, |
1255 |
} |
1256 |
); |
1257 |
my $issue_2 = $builder->build( |
1258 |
{ source => 'Issue', |
1259 |
value => { |
1260 |
borrowernumber => $patron->{borrowernumber}, |
1261 |
itemnumber => $item_2->itemnumber, |
1262 |
}, |
1263 |
} |
1264 |
); |
1265 |
my $item_3 = $builder->build_object( |
1266 |
{ class => 'Koha::Items', |
1267 |
value => { |
1268 |
itemlost => 0, |
1269 |
withdrawn => 0, |
1270 |
damaged => 0, |
1271 |
}, |
1272 |
} |
1273 |
); |
1274 |
my $issue_3 = $builder->build( |
1275 |
{ source => 'Issue', |
1276 |
value => { |
1277 |
borrowernumber => $patron->{borrowernumber}, |
1278 |
itemnumber => $item_3->itemnumber, |
1279 |
}, |
1280 |
} |
1281 |
); |
1282 |
my $item_4 = $builder->build_object( |
1283 |
{ class => 'Koha::Items', |
1284 |
value => { |
1285 |
itemlost => 0, |
1286 |
withdrawn => 0, |
1287 |
damaged => 0, |
1288 |
}, |
1289 |
} |
1290 |
); |
1291 |
my $issue_4 = $builder->build( |
1292 |
{ source => 'Issue', |
1293 |
value => { |
1294 |
borrowernumber => $patron->{borrowernumber}, |
1295 |
itemnumber => $item_4->itemnumber, |
1296 |
}, |
1297 |
} |
1298 |
); |
1299 |
|
1300 |
my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1301 |
my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1302 |
my ( $returned_3, undef, undef ) = C4::Circulation::AddReturn( $item_3->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1303 |
my ( $returned_4, undef, undef ) = C4::Circulation::AddReturn( $item_4->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1304 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
1305 |
$item_1->withdrawn(1)->store; |
1306 |
$item_2->itemlost(1)->store; |
1307 |
$item_3->damaged(1)->store; |
1308 |
|
1309 |
Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-12' } )->anonymise_issue_history(); |
1310 |
|
1311 |
my $dbh = C4::Context->dbh; |
1312 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1313 |
$sth->execute($item_1->itemnumber); |
1314 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1315 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'withrawn items should not be anonymised' ); |
1316 |
$sth->execute($item_2->itemnumber); |
1317 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1318 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'lost items should not be anonymised' ); |
1319 |
$sth->execute($item_3->itemnumber); |
1320 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1321 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'damaged items should not be anonymised' ); |
1322 |
$sth->execute($item_4->itemnumber); |
1323 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1324 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'not withdrawn, lost or damaged items are anonymised' ); |
1325 |
|
1326 |
}; |
1327 |
|
1328 |
}; |
1329 |
|
1214 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
1330 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
1215 |
plan tests => 3; |
1331 |
plan tests => 3; |
1216 |
|
1332 |
|
1217 |
- |
|
|