Bug 42723: Purchase suggestion 500 when EmailPurchaseSuggestions is set to BranchEmailAddress
Testing plan: - Set EmailPurchaseSuggestions to BranchEmailAddress - Go to create suggestion on the staff side /suggestion/suggestion.pl?op=add_form - Create a suggestion with Library: Any - 500 error: inbound_email_address is not a method of undef - Apply patch & repeat - Suggestion created Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
d6f1bdbe63
commit
9c994035fe
|
|
@ -103,8 +103,12 @@ sub store {
|
|||
|
||||
my $toaddress;
|
||||
if ( $emailpurchasesuggestions eq "BranchEmailAddress" ) {
|
||||
|
||||
# can be undef for branch=any suggestions
|
||||
my $library = $result->library;
|
||||
if ( $library && $library->inbound_email_address ) {
|
||||
$toaddress = $library->inbound_email_address;
|
||||
}
|
||||
} elsif ( $emailpurchasesuggestions eq "KohaAdminEmailAddress" ) {
|
||||
$toaddress = C4::Context->preference('ReplytoDefault')
|
||||
|| C4::Context->preference('KohaAdminEmailAddress');
|
||||
|
|
|
|||
|
|
@ -472,7 +472,7 @@ subtest 'DelSuggestionsOlderThan' => sub {
|
|||
};
|
||||
|
||||
subtest 'EmailPurchaseSuggestions' => sub {
|
||||
plan tests => 11;
|
||||
plan tests => 13;
|
||||
|
||||
$dbh->do(q|DELETE FROM message_queue|);
|
||||
|
||||
|
|
@ -533,6 +533,21 @@ subtest 'EmailPurchaseSuggestions' => sub {
|
|||
'BranchEmailAddress uses branchreplyto in preference to branchemail when set'
|
||||
);
|
||||
|
||||
my $branchless_suggestion = { %{$my_suggestion}, branchcode => undef };
|
||||
t::lib::Mocks::mock_preference( "ReplytoDefault", undef );
|
||||
|
||||
# must eval to test itself dying, then check $@ for error
|
||||
eval { Koha::Suggestion->new($branchless_suggestion)->store; };
|
||||
is( $@, '', 'BranchEmailAddress does not die when suggestion has no library branch' );
|
||||
|
||||
$newsuggestions_messages = C4::Letters::GetQueuedMessages( { letter_code => 'NEW_SUGGESTION' } );
|
||||
my $message_branchless =
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[4]->{message_id} );
|
||||
is(
|
||||
$message_branchless->{to_address}, undef,
|
||||
'BranchEmailAddress sets no to_address when suggestion has no branch'
|
||||
);
|
||||
|
||||
# EmailPurchaseSuggestions set to KohaAdminEmailAddress
|
||||
t::lib::Mocks::mock_preference(
|
||||
"EmailPurchaseSuggestions",
|
||||
|
|
@ -547,13 +562,13 @@ subtest 'EmailPurchaseSuggestions' => sub {
|
|||
|
||||
$newsuggestions_messages = C4::Letters::GetQueuedMessages( { letter_code => 'NEW_SUGGESTION' } );
|
||||
my $message5 =
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[4]->{message_id} );
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[5]->{message_id} );
|
||||
is(
|
||||
$message5->{to_address},
|
||||
'noreply@hosting.com', 'KohaAdminEmailAddress uses KohaAdminEmailAddress when ReplytoDefault is not set'
|
||||
);
|
||||
my $message6 =
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[5]->{message_id} );
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[6]->{message_id} );
|
||||
is(
|
||||
$message6->{to_address},
|
||||
'library@b.c', 'KohaAdminEmailAddress uses ReplytoDefualt when ReplytoDefault is set'
|
||||
|
|
@ -579,7 +594,7 @@ subtest 'EmailPurchaseSuggestions' => sub {
|
|||
|
||||
$newsuggestions_messages = C4::Letters::GetQueuedMessages( { letter_code => 'NEW_SUGGESTION' } );
|
||||
my $message7 =
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[6]->{message_id} );
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[7]->{message_id} );
|
||||
is(
|
||||
$message7->{to_address},
|
||||
'noreply@hosting.com',
|
||||
|
|
@ -587,14 +602,14 @@ subtest 'EmailPurchaseSuggestions' => sub {
|
|||
);
|
||||
|
||||
my $message8 =
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[7]->{message_id} );
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[8]->{message_id} );
|
||||
is(
|
||||
$message8->{to_address},
|
||||
'library@b.c', 'EmailAddressForSuggestions uses ReplytoDefault when EmailAddressForSuggestions is not set'
|
||||
);
|
||||
|
||||
my $message9 =
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[8]->{message_id} );
|
||||
C4::Letters::GetMessage( $newsuggestions_messages->[9]->{message_id} );
|
||||
is(
|
||||
$message9->{to_address},
|
||||
'suggestions@b.c', 'EmailAddressForSuggestions uses EmailAddressForSuggestions when set'
|
||||
|
|
|
|||
Loading…
Reference in New Issue