|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
| 23 |
use Try::Tiny; |
23 |
use Try::Tiny; |
| 24 |
|
24 |
|
| 25 |
use C4::Circulation; |
25 |
use C4::Circulation; |
|
Lines 54-64
subtest 'Config does not exist' => sub {
Link Here
|
| 54 |
C4::Stats::UpdateStats( |
54 |
C4::Stats::UpdateStats( |
| 55 |
{ |
55 |
{ |
| 56 |
type => 'issue', |
56 |
type => 'issue', |
| 57 |
branch => 'BBB', |
57 |
branch => $library->branchcode, |
| 58 |
itemnumber => $item->itemnumber, |
58 |
itemnumber => $item->itemnumber, |
| 59 |
borrowernumber => $patron->borrowernumber, |
59 |
borrowernumber => $patron->borrowernumber, |
| 60 |
itemtype => $item->effective_itemtype, |
60 |
itemtype => $item->effective_itemtype, |
| 61 |
location => $item->location, |
61 |
location => $item->location, |
|
|
62 |
ccode => $item->ccode, |
| 62 |
} |
63 |
} |
| 63 |
); |
64 |
); |
| 64 |
|
65 |
|
|
Lines 113-115
subtest 'Koha::Anonymized::Transactions tests' => sub {
Link Here
|
| 113 |
|
114 |
|
| 114 |
$schema->storage->txn_rollback; |
115 |
$schema->storage->txn_rollback; |
| 115 |
}; |
116 |
}; |
| 116 |
- |
117 |
|
|
|
118 |
subtest 'PseudonymizedBorrowerAttributes tests' => sub { |
| 119 |
|
| 120 |
plan tests => 3; |
| 121 |
|
| 122 |
$schema->storage->txn_begin; |
| 123 |
|
| 124 |
t::lib::Mocks::mock_config( 'key', '$2a$08$9lmorEKnwQloheaCLFIfje' ); |
| 125 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
| 126 |
t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', |
| 127 |
'branchcode,categorycode,sort1' ); |
| 128 |
|
| 129 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 130 |
my $patron_info = $patron->unblessed; |
| 131 |
delete $patron_info->{borrowernumber}; |
| 132 |
$patron->delete; |
| 133 |
|
| 134 |
my $attribute_type1 = Koha::Patron::Attribute::Type->new( |
| 135 |
{ |
| 136 |
code => 'my code1', |
| 137 |
description => 'my description1', |
| 138 |
repeatable => 1, |
| 139 |
keep_for_pseudonymization => 1, |
| 140 |
} |
| 141 |
)->store; |
| 142 |
my $attribute_type2 = Koha::Patron::Attribute::Type->new( |
| 143 |
{ |
| 144 |
code => 'my code2', |
| 145 |
description => 'my description2', |
| 146 |
keep_for_pseudonymization => 0, |
| 147 |
} |
| 148 |
)->store; |
| 149 |
my $attribute_type3 = Koha::Patron::Attribute::Type->new( |
| 150 |
{ |
| 151 |
code => 'my code3', |
| 152 |
description => 'my description3', |
| 153 |
keep_for_pseudonymization => 1, |
| 154 |
} |
| 155 |
)->store; |
| 156 |
|
| 157 |
$patron = Koha::Patron->new($patron_info)->store->get_from_storage; |
| 158 |
my $attribute_values = [ |
| 159 |
{ |
| 160 |
attribute => 'attribute for code1', |
| 161 |
code => $attribute_type1->code, |
| 162 |
}, |
| 163 |
{ |
| 164 |
attribute => 'attribute for code2', |
| 165 |
code => $attribute_type2->code |
| 166 |
}, |
| 167 |
{ |
| 168 |
attribute => 'attribute for code3', |
| 169 |
code => $attribute_type3->code |
| 170 |
}, |
| 171 |
]; |
| 172 |
|
| 173 |
$patron->extended_attributes($attribute_values); |
| 174 |
|
| 175 |
|
| 176 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 177 |
my $item = $builder->build_sample_item; |
| 178 |
|
| 179 |
C4::Stats::UpdateStats( |
| 180 |
{ |
| 181 |
type => 'issue', |
| 182 |
branch => $library->branchcode, |
| 183 |
itemnumber => $item->itemnumber, |
| 184 |
borrowernumber => $patron->borrowernumber, |
| 185 |
itemtype => $item->effective_itemtype, |
| 186 |
location => $item->location, |
| 187 |
ccode => $item->ccode, |
| 188 |
} |
| 189 |
); |
| 190 |
|
| 191 |
my $p = Koha::PseudonymizedTransactions->search({itemnumber => $item->itemnumber})->next; |
| 192 |
my $attributes = Koha::Database->new->schema->resultset('PseudonymizedBorrowerAttribute')->search({transaction_id => $p->id }); |
| 193 |
is( $attributes->count, 2, |
| 194 |
'Only the 2 attributes that have a type with keep_for_pseudonymization set should be kept' |
| 195 |
); |
| 196 |
my $attribute_1 = $attributes->next; |
| 197 |
is_deeply( |
| 198 |
{ attribute => $attribute_1->attribute, code => $attribute_1->code->code }, |
| 199 |
$attribute_values->[0], |
| 200 |
'Attribute 1 should be retrieved correctly' |
| 201 |
); |
| 202 |
my $attribute_2 = $attributes->next; |
| 203 |
is_deeply( |
| 204 |
{ attribute => $attribute_2->attribute, code => $attribute_2->code->code }, |
| 205 |
$attribute_values->[2], |
| 206 |
'Attribute 2 should be retrieved correctly' |
| 207 |
); |
| 208 |
|
| 209 |
$schema->storage->txn_rollback; |
| 210 |
}; |