|
Lines 20-29
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 3; |
22 |
use Test::More tests => 3; |
|
|
23 |
use Test::Warn; |
| 23 |
use Try::Tiny; |
24 |
use Try::Tiny; |
| 24 |
|
25 |
|
| 25 |
use C4::Circulation qw( AddIssue AddReturn ); |
26 |
use C4::Circulation qw( AddIssue AddReturn ); |
| 26 |
use C4::Stats qw( UpdateStats ); |
27 |
use C4::Stats qw( UpdateStats ); |
| 27 |
|
28 |
|
| 28 |
use Koha::Database; |
29 |
use Koha::Database; |
| 29 |
use Koha::DateUtils qw( dt_from_string ); |
30 |
use Koha::DateUtils qw( dt_from_string ); |
|
Lines 44-58
subtest 'Config does not exist' => sub {
Link Here
|
| 44 |
$schema->storage->txn_begin; |
45 |
$schema->storage->txn_begin; |
| 45 |
|
46 |
|
| 46 |
t::lib::Mocks::mock_config( 'bcrypt_settings', '' ); |
47 |
t::lib::Mocks::mock_config( 'bcrypt_settings', '' ); |
| 47 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
48 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
| 48 |
t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' ); |
49 |
t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' ); |
| 49 |
|
50 |
|
| 50 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
51 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 51 |
my $item = $builder->build_sample_item; |
52 |
my $item = $builder->build_sample_item; |
| 52 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
53 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 53 |
|
54 |
|
| 54 |
try{ |
55 |
try { |
| 55 |
C4::Stats::UpdateStats( |
56 |
my $stat = Koha::Statistic->new( |
| 56 |
{ |
57 |
{ |
| 57 |
type => 'issue', |
58 |
type => 'issue', |
| 58 |
branch => $library->branchcode, |
59 |
branch => $library->branchcode, |
|
Lines 63-72
subtest 'Config does not exist' => sub {
Link Here
|
| 63 |
ccode => $item->ccode, |
64 |
ccode => $item->ccode, |
| 64 |
} |
65 |
} |
| 65 |
); |
66 |
); |
|
|
67 |
my $pseudo = Koha::PseudonymizedTransaction->new_from_statistic($stat); |
| 66 |
|
68 |
|
| 67 |
} catch { |
69 |
} catch { |
| 68 |
ok($_->isa('Koha::Exceptions::Config::MissingEntry'), "Koha::Patron->store should raise a Koha::Exceptions::Config::MissingEntry if 'bcrypt_settings' is not defined in the config"); |
70 |
ok( |
| 69 |
is( $_->message, "Missing 'bcrypt_settings' entry in config file"); |
71 |
$_->isa('Koha::Exceptions::Config::MissingEntry'), |
|
|
72 |
"Koha::Patron->store should raise a Koha::Exceptions::Config::MissingEntry if 'bcrypt_settings' is not defined in the config" |
| 73 |
); |
| 74 |
is( $_->message, "Missing 'bcrypt_settings' entry in config file" ); |
| 70 |
}; |
75 |
}; |
| 71 |
|
76 |
|
| 72 |
$schema->storage->txn_rollback; |
77 |
$schema->storage->txn_rollback; |
|
Lines 74-111
subtest 'Config does not exist' => sub {
Link Here
|
| 74 |
|
79 |
|
| 75 |
subtest 'Koha::Anonymized::Transactions tests' => sub { |
80 |
subtest 'Koha::Anonymized::Transactions tests' => sub { |
| 76 |
|
81 |
|
| 77 |
plan tests => 12; |
82 |
plan tests => 15; |
| 78 |
|
83 |
|
| 79 |
$schema->storage->txn_begin; |
84 |
$schema->storage->txn_begin; |
| 80 |
|
85 |
|
| 81 |
t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); |
86 |
t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); |
| 82 |
|
87 |
|
|
|
88 |
my $pseudo_background = Test::MockModule->new('Koha::BackgroundJob::PseudonymizeStatistic'); |
| 89 |
$pseudo_background->mock( enqueue => sub { warn "Called" } ); |
| 90 |
|
| 83 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
91 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 84 |
|
92 |
|
| 85 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 0 ); |
93 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 0 ); |
| 86 |
my $item = $builder->build_sample_item; |
94 |
my $item = $builder->build_sample_item; |
| 87 |
t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch }); |
95 |
t::lib::Mocks::mock_userenv( { branchcode => $item->homebranch } ); |
| 88 |
AddIssue( $patron, $item->barcode, dt_from_string ); |
96 |
warnings_are { |
| 89 |
AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); |
97 |
AddIssue( $patron, $item->barcode, dt_from_string ); |
| 90 |
my $pseudonymized= Koha::PseudonymizedTransactions->search( |
98 |
} |
| 91 |
{ itemnumber => $item->itemnumber } )->next; |
99 |
undef, "No background job queued when pseudonymization disabled"; |
| 92 |
is( $pseudonymized, undef, |
100 |
warnings_are { |
| 93 |
'No pseudonymized transaction if Pseudonymization is off' ); |
101 |
AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); |
|
|
102 |
} |
| 103 |
undef, "No background job queued when pseudonymization disabled"; |
| 94 |
|
104 |
|
| 95 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
105 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
| 96 |
t::lib::Mocks::mock_preference( 'PseudonymizationTransactionFields', 'datetime,transaction_branchcode,transaction_type,itemnumber,itemtype,holdingbranch,homebranch,location,itemcallnumber,ccode' |
106 |
t::lib::Mocks::mock_preference( |
|
|
107 |
'PseudonymizationTransactionFields', |
| 108 |
'datetime,transaction_branchcode,transaction_type,itemnumber,itemtype,holdingbranch,homebranch,location,itemcallnumber,ccode' |
| 97 |
); |
109 |
); |
| 98 |
$item = $builder->build_sample_item; |
110 |
$item = $builder->build_sample_item; |
| 99 |
t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch }); |
111 |
t::lib::Mocks::mock_userenv( { branchcode => $item->homebranch } ); |
| 100 |
AddIssue( $patron, $item->barcode, dt_from_string ); |
112 |
warnings_are { |
| 101 |
AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); |
113 |
AddIssue( $patron, $item->barcode, dt_from_string ); |
| 102 |
my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next; |
114 |
} |
| 103 |
$pseudonymized = Koha::PseudonymizedTransactions->search( { itemnumber => $item->itemnumber } )->next; |
115 |
["Called"], "Background job enqueued when pseudonymization enabled"; |
| 104 |
like( $pseudonymized->hashed_borrowernumber, |
116 |
warnings_are { |
| 105 |
qr{^\$2a\$08\$}, "The hashed_borrowernumber must be a bcrypt hash" ); |
117 |
AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); |
|
|
118 |
} |
| 119 |
["Called"], "Background job enqueued when pseudonymization enabled"; |
| 120 |
|
| 121 |
my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next; |
| 122 |
my $pseudonymized = Koha::PseudonymizedTransaction->new_from_statistic($statistic); |
| 123 |
like( |
| 124 |
$pseudonymized->hashed_borrowernumber, |
| 125 |
qr{^\$2a\$08\$}, "The hashed_borrowernumber must be a bcrypt hash" |
| 126 |
); |
| 106 |
is( $pseudonymized->datetime, $statistic->datetime, 'datetime attribute copied correctly' ); |
127 |
is( $pseudonymized->datetime, $statistic->datetime, 'datetime attribute copied correctly' ); |
| 107 |
is( $pseudonymized->transaction_branchcode, $statistic->branch, 'transaction_branchcode copied correctly' ); |
128 |
is( $pseudonymized->transaction_branchcode, $statistic->branch, 'transaction_branchcode copied correctly' ); |
| 108 |
is( $pseudonymized->transaction_type, $statistic->type, 'transacttion_type copied correctly' ); |
129 |
is( $pseudonymized->transaction_type, $statistic->type, 'transaction_type copied correctly' ); |
| 109 |
is( $pseudonymized->itemnumber, $item->itemnumber, 'itemnumber copied correctly' ); |
130 |
is( $pseudonymized->itemnumber, $item->itemnumber, 'itemnumber copied correctly' ); |
| 110 |
is( $pseudonymized->itemtype, $item->effective_itemtype, 'itemtype copied correctly' ); |
131 |
is( $pseudonymized->itemtype, $item->effective_itemtype, 'itemtype copied correctly' ); |
| 111 |
is( $pseudonymized->holdingbranch, $item->holdingbranch, 'holdingbranch copied correctly' ); |
132 |
is( $pseudonymized->holdingbranch, $item->holdingbranch, 'holdingbranch copied correctly' ); |
|
Lines 125-134
subtest 'PseudonymizedBorrowerAttributes tests' => sub {
Link Here
|
| 125 |
|
146 |
|
| 126 |
t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); |
147 |
t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); |
| 127 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
148 |
t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); |
| 128 |
t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', |
149 |
t::lib::Mocks::mock_preference( |
| 129 |
'branchcode,categorycode,sort1' ); |
150 |
'PseudonymizationPatronFields', |
|
|
151 |
'branchcode,categorycode,sort1' |
| 152 |
); |
| 130 |
|
153 |
|
| 131 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
154 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 132 |
my $patron_info = $patron->unblessed; |
155 |
my $patron_info = $patron->unblessed; |
| 133 |
delete $patron_info->{borrowernumber}; |
156 |
delete $patron_info->{borrowernumber}; |
| 134 |
$patron->delete; |
157 |
$patron->delete; |
|
Lines 177-187
subtest 'PseudonymizedBorrowerAttributes tests' => sub {
Link Here
|
| 177 |
|
200 |
|
| 178 |
$patron->extended_attributes($attribute_values); |
201 |
$patron->extended_attributes($attribute_values); |
| 179 |
|
202 |
|
| 180 |
|
|
|
| 181 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
203 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 182 |
my $item = $builder->build_sample_item; |
204 |
my $item = $builder->build_sample_item; |
| 183 |
|
205 |
|
| 184 |
C4::Stats::UpdateStats( |
206 |
my $statistic = Koha::Statistic->new( |
| 185 |
{ |
207 |
{ |
| 186 |
type => 'issue', |
208 |
type => 'issue', |
| 187 |
branch => $library->branchcode, |
209 |
branch => $library->branchcode, |
|
Lines 193-203
subtest 'PseudonymizedBorrowerAttributes tests' => sub {
Link Here
|
| 193 |
} |
215 |
} |
| 194 |
); |
216 |
); |
| 195 |
|
217 |
|
| 196 |
my $p = Koha::PseudonymizedTransactions->search({itemnumber => $item->itemnumber})->next; |
218 |
my $p = Koha::PseudonymizedTransaction->new_from_statistic($statistic)->store; |
| 197 |
my $attributes = |
219 |
my $attributes = |
| 198 |
Koha::Database->new->schema->resultset('PseudonymizedBorrowerAttribute') |
220 |
Koha::Database->new->schema->resultset('PseudonymizedBorrowerAttribute') |
| 199 |
->search( { transaction_id => $p->id }, { order_by => 'attribute' } ); |
221 |
->search( { transaction_id => $p->id }, { order_by => 'attribute' } ); |
| 200 |
is( $attributes->count, 2, |
222 |
is( |
|
|
223 |
$attributes->count, 2, |
| 201 |
'Only the 2 attributes that have a type with keep_for_pseudonymization set should be kept' |
224 |
'Only the 2 attributes that have a type with keep_for_pseudonymization set should be kept' |
| 202 |
); |
225 |
); |
| 203 |
my $attribute_1 = $attributes->next; |
226 |
my $attribute_1 = $attributes->next; |
| 204 |
- |
|
|