From 9312a28e0265c6116dd0e8808421146508ad6310 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 --- 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 6007589ae9..f04bb1404b 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 => 21; +use Test::More tests => 23; use Test::Exception; use Test::Warn; @@ -1351,6 +1351,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.40.0