|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 40; |
22 |
use Test::More tests => 41; |
| 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 1171-1176
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
| 1171 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
1171 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
| 1172 |
}; |
1172 |
}; |
| 1173 |
|
1173 |
|
|
|
1174 |
subtest 'anonymise items_last_borrower' => sub { |
| 1175 |
plan tests => 1; |
| 1176 |
|
| 1177 |
# TODO create a subroutine in t::lib::Mocks |
| 1178 |
my $anonymous = $builder->build( { source => 'Borrower', }, ); |
| 1179 |
|
| 1180 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
| 1181 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
| 1182 |
|
| 1183 |
subtest 'withrawn, lost and damaged items' => sub { |
| 1184 |
plan tests => 5; |
| 1185 |
|
| 1186 |
my $patron = $builder->build( |
| 1187 |
{ source => 'Borrower', |
| 1188 |
value => { privacy => 1, } |
| 1189 |
} |
| 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 |
} |
| 1199 |
); |
| 1200 |
my $issue_1 = $builder->build( |
| 1201 |
{ source => 'Issue', |
| 1202 |
value => { |
| 1203 |
borrowernumber => $patron->{borrowernumber}, |
| 1204 |
itemnumber => $item_1->itemnumber, |
| 1205 |
}, |
| 1206 |
} |
| 1207 |
); |
| 1208 |
my $item_2 = $builder->build_object( |
| 1209 |
{ class => 'Koha::Items', |
| 1210 |
value => { |
| 1211 |
itemlost => 0, |
| 1212 |
withdrawn => 0, |
| 1213 |
damaged => 0, |
| 1214 |
}, |
| 1215 |
} |
| 1216 |
); |
| 1217 |
my $issue_2 = $builder->build( |
| 1218 |
{ source => 'Issue', |
| 1219 |
value => { |
| 1220 |
borrowernumber => $patron->{borrowernumber}, |
| 1221 |
itemnumber => $item_2->itemnumber, |
| 1222 |
}, |
| 1223 |
} |
| 1224 |
); |
| 1225 |
my $item_3 = $builder->build_object( |
| 1226 |
{ class => 'Koha::Items', |
| 1227 |
value => { |
| 1228 |
itemlost => 0, |
| 1229 |
withdrawn => 0, |
| 1230 |
damaged => 0, |
| 1231 |
}, |
| 1232 |
} |
| 1233 |
); |
| 1234 |
my $issue_3 = $builder->build( |
| 1235 |
{ source => 'Issue', |
| 1236 |
value => { |
| 1237 |
borrowernumber => $patron->{borrowernumber}, |
| 1238 |
itemnumber => $item_3->itemnumber, |
| 1239 |
}, |
| 1240 |
} |
| 1241 |
); |
| 1242 |
my $item_4 = $builder->build_object( |
| 1243 |
{ class => 'Koha::Items', |
| 1244 |
value => { |
| 1245 |
itemlost => 0, |
| 1246 |
withdrawn => 0, |
| 1247 |
damaged => 0, |
| 1248 |
}, |
| 1249 |
} |
| 1250 |
); |
| 1251 |
my $issue_4 = $builder->build( |
| 1252 |
{ source => 'Issue', |
| 1253 |
value => { |
| 1254 |
borrowernumber => $patron->{borrowernumber}, |
| 1255 |
itemnumber => $item_4->itemnumber, |
| 1256 |
}, |
| 1257 |
} |
| 1258 |
); |
| 1259 |
|
| 1260 |
my ( $returned_1, undef, undef ) = 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') ); |
| 1262 |
my ( $returned_3, undef, undef ) = 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') ); |
| 1264 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
| 1265 |
$item_1->withdrawn(1)->store; |
| 1266 |
$item_2->itemlost(1)->store; |
| 1267 |
$item_3->damaged(1)->store; |
| 1268 |
|
| 1269 |
Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-12' } )->anonymise_issue_history(); |
| 1270 |
|
| 1271 |
my $dbh = C4::Context->dbh; |
| 1272 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
| 1273 |
$sth->execute($item_1->itemnumber); |
| 1274 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1275 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'withrawn items should not be anonymised' ); |
| 1276 |
$sth->execute($item_2->itemnumber); |
| 1277 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1278 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'lost items should not be anonymised' ); |
| 1279 |
$sth->execute($item_3->itemnumber); |
| 1280 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1281 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'damaged items should not be anonymised' ); |
| 1282 |
$sth->execute($item_4->itemnumber); |
| 1283 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 1284 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'not withdrawn, lost or damaged items are anonymised' ); |
| 1285 |
|
| 1286 |
}; |
| 1287 |
|
| 1288 |
}; |
| 1289 |
|
| 1174 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
1290 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
| 1175 |
plan tests => 3; |
1291 |
plan tests => 3; |
| 1176 |
|
1292 |
|
| 1177 |
- |
|
|