Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 41; |
22 |
use Test::More tests => 42; |
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 1200-1215
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
1200 |
}; |
1200 |
}; |
1201 |
|
1201 |
|
1202 |
subtest 'anonymise items_last_borrower' => sub { |
1202 |
subtest 'anonymise items_last_borrower' => sub { |
1203 |
plan tests => 1; |
1203 |
plan tests => 2; |
1204 |
|
1204 |
|
1205 |
my $anonymous = $builder->build_object( { class => 'Koha::Patrons', }, ); |
1205 |
my $anonymous = $builder->build_object( { class => 'Koha::Patrons', }, ); |
1206 |
|
1206 |
|
1207 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->borrowernumber ); |
1207 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->borrowernumber ); |
1208 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
1208 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
|
|
1209 |
t::lib::Mocks::mock_preference('AnonymiseLastBorrower', 1); |
1210 |
|
1211 |
subtest 'anonymise items_last_borrower by days' => sub { |
1212 |
plan tests => 4; |
1213 |
|
1214 |
t::lib::Mocks::mock_preference('AnonymiseLastBorrowerDays', 5); |
1215 |
|
1216 |
my $patron = $builder->build_object( |
1217 |
{ |
1218 |
class => 'Koha::Patrons', |
1219 |
value => { privacy => 1, } |
1220 |
} |
1221 |
); |
1222 |
my $item_1 = $builder->build_sample_item; |
1223 |
my $issue_1 = $builder->build_object( |
1224 |
{ |
1225 |
class => 'Koha::Checkouts', |
1226 |
value => { |
1227 |
borrowernumber => $patron->borrowernumber, |
1228 |
itemnumber => $item_1->itemnumber, |
1229 |
}, |
1230 |
} |
1231 |
); |
1232 |
my $item_2 = $builder->build_sample_item; |
1233 |
my $issue_2 = $builder->build_object( |
1234 |
{ |
1235 |
class => 'Koha::Checkouts', |
1236 |
value => { |
1237 |
borrowernumber => $patron->borrowernumber, |
1238 |
itemnumber => $item_2->itemnumber, |
1239 |
}, |
1240 |
} |
1241 |
); |
1242 |
|
1243 |
my $dbh = C4::Context->dbh; |
1244 |
my ( $returned_1 ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string ); |
1245 |
my ( $returned_2 ) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string ); |
1246 |
is( $returned_1 && $returned_2, 1, 'The items should have been returned' ); |
1247 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber = ?|); |
1248 |
$stu->execute(DateTime->today(time_zone => C4::Context->tz())->add( days => -6 ), $item_2->itemnumber); |
1249 |
|
1250 |
my $nb_rows = Koha::Patrons->anonymise_last_borrowers(); |
1251 |
is( $nb_rows, 1, 'anonymise_issue_history should have returned the number of last borrowers anonymised'); |
1252 |
|
1253 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1254 |
$sth->execute($item_1->itemnumber); |
1255 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1256 |
is( $borrowernumber_used_to_anonymised, $patron->borrowernumber, 'Last borrower younger than 5 days are not anonymised' ); |
1257 |
$sth->execute($item_2->itemnumber); |
1258 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1259 |
is( $borrowernumber_used_to_anonymised, $anonymous->borrowernumber, 'Last borrower older than 5 days are anonymised' ); |
1260 |
|
1261 |
}; |
1209 |
|
1262 |
|
1210 |
subtest 'withrawn, lost and damaged items' => sub { |
1263 |
subtest 'withrawn, lost and damaged items' => sub { |
1211 |
plan tests => 6; |
1264 |
plan tests => 6; |
1212 |
|
1265 |
|
|
|
1266 |
t::lib::Mocks::mock_preference('AnonymiseLastBorrowerDays', 0); |
1267 |
|
1213 |
my $patron = $builder->build_object( |
1268 |
my $patron = $builder->build_object( |
1214 |
{ |
1269 |
{ |
1215 |
class => 'Koha::Patrons', |
1270 |
class => 'Koha::Patrons', |
Lines 1266-1275
subtest 'anonymise items_last_borrower' => sub {
Link Here
|
1266 |
$item_2->itemlost(1)->store; |
1321 |
$item_2->itemlost(1)->store; |
1267 |
$item_3->damaged(1)->store; |
1322 |
$item_3->damaged(1)->store; |
1268 |
|
1323 |
|
1269 |
my $nb_rows = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-12' } )->anonymise_issue_history(); |
|
|
1270 |
is( $nb_rows, 4, 'anonymise_issue_history should have returned the number of checkouts anonymised'); |
1271 |
|
1272 |
my $dbh = C4::Context->dbh; |
1324 |
my $dbh = C4::Context->dbh; |
|
|
1325 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber in (?, ?, ?, ?)|); |
1326 |
$stu->execute(DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ), $item_1->itemnumber,$item_2->itemnumber,$item_3->itemnumber,$item_4->itemnumber); |
1327 |
|
1328 |
my $nb_rows = Koha::Patrons->anonymise_last_borrowers(); |
1329 |
is( $nb_rows, 1, 'anonymise_issue_history should have returned the number of last borrowers anonymised'); |
1330 |
|
1273 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1331 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
1274 |
$sth->execute($item_1->itemnumber); |
1332 |
$sth->execute($item_1->itemnumber); |
1275 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1333 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1276 |
- |
|
|