|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 1; |
20 |
use Test::MockModule; |
|
|
21 |
use Test::More tests => 2; |
| 22 |
use Test::Warn; |
| 21 |
|
23 |
|
| 22 |
use Koha::DateUtils qw(dt_from_string); |
24 |
use Koha::DateUtils qw(dt_from_string); |
| 23 |
use Koha::Statistics; |
25 |
use Koha::Statistics; |
|
Lines 56-58
subtest 'new() tests' => sub {
Link Here
|
| 56 |
|
58 |
|
| 57 |
$schema->storage->txn_rollback; |
59 |
$schema->storage->txn_rollback; |
| 58 |
}; |
60 |
}; |
| 59 |
- |
61 |
|
|
|
62 |
subtest 'pseudonymize() tests' => sub { |
| 63 |
|
| 64 |
my @pseudonymization_types = qw(renew issue return onsite_checkout); |
| 65 |
plan tests => scalar(@pseudonymization_types) + 2; |
| 66 |
|
| 67 |
$schema->storage->txn_begin; |
| 68 |
|
| 69 |
my $not_type = 'not_gonna_pseudo'; |
| 70 |
|
| 71 |
my $pseudo_background = Test::MockModule->new('Koha::BackgroundJob::PseudonymizeStatistic'); |
| 72 |
$pseudo_background->mock( enqueue => sub { warn "Called" } ); |
| 73 |
|
| 74 |
my @statistics = (); |
| 75 |
|
| 76 |
ok( scalar(@pseudonymization_types) > 0, 'some pseudonymization_types are defined' ); |
| 77 |
|
| 78 |
my $sub_days = 0; # TestBuilder does not handle many rows of Koha::Statistics very intuitively |
| 79 |
foreach my $type (@pseudonymization_types) { |
| 80 |
push( |
| 81 |
@statistics, |
| 82 |
$builder->build_object( |
| 83 |
{ |
| 84 |
class => 'Koha::Statistics', |
| 85 |
value => { |
| 86 |
datetime => $dtf->format_datetime( dt_from_string()->subtract( days => $sub_days ) ), |
| 87 |
type => $type, |
| 88 |
}, |
| 89 |
} |
| 90 |
) |
| 91 |
); |
| 92 |
$sub_days++; |
| 93 |
} |
| 94 |
|
| 95 |
push( |
| 96 |
@statistics, |
| 97 |
$builder->build_object( |
| 98 |
{ |
| 99 |
class => 'Koha::Statistics', |
| 100 |
value => { |
| 101 |
datetime => $dtf->format_datetime( dt_from_string()->subtract( days => 7 ) ), |
| 102 |
type => $not_type, |
| 103 |
}, |
| 104 |
} |
| 105 |
) |
| 106 |
); |
| 107 |
|
| 108 |
foreach my $statistic (@statistics) { |
| 109 |
my $type = $statistic->type; |
| 110 |
if ( $type ne $not_type ) { |
| 111 |
warnings_are { |
| 112 |
$statistic->pseudonymize(); |
| 113 |
} |
| 114 |
["Called"], "Background job enqueued for type $type"; |
| 115 |
} else { |
| 116 |
warnings_are { |
| 117 |
$statistic->pseudonymize(); |
| 118 |
} |
| 119 |
undef, "Background job not enqueued for type $type"; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
$schema->storage->txn_rollback; |
| 124 |
}; |