Bug 42645: Add tests for FallbackToSMSIfNoEmail with alternate email fields

Verify that the SMS fallback in ModSuggestion() respects EmailFieldPrimary
and EmailFieldPrecedence: a patron with smsalertnumber and an emailpro
address (but no borrowers.email) must receive the notice by email, not SMS.

Sponsored-by: OpenFifth <https://openfifth.co.uk/>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Martin Renvoize 2026-05-19 16:49:35 +01:00 committed by Pedro Amorim
parent 57e110ee2c
commit 88fd58dd6c
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 43 additions and 1 deletions

View File

@ -19,7 +19,7 @@ use Modern::Perl;
use DateTime::Duration;
use Test::NoWarnings;
use Test::More tests => 49;
use Test::More tests => 51;
use Test::Warn;
use t::lib::Mocks;
@ -285,6 +285,48 @@ is(
'When FallbackToSMSIfNoEmail syspref is enabled the suggestion message_transport_type is email if the borrower has an email'
);
# Check that FallbackToSMSIfNoEmail respects notice_email_address, i.e. consults
# EmailFieldPrimary / EmailFieldPrecedence rather than only borrowers.email.
# A patron with no raw email but a populated alternate field must not fall back to SMS.
my $emailpro_patron = Koha::Patron->new(
{
firstname => 'Test',
surname => 'Emailpro',
categorycode => $patron_category->{categorycode},
branchcode => 'CPL',
smsalertnumber => 99999,
emailpro => 'emailpro@example.com',
}
)->store;
my $suggestion_for_emailpro_patron = Koha::Suggestion->new(
{
title => 'emailpro suggestion',
author => 'test author',
suggestedby => $emailpro_patron->borrowernumber,
biblionumber => $biblio_1->biblionumber,
branchcode => 'CPL',
note => 'test',
}
)->store;
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 1 );
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' );
ModSuggestion( { STATUS => 'CHECKED', suggestionid => $suggestion_for_emailpro_patron->id } );
my $emailpro_messages = C4::Letters::GetQueuedMessages( { borrowernumber => $emailpro_patron->borrowernumber } );
is(
$emailpro_messages->[0]->{message_transport_type}, 'email',
'FallbackToSMSIfNoEmail does not fall back to SMS when patron has emailpro set and EmailFieldPrimary=emailpro'
);
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', '' );
t::lib::Mocks::mock_preference( 'EmailFieldPrecedence', 'emailpro|email|B_email' );
ModSuggestion( { STATUS => 'ORDERED', suggestionid => $suggestion_for_emailpro_patron->id } );
$emailpro_messages = C4::Letters::GetQueuedMessages( { borrowernumber => $emailpro_patron->borrowernumber } );
is(
$emailpro_messages->[1]->{message_transport_type}, 'email',
'FallbackToSMSIfNoEmail does not fall back to SMS when patron has emailpro set and EmailFieldPrecedence includes emailpro'
);
# changing STATUS from ORDERED to CHECKED should generate a message
my $mod_suggestion5 = {
STATUS => 'CHECKED',