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

(-)a/t/db_dependent/Koha/Pseudonymization.t (-2 / +50 lines)
Lines 19-28 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
24
use C4::Circulation;
23
25
24
use Koha::Database;
26
use Koha::Database;
27
use Koha::DateUtils qw( dt_from_string );
25
use Koha::Patrons;
28
use Koha::Patrons;
29
use Koha::Anonymized::Patrons;
30
use Koha::Anonymized::Transactions;
26
31
27
use t::lib::TestBuilder;
32
use t::lib::TestBuilder;
28
use t::lib::Mocks;
33
use t::lib::Mocks;
Lines 69-71 subtest 'Koha::Anonymized::Patrons tests' => sub { Link Here
69
74
70
    $schema->storage->txn_rollback;
75
    $schema->storage->txn_rollback;
71
};
76
};
72
- 
77
78
subtest 'Koha::Anonymized::Transactions tests' => sub {
79
80
    plan tests => 11;
81
82
    $schema->storage->txn_begin;
83
84
    t::lib::Mocks::mock_config( 'key', '$2a$08$9lmorEKnwQloheaCLFIfje' );
85
86
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
87
88
    t::lib::Mocks::mock_preference( 'Pseudonymization', 0 );
89
    my $item = $builder->build_sample_item;
90
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
91
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string );
92
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
93
    my $anonymized = Koha::Anonymized::Transactions->search(
94
        { itemnumber => $item->itemnumber } )->next;
95
    is( $anonymized, undef,
96
        'No anonymized transaction if Pseudonymization is off' );
97
98
    t::lib::Mocks::mock_preference( 'Pseudonymization', 1 );
99
    t::lib::Mocks::mock_preference( 'PseudonymizationTransactionFields', 'datetime,branchcode,transaction_type,itemnumber,itemtype,holdingbranch,location,itemcallnumber,ccode'
100
    );
101
    $item = $builder->build_sample_item;
102
    t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch });
103
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string );
104
    AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string );
105
    my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next;
106
    $anonymized = Koha::Anonymized::Transactions->search( { itemnumber => $item->itemnumber } )->next;
107
    like( $anonymized->hashed_borrowernumber,
108
        qr{^\$2a\$08\$}, "The hashed_borrowernumber must be a bcrypt hash" );
109
    is( $anonymized->datetime,         $statistic->datetime );
110
    is( $anonymized->branchcode,       $statistic->branch );
111
    is( $anonymized->transaction_type, $statistic->type );
112
    is( $anonymized->itemnumber,       $item->itemnumber );
113
    is( $anonymized->itemtype,         $item->effective_itemtype );
114
    is( $anonymized->holdingbranch,    $item->holdingbranch );
115
    is( $anonymized->location,         $item->location );
116
    is( $anonymized->itemcallnumber,   $item->itemcallnumber );
117
    is( $anonymized->ccode,            $item->ccode );
118
119
    $schema->storage->txn_rollback;
120
};

Return to bug 24151