From 2a9c6db3385b025f18b382458f95d72e1c47dd97 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 20 Apr 2023 14:18:20 +0100 Subject: [PATCH] Bug 29046: Unit tests Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Patron.t | 28 +++++++++++++++++++++++++++- t/db_dependent/Koha/Patrons.t | 16 +--------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 3568a3ac8c..5d05a16efd 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 22; +use Test::More tests => 24; use Test::Exception; use Test::Warn; @@ -1393,6 +1393,32 @@ subtest 'notify_library_of_registration()' => sub { $schema->storage->txn_rollback; }; +subtest 'notice_email_address' => sub { + plan tests => 2; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + + t::lib::Mocks::mock_preference( 'EmailFieldPrecedence', 'email|emailpro' ); + t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' ); + is ($patron->notice_email_address, $patron->email, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is off"); + + t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' ); + is ($patron->notice_email_address, $patron->emailpro, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is emailpro"); + + $patron->delete; +}; + +subtest 'first_valid_email_address' => sub { + plan tests => 1; + + my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { emailpro => ''}}); + + t::lib::Mocks::mock_preference( 'EmailFieldPrecedence', 'emailpro|email' ); + is ($patron->first_valid_email_address, $patron->email, "Koha::Patron->first_valid_email_address returns correct value when EmailFieldPrecedence is 'emailpro|email' and emailpro is empty"); + + $patron->delete; +}; + subtest 'get_savings tests' => sub { plan tests => 4; diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 187b18c379..567ff118dd 100755 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 44; +use Test::More tests => 43; use Test::Warn; use Test::Exception; use Test::MockModule; @@ -1061,20 +1061,6 @@ subtest 'holds and old_holds' => sub { $patron->delete; }; -subtest 'notice_email_address' => sub { - plan tests => 2; - - my $patron = $builder->build_object({ class => 'Koha::Patrons' }); - - t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' ); - is ($patron->notice_email_address, $patron->email, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is off"); - - t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' ); - is ($patron->notice_email_address, $patron->emailpro, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is emailpro"); - - $patron->delete; -}; - subtest 'search_patrons_to_anonymise' => sub { plan tests => 5; -- 2.20.1