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