From b16d43394376bdcfbcaaaf2f5543567c3aec9771 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 25 Feb 2020 07:36:12 +0000 Subject: [PATCH] Bug 22823: Add unit tests for get_effective_email This patch adds unit tests for the newly introduced get_effective_email method in the Koha::Library class. Signed-off-by: Bernardo Gonzalez Kriegel Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- t/db_dependent/Koha/Libraries.t | 39 ++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Libraries.t b/t/db_dependent/Koha/Libraries.t index 7c3cd78eff..874b3a316b 100644 --- a/t/db_dependent/Koha/Libraries.t +++ b/t/db_dependent/Koha/Libraries.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 9; +use Test::More tests => 10; use C4::Biblio; use C4::Context; @@ -452,6 +452,43 @@ subtest '->get_effective_marcorgcode' => sub { $schema->storage->txn_rollback; }; +subtest '->get_effective_email' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $library_1 = $builder->build_object( + { + class => 'Koha::Libraries', + value => { + branchemail => 'from@mybranc.com', + branchreplyto => 'reply@mybranch.com' + } + } + ); + + t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'admin@mylibrary.com' ); + t::lib::Mocks::mock_preference( 'ReplytoDefault', 'reply@mylibrary.com' ); + + is( $library_1->get_effective_email, $library_1->branchreplyto, + 'If defined, use branches replyto address'); + + $library_1->branchreplyto(undef)->store(); + is( $library_1->get_effective_email, $library_1->branchemail, + 'Fallback to branches email address when branchreplyto is undefined'); + + $library_1->branchemail(undef)->store(); + is( $library_1->get_effective_email, 'reply@mylibrary.com', + 'Fallback to ReplytoDefault email address when branchreplyto and branchemail are undefined'); + + t::lib::Mocks::mock_preference( 'ReplytoDefault', undef ); + is( $library_1->get_effective_email, 'admin@mylibrary.com', + 'Fallback to KohaAdminEmailAddress email address when branchreplyto, branchemail and eplytoDefault are undefined'); + + $schema->storage->txn_rollback; +}; + subtest 'cash_registers' => sub { plan tests => 3; -- 2.39.5