From 2d4a44eab908b72bba1fe51e4b917761c03743e2 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 | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Pseudonymization.t b/t/db_dependent/Koha/Pseudonymization.t index a87a16ac2c..b5297f3dc5 100644 --- a/t/db_dependent/Koha/Pseudonymization.t +++ b/t/db_dependent/Koha/Pseudonymization.t @@ -19,7 +19,8 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; +use Try::Tiny; use C4::Circulation; @@ -35,6 +36,31 @@ use t::lib::Mocks; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; +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 $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $patron_info = $patron->unblessed; + delete $patron_info->{borrowernumber}; + $patron->delete; + + try{ + $patron = Koha::Patron->new($patron_info)->store; + } 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::Patrons tests' => sub { plan tests => 9; -- 2.11.0