Lines 148-153
is( $resent, 0, 'The message should not have been resent again' );
Link Here
|
148 |
$resent = C4::Letters::ResendMessage(); |
148 |
$resent = C4::Letters::ResendMessage(); |
149 |
is( $resent, undef, 'ResendMessage should return undef if not message_id given' ); |
149 |
is( $resent, undef, 'ResendMessage should return undef if not message_id given' ); |
150 |
|
150 |
|
|
|
151 |
#Test guarantee-guarantor email redirection |
152 |
my ($GUARANTEE_EMAIL, $GUARANTOR_EMAIL) = qw| guarantee@example.com guarantor@example.com |; |
153 |
my $guarantor = { |
154 |
email => $GUARANTOR_EMAIL, |
155 |
categorycode => 'PT', |
156 |
branchcode => 'CPL', |
157 |
surname => "Guarantor" |
158 |
}; |
159 |
$guarantor->{'borrowernumber'} = AddMember(%$guarantor); |
160 |
my $guarantee = { |
161 |
guarantorid => $guarantor->{'borrowernumber'}, |
162 |
email => $GUARANTEE_EMAIL, |
163 |
categorycode => 'PT', |
164 |
branchcode => 'CPL', |
165 |
surname => "Guarantee" |
166 |
}; |
167 |
$guarantee->{'borrowernumber'} = AddMember(%$guarantee); |
168 |
|
169 |
my $GUARANTEE_TO_ADDRESS = 'toto@exemple.com'; |
170 |
my $guarantee_message = { |
171 |
borrowernumber => $guarantee->{'borrowernumber'}, |
172 |
message_transport_type => 'email', |
173 |
to_address => $GUARANTEE_TO_ADDRESS, |
174 |
from_address => 'from@example.com', |
175 |
letter => $my_message->{'letter'} |
176 |
}; |
177 |
|
178 |
sub SendToGuarantor { |
179 |
my ($useGuarantor, $message) = @_; |
180 |
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' ); |
181 |
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', $useGuarantor ); |
182 |
C4::Context->clear_syspref_cache(); |
183 |
my $id = C4::Letters::EnqueueLetter($message); |
184 |
C4::Letters::SendQueuedMessages(); |
185 |
my $result = $dbh->selectrow_hashref( 'SELECT to_address, status FROM message_queue WHERE message_id = ?', undef, ($id) ); |
186 |
return $result; |
187 |
} |
188 |
my $result = SendToGuarantor(0,$guarantee_message); |
189 |
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail off, message is sent."); |
190 |
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail off, Message is sent to the specified to_address."); |
191 |
|
192 |
$result = SendToGuarantor(1,$guarantee_message); |
193 |
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail on, message is sent."); |
194 |
is($result->{'to_address'}, $GUARANTOR_EMAIL, "With EnableRedirectGuaranteeEmail on, Message is sent to the guarantor's email address."); |
195 |
|
196 |
$guarantor->{'email'} = undef; |
197 |
ModMember(%$guarantor); |
198 |
$result = SendToGuarantor(1,$guarantee_message); |
199 |
is($result->{'status'}, "failed", "With EnableRedirectGuaranteeEmail on, message fails if guarantor has no address."); |
200 |
|
201 |
$guarantee->{'guarantorid'} = undef; |
202 |
ModMember(%$guarantee); |
203 |
$result = SendToGuarantor(1,$guarantee_message); |
204 |
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail on, Message is sent to specicied to_address if he has no guarantor."); |
205 |
|
151 |
# GetLetters |
206 |
# GetLetters |
152 |
my $letters = C4::Letters::GetLetters(); |
207 |
my $letters = C4::Letters::GetLetters(); |
153 |
is( @$letters, 0, 'GetLetters returns the correct number of letters' ); |
208 |
is( @$letters, 0, 'GetLetters returns the correct number of letters' ); |