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