|
Lines 137-142
is(
Link Here
|
| 137 |
'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)' |
137 |
'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)' |
| 138 |
); |
138 |
); |
| 139 |
|
139 |
|
|
|
140 |
#Test guarantee-guarantor email redirection |
| 141 |
my ($GUARANTEE_EMAIL, $GUARANTOR_EMAIL) = qw| guarantee@example.com guarantor@example.com |; |
| 142 |
my $guarantor = { |
| 143 |
email => $GUARANTOR_EMAIL, |
| 144 |
categorycode => 'PT', |
| 145 |
branchcode => 'CPL', |
| 146 |
surname => "Guarantor" |
| 147 |
}; |
| 148 |
$guarantor->{'borrowernumber'} = AddMember(%$guarantor); |
| 149 |
my $guarantee = { |
| 150 |
guarantorid => $guarantor->{'borrowernumber'}, |
| 151 |
email => $GUARANTEE_EMAIL, |
| 152 |
categorycode => 'PT', |
| 153 |
branchcode => 'CPL', |
| 154 |
surname => "Guarantee" |
| 155 |
}; |
| 156 |
$guarantee->{'borrowernumber'} = AddMember(%$guarantee); |
| 157 |
|
| 158 |
my $GUARANTEE_TO_ADDRESS = 'toto@exemple.com'; |
| 159 |
my $guarantee_message = { |
| 160 |
borrowernumber => $guarantee->{'borrowernumber'}, |
| 161 |
message_transport_type => 'email', |
| 162 |
to_address => $GUARANTEE_TO_ADDRESS, |
| 163 |
from_address => 'from@example.com', |
| 164 |
letter => $my_message->{'letter'} |
| 165 |
}; |
| 166 |
|
| 167 |
sub SendToGuarantor { |
| 168 |
my ($useGuarantor, $message) = @_; |
| 169 |
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' ); |
| 170 |
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', $useGuarantor ); |
| 171 |
C4::Context->clear_syspref_cache(); |
| 172 |
my $id = C4::Letters::EnqueueLetter($message); |
| 173 |
C4::Letters::SendQueuedMessages(); |
| 174 |
my $result = $dbh->selectrow_hashref( 'SELECT to_address, status FROM message_queue WHERE message_id = ?', undef, ($id) ); |
| 175 |
return $result; |
| 176 |
} |
| 177 |
my $result = SendToGuarantor(0,$guarantee_message); |
| 178 |
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail off, message is sent."); |
| 179 |
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail off, Message is sent to the specified to_address."); |
| 180 |
|
| 181 |
$result = SendToGuarantor(1,$guarantee_message); |
| 182 |
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail on, message is sent."); |
| 183 |
is($result->{'to_address'}, $GUARANTOR_EMAIL, "With EnableRedirectGuaranteeEmail on, Message is sent to the guarantor's email address."); |
| 184 |
|
| 185 |
$guarantor->{'email'} = undef; |
| 186 |
ModMember(%$guarantor); |
| 187 |
$result = SendToGuarantor(1,$guarantee_message); |
| 188 |
is($result->{'status'}, "failed", "With EnableRedirectGuaranteeEmail on, message fails if guarantor has no address."); |
| 189 |
|
| 190 |
$guarantee->{'guarantorid'} = undef; |
| 191 |
ModMember(%$guarantee); |
| 192 |
$result = SendToGuarantor(1,$guarantee_message); |
| 193 |
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail on, Message is sent to specicied to_address if he has no guarantor."); |
| 194 |
|
| 140 |
# GetLetters |
195 |
# GetLetters |
| 141 |
my $letters = C4::Letters::GetLetters(); |
196 |
my $letters = C4::Letters::GetLetters(); |
| 142 |
is( @$letters, 0, 'GetLetters returns the correct number of letters' ); |
197 |
is( @$letters, 0, 'GetLetters returns the correct number of letters' ); |