From 3227a0b9640ff48c1ed94421ae8a4b84d9931788 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 26 Nov 2019 17:40:15 +0100 Subject: [PATCH] Bug 24151: Add tests Sponsored-by: Association KohaLa - https://koha-fr.org/ Signed-off-by: Signed-off-by: Sonia Bouis --- t/db_dependent/Koha/Pseudonymization.t | 79 ++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 t/db_dependent/Koha/Pseudonymization.t diff --git a/t/db_dependent/Koha/Pseudonymization.t b/t/db_dependent/Koha/Pseudonymization.t new file mode 100644 index 0000000000..99f6e2d40c --- /dev/null +++ b/t/db_dependent/Koha/Pseudonymization.t @@ -0,0 +1,79 @@ +#!/usr/bin/perl + +# Copyright 2019 Koha Development team +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 1; + +use C4::Circulation; + +use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); +use Koha::Patrons; +use Koha::PseudonymizedTransactions; + +use t::lib::TestBuilder; +use t::lib::Mocks; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'Koha::PseudonymizedTransactions 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 $pseudonymized= Koha::PseudonymizedTransactions->search( + { itemnumber => $item->itemnumber } )->next; + is( $pseudonymized, undef, + 'No pseudonymized transaction if Pseudonymization is off' ); + + t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); + t::lib::Mocks::mock_preference( 'PseudonymizationTransactionFields', 'datetime,transaction_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; + $pseudonymized = Koha::PseudonymizedTransactions->search( { itemnumber => $item->itemnumber } )->next; + like( $pseudonymized->hashed_borrowernumber, + qr{^\$2a\$08\$}, "The hashed_borrowernumber must be a bcrypt hash" ); + is( $pseudonymized->datetime, $statistic->datetime ); + is( $pseudonymized->transaction_branchcode, $statistic->branch ); + is( $pseudonymized->transaction_type, $statistic->type ); + is( $pseudonymized->itemnumber, $item->itemnumber ); + is( $pseudonymized->itemtype, $item->effective_itemtype ); + is( $pseudonymized->holdingbranch, $item->holdingbranch ); + is( $pseudonymized->location, $item->location ); + is( $pseudonymized->itemcallnumber, $item->itemcallnumber ); + is( $pseudonymized->ccode, $item->ccode ); + + $schema->storage->txn_rollback; +}; -- 2.20.1