From 5d4f3af21619f2185d8253e34d2c6a6ceccc7888 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 26 Nov 2019 19:45:33 +0100 Subject: [PATCH] Bug 24151: Add tests for transactions Sponsored-by: Association KohaLa - https://koha-fr.org/ --- t/db_dependent/Koha/Pseudonymization.t | 51 +++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Pseudonymization.t b/t/db_dependent/Koha/Pseudonymization.t index 7c8140cee4..a87a16ac2c 100644 --- a/t/db_dependent/Koha/Pseudonymization.t +++ b/t/db_dependent/Koha/Pseudonymization.t @@ -19,10 +19,15 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; + +use C4::Circulation; use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); use Koha::Patrons; +use Koha::Anonymized::Patrons; +use Koha::Anonymized::Transactions; use t::lib::TestBuilder; use t::lib::Mocks; @@ -69,3 +74,47 @@ subtest 'Koha::Anonymized::Patrons tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'Koha::Anonymized::Transactions tests' => sub { + + plan tests => 11; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_config( 'key', '$2a$08$9lmorEKnwQloheaCLFIfje' ); + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + t::lib::Mocks::mock_preference( 'Pseudonymization', 0 ); + my $item = $builder->build_sample_item; + t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch }); + AddIssue( $patron->unblessed, $item->barcode, dt_from_string ); + AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); + my $anonymized = Koha::Anonymized::Transactions->search( + { itemnumber => $item->itemnumber } )->next; + is( $anonymized, undef, + 'No anonymized transaction if Pseudonymization is off' ); + + t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); + t::lib::Mocks::mock_preference( 'PseudonymizationTransactionFields', 'datetime,branchcode,transaction_type,itemnumber,itemtype,holdingbranch,location,itemcallnumber,ccode' + ); + $item = $builder->build_sample_item; + t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch }); + AddIssue( $patron->unblessed, $item->barcode, dt_from_string ); + AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); + my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next; + $anonymized = Koha::Anonymized::Transactions->search( { itemnumber => $item->itemnumber } )->next; + like( $anonymized->hashed_borrowernumber, + qr{^\$2a\$08\$}, "The hashed_borrowernumber must be a bcrypt hash" ); + is( $anonymized->datetime, $statistic->datetime ); + is( $anonymized->branchcode, $statistic->branch ); + is( $anonymized->transaction_type, $statistic->type ); + is( $anonymized->itemnumber, $item->itemnumber ); + is( $anonymized->itemtype, $item->effective_itemtype ); + is( $anonymized->holdingbranch, $item->holdingbranch ); + is( $anonymized->location, $item->location ); + is( $anonymized->itemcallnumber, $item->itemcallnumber ); + is( $anonymized->ccode, $item->ccode ); + + $schema->storage->txn_rollback; +}; -- 2.11.0