Lines 149-172
$resent = C4::Letters::ResendMessage();
Link Here
|
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 |
151 |
#Test guarantee-guarantor email redirection |
|
|
152 |
$library = $builder->build({ |
153 |
source => 'Branch', |
154 |
}); |
152 |
my ($GUARANTEE_EMAIL, $GUARANTOR_EMAIL) = qw| guarantee@example.com guarantor@example.com |; |
155 |
my ($GUARANTEE_EMAIL, $GUARANTOR_EMAIL) = qw| guarantee@example.com guarantor@example.com |; |
|
|
156 |
my $guarantor_category = $builder->build({ source => 'Category' }); |
153 |
my $guarantor = { |
157 |
my $guarantor = { |
154 |
email => $GUARANTOR_EMAIL, |
158 |
email => $GUARANTOR_EMAIL, |
155 |
categorycode => 'PT', |
159 |
categorycode => $guarantor_category, |
156 |
branchcode => 'CPL', |
160 |
branchcode => $library->{branchcode}, |
157 |
surname => "Guarantor" |
161 |
surname => "Guarantor" |
158 |
}; |
162 |
}; |
159 |
$guarantor->{'borrowernumber'} = AddMember(%$guarantor); |
163 |
$guarantor->{'borrowernumber'} = AddMember(%$guarantor); |
160 |
my $guarantee = { |
164 |
my $guarantee = { |
161 |
guarantorid => $guarantor->{'borrowernumber'}, |
165 |
guarantorid => $guarantor->{'borrowernumber'}, |
162 |
email => $GUARANTEE_EMAIL, |
166 |
email => $GUARANTEE_EMAIL, |
163 |
categorycode => 'PT', |
167 |
categorycode => $guarantor_category, |
164 |
branchcode => 'CPL', |
168 |
branchcode => $library->{branchcode}, |
165 |
surname => "Guarantee" |
169 |
surname => "Guarantee" |
166 |
}; |
170 |
}; |
167 |
$guarantee->{'borrowernumber'} = AddMember(%$guarantee); |
171 |
$guarantee->{'borrowernumber'} = AddMember(%$guarantee); |
168 |
|
172 |
|
169 |
my $GUARANTEE_TO_ADDRESS = 'toto@exemple.com'; |
173 |
my $GUARANTEE_TO_ADDRESS = 'guarantor@example.com'; |
170 |
my $guarantee_message = { |
174 |
my $guarantee_message = { |
171 |
borrowernumber => $guarantee->{'borrowernumber'}, |
175 |
borrowernumber => $guarantee->{'borrowernumber'}, |
172 |
message_transport_type => 'email', |
176 |
message_transport_type => 'email', |
Lines 178-184
my $guarantee_message = {
Link Here
|
178 |
sub SendToGuarantor { |
182 |
sub SendToGuarantor { |
179 |
my ($useGuarantor, $message) = @_; |
183 |
my ($useGuarantor, $message) = @_; |
180 |
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' ); |
184 |
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' ); |
181 |
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', $useGuarantor ); |
185 |
C4::Context->set_preference( 'RedirectGuaranteeEmail', $useGuarantor ); |
182 |
C4::Context->clear_syspref_cache(); |
186 |
C4::Context->clear_syspref_cache(); |
183 |
my $id = C4::Letters::EnqueueLetter($message); |
187 |
my $id = C4::Letters::EnqueueLetter($message); |
184 |
C4::Letters::SendQueuedMessages(); |
188 |
C4::Letters::SendQueuedMessages(); |
Lines 186-207
sub SendToGuarantor {
Link Here
|
186 |
return $result; |
190 |
return $result; |
187 |
} |
191 |
} |
188 |
my $result = SendToGuarantor(0,$guarantee_message); |
192 |
my $result = SendToGuarantor(0,$guarantee_message); |
189 |
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail off, message is sent."); |
193 |
is($result->{'status'}, "sent", "With RedirectGuaranteeEmail off, message is sent."); |
190 |
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail off, Message is sent to the specified to_address."); |
194 |
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With RedirectGuaranteeEmail 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 |
|
195 |
|
201 |
$guarantee->{'guarantorid'} = undef; |
|
|
202 |
ModMember(%$guarantee); |
203 |
$result = SendToGuarantor(1,$guarantee_message); |
196 |
$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."); |
197 |
is($result->{'status'}, "sent", "With RedirectGuaranteeEmail on, message is sent."); |
|
|
198 |
is($result->{'to_address'}, $GUARANTOR_EMAIL, "With RedirectGuaranteeEmail on, Message is sent to the guarantor's email address."); |
205 |
|
199 |
|
206 |
# GetLetters |
200 |
# GetLetters |
207 |
my $letters = C4::Letters::GetLetters(); |
201 |
my $letters = C4::Letters::GetLetters(); |