|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 3; |
22 |
use Test::More tests => 4; |
| 23 |
use Try::Tiny; |
23 |
use Try::Tiny; |
| 24 |
|
24 |
|
| 25 |
use C4::Circulation; |
25 |
use C4::Circulation; |
|
Lines 169-171
subtest 'Koha::Anonymized::Transactions tests' => sub {
Link Here
|
| 169 |
|
169 |
|
| 170 |
$schema->storage->txn_rollback; |
170 |
$schema->storage->txn_rollback; |
| 171 |
}; |
171 |
}; |
| 172 |
- |
172 |
|
|
|
173 |
subtest 'Koha::Anonymized::Patrons tests' => sub { |
| 174 |
|
| 175 |
plan tests => 6; |
| 176 |
|
| 177 |
$schema->storage->txn_begin; |
| 178 |
|
| 179 |
t::lib::Mocks::mock_config( 'key', '$2a$08$9lmorEKnwQloheaCLFIfje' ); |
| 180 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
| 181 |
t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', |
| 182 |
'branchcode,categorycode,sort1' ); |
| 183 |
|
| 184 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 185 |
my $patron_info = $patron->unblessed; |
| 186 |
delete $patron_info->{borrowernumber}; |
| 187 |
$patron->delete; |
| 188 |
|
| 189 |
my $attribute_type1 = Koha::Patron::Attribute::Type->new( |
| 190 |
{ |
| 191 |
code => 'my code1', |
| 192 |
description => 'my description1', |
| 193 |
repeatable => 1, |
| 194 |
keep_for_anonymized => 1, |
| 195 |
} |
| 196 |
)->store; |
| 197 |
my $attribute_type2 = Koha::Patron::Attribute::Type->new( |
| 198 |
{ |
| 199 |
code => 'my code2', |
| 200 |
description => 'my description2', |
| 201 |
keep_for_anonymized => 0, |
| 202 |
} |
| 203 |
)->store; |
| 204 |
my $attribute_type3 = Koha::Patron::Attribute::Type->new( |
| 205 |
{ |
| 206 |
code => 'my code3', |
| 207 |
description => 'my description3', |
| 208 |
keep_for_anonymized => 1, |
| 209 |
} |
| 210 |
)->store; |
| 211 |
my $attribute_type4 = Koha::Patron::Attribute::Type->new( |
| 212 |
{ |
| 213 |
code => 'my code4', |
| 214 |
description => 'my description4', |
| 215 |
keep_for_anonymized => 0, |
| 216 |
} |
| 217 |
)->store; |
| 218 |
my $attribute_type5 = Koha::Patron::Attribute::Type->new( |
| 219 |
{ |
| 220 |
code => 'my code5', |
| 221 |
description => 'my description5', |
| 222 |
keep_for_anonymized => 1, |
| 223 |
} |
| 224 |
)->store; |
| 225 |
|
| 226 |
$patron = Koha::Patron->new($patron_info)->store->get_from_storage; |
| 227 |
my $attribute_values = [ |
| 228 |
{ |
| 229 |
attribute => 'attribute for code1', |
| 230 |
code => $attribute_type1->code, |
| 231 |
}, |
| 232 |
{ |
| 233 |
attribute => 'attribute for code2', |
| 234 |
code => $attribute_type2->code |
| 235 |
}, |
| 236 |
{ |
| 237 |
attribute => 'attribute for code3', |
| 238 |
code => $attribute_type3->code |
| 239 |
}, |
| 240 |
]; |
| 241 |
|
| 242 |
$patron->extended_attributes($attribute_values); |
| 243 |
my $anonymized = Koha::Anonymized::Patrons->find_from_borrowernumber( |
| 244 |
$patron->borrowernumber ); |
| 245 |
my $attributes = $anonymized->extended_attributes; |
| 246 |
is( $attributes->count, 2, |
| 247 |
'Only the 2 attributes that have a type with keep_for_anonymized set should be kept' |
| 248 |
); |
| 249 |
my $attribute_1 = $attributes->next; |
| 250 |
is_deeply( |
| 251 |
{ attribute => $attribute_1->attribute, code => $attribute_1->code }, |
| 252 |
$attribute_values->[0], |
| 253 |
'Attribute 1 should be retrieved correctly' |
| 254 |
); |
| 255 |
my $attribute_2 = $attributes->next; |
| 256 |
is_deeply( |
| 257 |
{ attribute => $attribute_2->attribute, code => $attribute_2->code }, |
| 258 |
$attribute_values->[2], |
| 259 |
'Attribute 2 should be retrieved correctly' |
| 260 |
); |
| 261 |
|
| 262 |
# Adding another attribute for code 1, that is repeatable |
| 263 |
$patron->add_extended_attribute( |
| 264 |
{ |
| 265 |
attribute => 'attribute 2 for code 1', |
| 266 |
code => $attribute_type1->code |
| 267 |
} |
| 268 |
); |
| 269 |
$attributes = $anonymized->extended_attributes; |
| 270 |
is( $attributes->count, 3, |
| 271 |
'New repeatable attribute should have been added' ); |
| 272 |
|
| 273 |
# Adding an attribute for code 4, that should not be kept |
| 274 |
$patron->add_extended_attribute( |
| 275 |
{ |
| 276 |
attribute => 'attribute 1 for code 4', |
| 277 |
code => $attribute_type4->code |
| 278 |
} |
| 279 |
); |
| 280 |
$attributes = $anonymized->extended_attributes; |
| 281 |
is( $attributes->count, 3, 'No new attribute kept' ); |
| 282 |
|
| 283 |
# Adding a new attribute for code 5, no repeatable but kept |
| 284 |
$patron->add_extended_attribute( |
| 285 |
{ |
| 286 |
attribute => 'attribute 1 for code 5', |
| 287 |
code => $attribute_type5->code |
| 288 |
} |
| 289 |
); |
| 290 |
$attributes = $anonymized->extended_attributes; |
| 291 |
is( $attributes->count, 4, 'New attribute kept' ); |
| 292 |
|
| 293 |
$schema->storage->txn_rollback; |
| 294 |
}; |