|
Lines 1174-1266
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
| 1174 |
subtest 'anonymise items_last_borrower' => sub { |
1174 |
subtest 'anonymise items_last_borrower' => sub { |
| 1175 |
plan tests => 1; |
1175 |
plan tests => 1; |
| 1176 |
|
1176 |
|
| 1177 |
# TODO create a subroutine in t::lib::Mocks |
1177 |
my $anonymous = $builder->build_object( { class => 'Koha::Patrons', }, ); |
| 1178 |
my $anonymous = $builder->build( { source => 'Borrower', }, ); |
|
|
| 1179 |
|
1178 |
|
| 1180 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
1179 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->borrowernumber ); |
| 1181 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
1180 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
| 1182 |
|
1181 |
|
| 1183 |
subtest 'withrawn, lost and damaged items' => sub { |
1182 |
subtest 'withrawn, lost and damaged items' => sub { |
| 1184 |
plan tests => 5; |
1183 |
plan tests => 5; |
| 1185 |
|
1184 |
|
| 1186 |
my $patron = $builder->build( |
1185 |
my $patron = $builder->build_object( |
| 1187 |
{ source => 'Borrower', |
1186 |
{ |
| 1188 |
value => { privacy => 1, } |
1187 |
class => 'Koha::Patrons', |
| 1189 |
} |
1188 |
value => { privacy => 1, } |
| 1190 |
); |
|
|
| 1191 |
my $item_1 = $builder->build_object( |
| 1192 |
{ class => 'Koha::Items', |
| 1193 |
value => { |
| 1194 |
itemlost => 0, |
| 1195 |
withdrawn => 0, |
| 1196 |
damaged => 0, |
| 1197 |
}, |
| 1198 |
} |
1189 |
} |
| 1199 |
); |
1190 |
); |
| 1200 |
my $issue_1 = $builder->build( |
1191 |
my $item_1 = $builder->build_sample_item; |
| 1201 |
{ source => 'Issue', |
1192 |
my $issue_1 = $builder->build_object( |
| 1202 |
value => { |
1193 |
{ |
| 1203 |
borrowernumber => $patron->{borrowernumber}, |
1194 |
class => 'Koha::Checkouts', |
|
|
1195 |
value => { |
| 1196 |
borrowernumber => $patron->borrowernumber, |
| 1204 |
itemnumber => $item_1->itemnumber, |
1197 |
itemnumber => $item_1->itemnumber, |
| 1205 |
}, |
1198 |
}, |
| 1206 |
} |
1199 |
} |
| 1207 |
); |
1200 |
); |
| 1208 |
my $item_2 = $builder->build_object( |
1201 |
my $item_2 = $builder->build_sample_item; |
| 1209 |
{ class => 'Koha::Items', |
1202 |
my $issue_2 = $builder->build_object( |
| 1210 |
value => { |
1203 |
{ |
| 1211 |
itemlost => 0, |
1204 |
class => 'Koha::Checkouts', |
| 1212 |
withdrawn => 0, |
1205 |
value => { |
| 1213 |
damaged => 0, |
1206 |
borrowernumber => $patron->borrowernumber, |
| 1214 |
}, |
|
|
| 1215 |
} |
| 1216 |
); |
| 1217 |
my $issue_2 = $builder->build( |
| 1218 |
{ source => 'Issue', |
| 1219 |
value => { |
| 1220 |
borrowernumber => $patron->{borrowernumber}, |
| 1221 |
itemnumber => $item_2->itemnumber, |
1207 |
itemnumber => $item_2->itemnumber, |
| 1222 |
}, |
1208 |
}, |
| 1223 |
} |
1209 |
} |
| 1224 |
); |
1210 |
); |
| 1225 |
my $item_3 = $builder->build_object( |
1211 |
my $item_3 = $builder->build_sample_item; |
| 1226 |
{ class => 'Koha::Items', |
1212 |
my $issue_3 = $builder->build_object( |
| 1227 |
value => { |
1213 |
{ |
| 1228 |
itemlost => 0, |
1214 |
class => 'Koha::Checkouts', |
| 1229 |
withdrawn => 0, |
1215 |
value => { |
| 1230 |
damaged => 0, |
1216 |
borrowernumber => $patron->borrowernumber, |
| 1231 |
}, |
|
|
| 1232 |
} |
| 1233 |
); |
| 1234 |
my $issue_3 = $builder->build( |
| 1235 |
{ source => 'Issue', |
| 1236 |
value => { |
| 1237 |
borrowernumber => $patron->{borrowernumber}, |
| 1238 |
itemnumber => $item_3->itemnumber, |
1217 |
itemnumber => $item_3->itemnumber, |
| 1239 |
}, |
1218 |
}, |
| 1240 |
} |
1219 |
} |
| 1241 |
); |
1220 |
); |
| 1242 |
my $item_4 = $builder->build_object( |
1221 |
my $item_4 = $builder->build_sample_item; |
| 1243 |
{ class => 'Koha::Items', |
1222 |
my $issue_4 = $builder->build_object( |
| 1244 |
value => { |
1223 |
{ |
| 1245 |
itemlost => 0, |
1224 |
class => 'Koha::Checkouts', |
| 1246 |
withdrawn => 0, |
1225 |
value => { |
| 1247 |
damaged => 0, |
1226 |
borrowernumber => $patron->borrowernumber, |
| 1248 |
}, |
|
|
| 1249 |
} |
| 1250 |
); |
| 1251 |
my $issue_4 = $builder->build( |
| 1252 |
{ source => 'Issue', |
| 1253 |
value => { |
| 1254 |
borrowernumber => $patron->{borrowernumber}, |
| 1255 |
itemnumber => $item_4->itemnumber, |
1227 |
itemnumber => $item_4->itemnumber, |
| 1256 |
}, |
1228 |
}, |
| 1257 |
} |
1229 |
} |
| 1258 |
); |
1230 |
); |
| 1259 |
|
1231 |
|
| 1260 |
my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1232 |
my ( $returned_1 ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1261 |
my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1233 |
my ( $returned_2 ) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1262 |
my ( $returned_3, undef, undef ) = C4::Circulation::AddReturn( $item_3->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1234 |
my ( $returned_3 ) = C4::Circulation::AddReturn( $item_3->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1263 |
my ( $returned_4, undef, undef ) = C4::Circulation::AddReturn( $item_4->barcode, undef, undef, dt_from_string('2010-10-11') ); |
1235 |
my ( $returned_4 ) = C4::Circulation::AddReturn( $item_4->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1264 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
1236 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
| 1265 |
$item_1->withdrawn(1)->store; |
1237 |
$item_1->withdrawn(1)->store; |
| 1266 |
$item_2->itemlost(1)->store; |
1238 |
$item_2->itemlost(1)->store; |
|
Lines 1272-1287
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
| 1272 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1244 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
| 1273 |
$sth->execute($item_1->itemnumber); |
1245 |
$sth->execute($item_1->itemnumber); |
| 1274 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1246 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1275 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'withrawn items should not be anonymised' ); |
1247 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'withrawn items should not be anonymised' ); |
| 1276 |
$sth->execute($item_2->itemnumber); |
1248 |
$sth->execute($item_2->itemnumber); |
| 1277 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1249 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1278 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'lost items should not be anonymised' ); |
1250 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'lost items should not be anonymised' ); |
| 1279 |
$sth->execute($item_3->itemnumber); |
1251 |
$sth->execute($item_3->itemnumber); |
| 1280 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1252 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1281 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'damaged items should not be anonymised' ); |
1253 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'damaged items should not be anonymised' ); |
| 1282 |
$sth->execute($item_4->itemnumber); |
1254 |
$sth->execute($item_4->itemnumber); |
| 1283 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1255 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1284 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'not withdrawn, lost or damaged items are anonymised' ); |
1256 |
is( $borrowernumber_used_to_anonymised, $anonymous->borrowernumber, 'not withdrawn, lost or damaged items are anonymised' ); |
| 1285 |
|
1257 |
|
| 1286 |
}; |
1258 |
}; |
| 1287 |
|
1259 |
|
| 1288 |
- |
|
|