From eb07581e365fb09b154136e3f48f58c298856960 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 30 Nov 2019 12:48:04 +0100 Subject: [PATCH] Bug 24151: Add tests - if config does not exist Sponsored-by: Association KohaLa - https://koha-fr.org/ --- t/db_dependent/Koha/Pseudonymization.t | 40 ++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/Pseudonymization.t b/t/db_dependent/Koha/Pseudonymization.t index 99f6e2d40c..6c8031224b 100644 --- a/t/db_dependent/Koha/Pseudonymization.t +++ b/t/db_dependent/Koha/Pseudonymization.t @@ -19,9 +19,11 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; +use Try::Tiny; use C4::Circulation; +use C4::Stats; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); @@ -34,7 +36,41 @@ use t::lib::Mocks; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; -subtest 'Koha::PseudonymizedTransactions tests' => sub { +subtest 'Config does not exist' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + t::lib::Mocks::mock_config( 'key', '' ); + t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); + t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' ); + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $item = $builder->build_sample_item; + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + try{ + C4::Stats::UpdateStats( + { + type => 'issue', + branch => 'BBB', + itemnumber => $item->itemnumber, + borrowernumber => $patron->borrowernumber, + itemtype => $item->effective_itemtype, + location => $item->location, + } + ); + + } catch { + ok($_->isa('Koha::Exceptions::Config::MissingEntry'), "Koha::Patron->store should raise a Koha::Exceptions::Config::MissingEntry if 'key' is not defined in the config"); + is( $_->message, "Missing 'key' entry in config file"); + }; + + $schema->storage->txn_rollback; +}; + +subtest 'Koha::Anonymized::Transactions tests' => sub { plan tests => 11; -- 2.11.0