|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::NoWarnings; |
22 |
use Test::NoWarnings; |
| 23 |
use Test::More tests => 3; |
23 |
use Test::More tests => 4; |
| 24 |
|
24 |
|
| 25 |
use C4::Letters qw( GetPreparedLetter EnqueueLetter ); |
25 |
use C4::Letters qw( GetPreparedLetter EnqueueLetter ); |
| 26 |
|
26 |
|
|
Lines 145-151
subtest 'html_content() tests' => sub {
Link Here
|
| 145 |
} |
145 |
} |
| 146 |
); |
146 |
); |
| 147 |
|
147 |
|
| 148 |
t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); |
148 |
# Mock all CSS preferences to ensure clean test state |
|
|
149 |
t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); |
| 150 |
t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); |
| 151 |
t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); |
| 152 |
t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '' ); |
| 153 |
t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', '' ); |
| 154 |
t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '' ); |
| 155 |
|
| 149 |
my $css_import = ''; |
156 |
my $css_import = ''; |
| 150 |
my $message = Koha::Notice::Messages->find($message_id); |
157 |
my $message = Koha::Notice::Messages->find($message_id); |
| 151 |
my $wrapped_compare = <<"WRAPPED"; |
158 |
my $wrapped_compare = <<"WRAPPED"; |
|
Lines 190-195
WRAPPED
Link Here
|
| 190 |
); |
197 |
); |
| 191 |
|
198 |
|
| 192 |
$template->is_html(0)->store; |
199 |
$template->is_html(0)->store; |
|
|
200 |
|
| 201 |
# Reset all preferences for plaintext test |
| 202 |
t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); |
| 203 |
t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); |
| 204 |
t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); |
| 205 |
t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '' ); |
| 206 |
t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', '' ); |
| 207 |
t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '' ); |
| 208 |
|
| 193 |
$prepared_letter = GetPreparedLetter( |
209 |
$prepared_letter = GetPreparedLetter( |
| 194 |
( |
210 |
( |
| 195 |
module => 'test', |
211 |
module => 'test', |
|
Lines 220-223
WRAPPED
Link Here
|
| 220 |
$schema->storage->txn_rollback; |
236 |
$schema->storage->txn_rollback; |
| 221 |
}; |
237 |
}; |
| 222 |
|
238 |
|
|
|
239 |
subtest 'stylesheets() tests' => sub { |
| 240 |
plan tests => 8; |
| 241 |
|
| 242 |
$schema->storage->txn_begin; |
| 243 |
|
| 244 |
my $template = $builder->build_object( |
| 245 |
{ |
| 246 |
class => 'Koha::Notice::Templates', |
| 247 |
value => { |
| 248 |
module => 'test', |
| 249 |
code => 'TEST', |
| 250 |
message_transport_type => 'email', |
| 251 |
is_html => '1', |
| 252 |
name => 'test notice template', |
| 253 |
title => 'Test Title', |
| 254 |
content => 'Test content', |
| 255 |
branchcode => "", |
| 256 |
lang => 'default', |
| 257 |
} |
| 258 |
} |
| 259 |
); |
| 260 |
|
| 261 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 262 |
|
| 263 |
my $prepared_letter = GetPreparedLetter( |
| 264 |
( |
| 265 |
module => 'test', |
| 266 |
letter_code => 'TEST', |
| 267 |
tables => { |
| 268 |
borrowers => $patron->id, |
| 269 |
}, |
| 270 |
) |
| 271 |
); |
| 272 |
|
| 273 |
# Test with no stylesheets set |
| 274 |
t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); |
| 275 |
t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); |
| 276 |
t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); |
| 277 |
t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '' ); |
| 278 |
t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', '' ); |
| 279 |
t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '' ); |
| 280 |
|
| 281 |
my $message_id = EnqueueLetter( |
| 282 |
{ |
| 283 |
letter => $prepared_letter, |
| 284 |
borrowernumber => $patron->id, |
| 285 |
message_transport_type => 'email' |
| 286 |
} |
| 287 |
); |
| 288 |
my $message = Koha::Notice::Messages->find($message_id); |
| 289 |
|
| 290 |
is( $message->stylesheets, '', "No stylesheets when all preferences are empty" ); |
| 291 |
|
| 292 |
# Test AllNoticeStylesheet only |
| 293 |
t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', 'https://example.com/all.css' ); |
| 294 |
is( |
| 295 |
$message->stylesheets, '<link rel="stylesheet" type="text/css" href="https://example.com/all.css">', |
| 296 |
"AllNoticeStylesheet works correctly" |
| 297 |
); |
| 298 |
|
| 299 |
# Test AllNoticeCSS only |
| 300 |
t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); |
| 301 |
t::lib::Mocks::mock_preference( 'AllNoticeCSS', 'body { color: red; }' ); |
| 302 |
is( $message->stylesheets, '<style type="text/css">body { color: red; }</style>', "AllNoticeCSS works correctly" ); |
| 303 |
|
| 304 |
# Test email-specific stylesheet for email transport |
| 305 |
t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); |
| 306 |
t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', 'https://example.com/email.css' ); |
| 307 |
is( |
| 308 |
$message->stylesheets, '<link rel="stylesheet" type="text/css" href="https://example.com/email.css">', |
| 309 |
"EmailNoticeStylesheet works for email transport" |
| 310 |
); |
| 311 |
|
| 312 |
# Test email-specific CSS for email transport |
| 313 |
t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); |
| 314 |
t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '.email { font-weight: bold; }' ); |
| 315 |
is( |
| 316 |
$message->stylesheets, '<style type="text/css">.email { font-weight: bold; }</style>', |
| 317 |
"EmailNoticeCSS works for email transport" |
| 318 |
); |
| 319 |
|
| 320 |
# Test combined all + email styles |
| 321 |
t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', 'https://example.com/all.css' ); |
| 322 |
t::lib::Mocks::mock_preference( 'AllNoticeCSS', 'body { margin: 0; }' ); |
| 323 |
t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', 'https://example.com/email.css' ); |
| 324 |
t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '.email { color: blue; }' ); |
| 325 |
|
| 326 |
my $expected_combined = |
| 327 |
'<link rel="stylesheet" type="text/css" href="https://example.com/all.css">' . "\n" |
| 328 |
. '<style type="text/css">body { margin: 0; }</style>' |
| 329 |
. '<link rel="stylesheet" type="text/css" href="https://example.com/email.css">' . "\n" |
| 330 |
. '<style type="text/css">.email { color: blue; }</style>'; |
| 331 |
is( $message->stylesheets, $expected_combined, "Combined all and email styles work correctly" ); |
| 332 |
|
| 333 |
# Test print transport type |
| 334 |
$message_id = EnqueueLetter( |
| 335 |
{ |
| 336 |
letter => $prepared_letter, |
| 337 |
borrowernumber => $patron->id, |
| 338 |
message_transport_type => 'print' |
| 339 |
} |
| 340 |
); |
| 341 |
$message = Koha::Notice::Messages->find($message_id); |
| 342 |
|
| 343 |
# Reset email preferences and set print preferences |
| 344 |
t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); |
| 345 |
t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '' ); |
| 346 |
t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', 'https://example.com/print.css' ); |
| 347 |
t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '.print { page-break-after: always; }' ); |
| 348 |
|
| 349 |
my $expected_print = |
| 350 |
'<link rel="stylesheet" type="text/css" href="https://example.com/all.css">' . "\n" |
| 351 |
. '<style type="text/css">body { margin: 0; }</style>' |
| 352 |
. '<link rel="stylesheet" type="text/css" href="https://example.com/print.css">' . "\n" |
| 353 |
. '<style type="text/css">.print { page-break-after: always; }</style>'; |
| 354 |
is( $message->stylesheets, $expected_print, "Print transport type uses correct stylesheets" ); |
| 355 |
|
| 356 |
# Test that email styles are NOT included for print transport |
| 357 |
t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); |
| 358 |
t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); |
| 359 |
t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', 'https://example.com/email.css' ); |
| 360 |
t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '.email { color: blue; }' ); |
| 361 |
t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', '' ); |
| 362 |
t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '' ); |
| 363 |
|
| 364 |
is( $message->stylesheets, '', "Print transport does not include email-specific styles" ); |
| 365 |
|
| 366 |
$schema->storage->txn_rollback; |
| 367 |
}; |
| 368 |
|
| 223 |
1; |
369 |
1; |
| 224 |
- |
|
|