View | Details | Raw Unified | Return to bug 37182
Collapse All | Expand All

(-)a/t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t (-11 / +23 lines)
Lines 21-26 use Test::More tests => 2; Link Here
21
use Test::Exception;
21
use Test::Exception;
22
22
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::DateUtils qw(dt_from_string);
24
use Koha::BackgroundJobs;
25
use Koha::BackgroundJobs;
25
use Koha::BackgroundJob::PseudonymizeStatistic;
26
use Koha::BackgroundJob::PseudonymizeStatistic;
26
27
Lines 29-34 use t::lib::TestBuilder; Link Here
29
30
30
my $schema  = Koha::Database->new->schema;
31
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
my $builder = t::lib::TestBuilder->new;
33
my $dtf     = $schema->storage->datetime_parser;
32
34
33
subtest 'enqueue() tests' => sub {
35
subtest 'enqueue() tests' => sub {
34
36
Lines 65-93 subtest 'enqueue() tests' => sub { Link Here
65
67
66
subtest 'process() tests' => sub {
68
subtest 'process() tests' => sub {
67
69
68
    plan tests => 2;
70
    plan tests => 3;
69
71
70
    $schema->storage->txn_begin;
72
    $schema->storage->txn_begin;
71
73
72
    t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' );
74
    t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' );
73
    t::lib::Mocks::mock_preference( 'Pseudonymization',             1 );
75
    t::lib::Mocks::mock_preference( 'Pseudonymization',                  1 );
74
    t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' );
76
    t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields',      'branchcode,categorycode,sort1' );
77
    t::lib::Mocks::mock_preference( 'PseudonymizationTransactionFields', 'datetime' );
75
78
76
    my $patron    = $builder->build_object( { class => 'Koha::Patrons' } );
79
    my $patron    = $builder->build_object( { class => 'Koha::Patrons' } );
77
    my $item      = $builder->build_sample_item();
80
    my $item      = $builder->build_sample_item();
78
    my $statistic = $builder->build_object(
81
    my $statistic = $builder->build_object(
79
        {
82
        {
80
            class => 'Koha::Statistics',
83
            class => 'Koha::Statistics',
81
            value => { type => 'issue', borrowernumber => $patron->id, itemnumber => $item->id }
84
            value => {
85
                borrowernumber => $patron->id,
86
                datetime       => $dtf->format_datetime( dt_from_string()->subtract( days => 7 ) ),
87
                itemnumber     => $item->id,
88
                type           => 'issue',
89
            }
82
        }
90
        }
83
    );
91
    )->unblessed;
84
92
85
    my $job_id = Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $statistic->unblessed } );
93
    my $job_id          = Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $statistic } );
86
    my $pseudonymized_transactions_before = Koha::PseudonymizedTransactions->search()->count();
94
    my $pt_count_before = Koha::PseudonymizedTransactions->search()->count();
87
    my $job                               = Koha::BackgroundJobs->find($job_id)->_derived_class;
95
88
    $job->process( { statistic => $statistic->unblessed } );
96
    my $job = Koha::BackgroundJobs->find($job_id)->_derived_class;
89
    my $pseudonymized_transactions_after = Koha::PseudonymizedTransactions->search()->count();
97
    $job->process( { statistic => $statistic } );
90
    is( $pseudonymized_transactions_after, $pseudonymized_transactions_before + 1, "Pseudonymized transaction added" );
98
99
    my $pt_after = Koha::PseudonymizedTransactions->search();
100
    is( $pt_after->count, $pt_count_before + 1, "Pseudonymized transaction added" );
101
102
    is( $statistic->{datetime}, $pt_after->last->datetime, "'datetime' column preserved" );
91
103
92
    $job->discard_changes;
104
    $job->discard_changes;
93
    is( $job->data, '{"data":""}', "Job data cleared after pseudonymization" );
105
    is( $job->data, '{"data":""}', "Job data cleared after pseudonymization" );
(-)a/t/db_dependent/Koha/Statistic.t (-1 / +58 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
22
use Koha::DateUtils qw(dt_from_string);
23
use Koha::Statistics;
24
use Koha::Database;
25
26
use t::lib::TestBuilder;
27
28
my $builder = t::lib::TestBuilder->new;
29
my $schema  = Koha::Database->new->schema;
30
my $dtf     = $schema->storage->datetime_parser;
31
32
subtest 'new() tests' => sub {
33
34
    plan tests => 3;
35
36
    $schema->storage->txn_begin;
37
38
    my $statistic = $builder->build_object(
39
        {
40
            class => 'Koha::Statistics',
41
            value => {
42
                datetime => $dtf->format_datetime( dt_from_string()->subtract( days => 7 ) ),
43
                type     => 'issue',
44
            },
45
        }
46
    )->unblessed;
47
48
    my $new_statistic = Koha::Statistic->new($statistic);
49
    is( $new_statistic->datetime, $statistic->{datetime}, "Passed 'datetime' is preserved" );
50
51
    delete $statistic->{datetime};
52
    is( $statistic->{datetime}, undef, "'datetime' not present (check)" );
53
54
    $new_statistic = Koha::Statistic->new($statistic);
55
    ok( defined $new_statistic->datetime, "'datetime' calculated if not passed" );
56
57
    $schema->storage->txn_rollback;
58
};

Return to bug 37182