|
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 40-45
use Koha::Patron::Categories;
Link Here
|
| 40 |
use Koha::Patron::Relationship; |
40 |
use Koha::Patron::Relationship; |
| 41 |
use Koha::Database; |
41 |
use Koha::Database; |
| 42 |
use Koha::DateUtils; |
42 |
use Koha::DateUtils; |
|
|
43 |
use DateTime; |
| 44 |
use DateTime::Duration; |
| 43 |
use Koha::Virtualshelves; |
45 |
use Koha::Virtualshelves; |
| 44 |
|
46 |
|
| 45 |
use t::lib::TestBuilder; |
47 |
use t::lib::TestBuilder; |
|
Lines 1178-1183
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
| 1178 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
1180 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
| 1179 |
}; |
1181 |
}; |
| 1180 |
|
1182 |
|
|
|
1183 |
subtest 'search_patrons_to_anonymise & anonymise_items_last_borrower' => sub { |
| 1184 |
plan tests => 3; |
| 1185 |
|
| 1186 |
my $branch = $builder->build({ source => 'Branch' }); |
| 1187 |
my $userenv_patron = $builder->build_object({ |
| 1188 |
class => 'Koha::Patrons', |
| 1189 |
value => { branchcode => $branch->{branchcode}, flags => 0 }, |
| 1190 |
}); |
| 1191 |
t::lib::Mocks::mock_userenv({ patron => $userenv_patron }); |
| 1192 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 1); |
| 1193 |
|
| 1194 |
subtest 'AnonymousPatron is defined' => sub { |
| 1195 |
plan tests => 3; |
| 1196 |
|
| 1197 |
my $anonymous = $builder->build( { source => 'Borrower', }, ); |
| 1198 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
| 1199 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
| 1200 |
my $patron = $builder->build( |
| 1201 |
{ source => 'Borrower', |
| 1202 |
value => { privacy => 1, } |
| 1203 |
} |
| 1204 |
); |
| 1205 |
my $item = $builder->build( |
| 1206 |
{ source => 'Item', |
| 1207 |
value => { |
| 1208 |
itemlost => 0, |
| 1209 |
withdrawn => 0, |
| 1210 |
damaged => 0 |
| 1211 |
}, |
| 1212 |
} |
| 1213 |
); |
| 1214 |
my $issue = $builder->build( |
| 1215 |
{ source => 'Issue', |
| 1216 |
value => { |
| 1217 |
borrowernumber => $patron->{borrowernumber}, |
| 1218 |
itemnumber => $item->{itemnumber}, |
| 1219 |
}, |
| 1220 |
} |
| 1221 |
); |
| 1222 |
|
| 1223 |
my $now = DateTime->now; |
| 1224 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, $now ); |
| 1225 |
is( $returned, 1, 'The item should have been returned' ); |
| 1226 |
my $before = $now + DateTime::Duration->new( days => 1 ); |
| 1227 |
my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => $before->ymd, for => 'items_last_borrower' } )->anonymise_items_last_borrower( { before => $before->ymd } ); |
| 1228 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
| 1229 |
my $dbh = C4::Context->dbh; |
| 1230 |
my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q| |
| 1231 |
SELECT borrowernumber FROM items_last_borrower where itemnumber = ? |
| 1232 |
|, undef, $item->{itemnumber}); |
| 1233 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'AnonymousPatron should have been used to anonymise' ); |
| 1234 |
Koha::Patrons->find( $patron->{borrowernumber})->delete; |
| 1235 |
Koha::Patrons->find( $anonymous->{borrowernumber})->delete; |
| 1236 |
}; |
| 1237 |
|
| 1238 |
subtest 'AnonymousPatron is not defined' => sub { |
| 1239 |
plan tests => 3; |
| 1240 |
|
| 1241 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
| 1242 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', '' ); |
| 1243 |
my $patron = $builder->build( |
| 1244 |
{ source => 'Borrower', |
| 1245 |
value => { privacy => 1, } |
| 1246 |
} |
| 1247 |
); |
| 1248 |
my $item = $builder->build( |
| 1249 |
{ source => 'Item', |
| 1250 |
value => { |
| 1251 |
itemlost => 0, |
| 1252 |
withdrawn => 0, |
| 1253 |
damaged => 0 |
| 1254 |
}, |
| 1255 |
} |
| 1256 |
); |
| 1257 |
my $issue = $builder->build( |
| 1258 |
{ source => 'Issue', |
| 1259 |
value => { |
| 1260 |
borrowernumber => $patron->{borrowernumber}, |
| 1261 |
itemnumber => $item->{itemnumber}, |
| 1262 |
}, |
| 1263 |
} |
| 1264 |
); |
| 1265 |
|
| 1266 |
my $now = DateTime->now; |
| 1267 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, $now ); |
| 1268 |
is( $returned, 1, 'The item should have been returned' ); |
| 1269 |
my $before = $now + DateTime::Duration->new( days => 1 ); |
| 1270 |
my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => $before->ymd, for => 'items_last_borrower' } )->anonymise_items_last_borrower( { before => $before->ymd } ); |
| 1271 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
| 1272 |
my $dbh = C4::Context->dbh; |
| 1273 |
my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q| |
| 1274 |
SELECT borrowernumber FROM items_last_borrower where itemnumber = ? |
| 1275 |
|, undef, $item->{itemnumber}); |
| 1276 |
is( $borrowernumber_used_to_anonymised, undef, 'undef should have been used to anonymise' ); |
| 1277 |
Koha::Patrons->find( $patron->{borrowernumber})->delete; |
| 1278 |
}; |
| 1279 |
|
| 1280 |
subtest 'Logged in librarian is not superlibrarian & IndependentBranches' => sub { |
| 1281 |
plan tests => 1; |
| 1282 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 1 ); |
| 1283 |
my $patron = $builder->build( |
| 1284 |
{ source => 'Borrower', |
| 1285 |
value => { privacy => 1 } # Another branchcode than the logged in librarian |
| 1286 |
} |
| 1287 |
); |
| 1288 |
my $item = $builder->build( |
| 1289 |
{ source => 'Item', |
| 1290 |
value => { |
| 1291 |
itemlost => 0, |
| 1292 |
withdrawn => 0, |
| 1293 |
damaged => 0 |
| 1294 |
}, |
| 1295 |
} |
| 1296 |
); |
| 1297 |
my $issue = $builder->build( |
| 1298 |
{ source => 'Issue', |
| 1299 |
value => { |
| 1300 |
borrowernumber => $patron->{borrowernumber}, |
| 1301 |
itemnumber => $item->{itemnumber}, |
| 1302 |
}, |
| 1303 |
} |
| 1304 |
); |
| 1305 |
|
| 1306 |
my $now = DateTime->now; |
| 1307 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, $now ); |
| 1308 |
my $before = $now + DateTime::Duration->new( days => 1 ); |
| 1309 |
is( Koha::Patrons->search_patrons_to_anonymise( { before => $before->ymd, for => 'items_last_borrower' } )->count, 0 ); |
| 1310 |
Koha::Patrons->find( $patron->{borrowernumber})->delete; |
| 1311 |
}; |
| 1312 |
|
| 1313 |
$userenv_patron->delete; |
| 1314 |
t::lib::Mocks::mock_preference('StoreLastBorrower', 0); |
| 1315 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
| 1316 |
}; |
| 1317 |
|
| 1181 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
1318 |
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { |
| 1182 |
plan tests => 3; |
1319 |
plan tests => 3; |
| 1183 |
|
1320 |
|
| 1184 |
- |
|
|