Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 1; |
22 |
use Test::More tests => 2; |
23 |
|
23 |
|
24 |
use C4::Letters qw( GetPreparedLetter EnqueueLetter ); |
24 |
use C4::Letters qw( GetPreparedLetter EnqueueLetter ); |
25 |
|
25 |
|
Lines 29-39
use t::lib::TestBuilder;
Link Here
|
29 |
my $schema = Koha::Database->new->schema; |
29 |
my $schema = Koha::Database->new->schema; |
30 |
my $builder = t::lib::TestBuilder->new; |
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
31 |
|
32 |
subtest 'html_content() tests' => sub { |
32 |
subtest 'is_html() tests' => sub { |
33 |
plan tests => 2; |
33 |
plan tests => 2; |
34 |
|
34 |
|
35 |
$schema->storage->txn_begin; |
35 |
$schema->storage->txn_begin; |
36 |
|
36 |
|
|
|
37 |
my $template = $builder->build_object( |
38 |
{ |
39 |
class => 'Koha::Notice::Templates', |
40 |
value => { |
41 |
module => 'test', |
42 |
code => 'TEST', |
43 |
message_transport_type => 'email', |
44 |
is_html => '0', |
45 |
name => 'test notice template', |
46 |
title => '[% borrower.firstname %]', |
47 |
content => 'This is a test template using borrower [% borrower.id %]', |
48 |
branchcode => "", |
49 |
lang => 'default', |
50 |
} |
51 |
} |
52 |
); |
53 |
|
54 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
55 |
my $firstname = $patron->firstname; |
56 |
my $borrowernumber = $patron->id; |
57 |
|
58 |
my $prepared_letter = GetPreparedLetter( |
59 |
( |
60 |
module => 'test', |
61 |
letter_code => 'TEST', |
62 |
tables => { |
63 |
borrowers => $patron->id, |
64 |
}, |
65 |
) |
66 |
); |
67 |
|
68 |
my $message_id = EnqueueLetter( |
69 |
{ |
70 |
letter => $prepared_letter, |
71 |
borrowernumber => $patron->id, |
72 |
message_transport_type => 'email' |
73 |
} |
74 |
); |
75 |
my $message = Koha::Notice::Messages->find($message_id); |
76 |
|
77 |
ok( !$message->is_html, "Non html template yields a non html message" ); |
78 |
|
79 |
$template->is_html(1)->store; |
80 |
$prepared_letter = GetPreparedLetter( |
81 |
( |
82 |
module => 'test', |
83 |
letter_code => 'TEST', |
84 |
tables => { |
85 |
borrowers => $patron->id, |
86 |
}, |
87 |
) |
88 |
); |
89 |
|
90 |
$message_id = EnqueueLetter( |
91 |
{ |
92 |
letter => $prepared_letter, |
93 |
borrowernumber => $patron->id, |
94 |
message_transport_type => 'email' |
95 |
} |
96 |
); |
97 |
|
98 |
$message = Koha::Notice::Messages->find($message_id); |
99 |
ok( $message->is_html, "HTML template yields a html message" ); |
100 |
|
101 |
$schema->storage->txn_rollback; |
102 |
}; |
103 |
|
104 |
subtest 'html_content() tests' => sub { |
105 |
plan tests => 3; |
106 |
|
107 |
$schema->storage->txn_begin; |
108 |
|
37 |
my $template = $builder->build_object( |
109 |
my $template = $builder->build_object( |
38 |
{ |
110 |
{ |
39 |
class => 'Koha::Notice::Templates', |
111 |
class => 'Koha::Notice::Templates', |
Lines 116-121
WRAPPED
Link Here
|
116 |
"html_content returned the correct html wrapped letter including stylesheet" |
188 |
"html_content returned the correct html wrapped letter including stylesheet" |
117 |
); |
189 |
); |
118 |
|
190 |
|
|
|
191 |
$template->is_html(0)->store; |
192 |
$prepared_letter = GetPreparedLetter( |
193 |
( |
194 |
module => 'test', |
195 |
letter_code => 'TEST', |
196 |
tables => { |
197 |
borrowers => $patron->id, |
198 |
}, |
199 |
) |
200 |
); |
201 |
|
202 |
$message_id = EnqueueLetter( |
203 |
{ |
204 |
letter => $prepared_letter, |
205 |
borrowernumber => $patron->id, |
206 |
message_transport_type => 'email' |
207 |
} |
208 |
); |
209 |
|
210 |
$wrapped_compare = <<"WRAPPED"; |
211 |
<div style="white-space: pre-wrap;"> |
212 |
This is a test template using borrower $borrowernumber |
213 |
</div> |
214 |
WRAPPED |
215 |
|
216 |
$message = Koha::Notice::Messages->find($message_id); |
217 |
is( |
218 |
$message->html_content, $wrapped_compare, |
219 |
"html_content returned the correct html wrapped letter for a plaintext template" |
220 |
); |
221 |
|
119 |
$schema->storage->txn_rollback; |
222 |
$schema->storage->txn_rollback; |
120 |
}; |
223 |
}; |
121 |
|
224 |
|
122 |
- |
|
|