Bugzilla – Attachment 184046 Details for
Bug 35267
Clarify CSS options for Notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35267: (follow-up) More comprehensive and db agnostic tests
Bug-35267-follow-up-More-comprehensive-and-db-agno.patch (text/plain), 8.26 KB, created by
Martin Renvoize (ashimema)
on 2025-07-13 07:36:34 UTC
(
hide
)
Description:
Bug 35267: (follow-up) More comprehensive and db agnostic tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-07-13 07:36:34 UTC
Size:
8.26 KB
patch
obsolete
>From 478e9ed4d8be3ed88cd465f87196859a9a23d083 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Sun, 13 Jul 2025 08:34:21 +0100 >Subject: [PATCH] Bug 35267: (follow-up) More comprehensive and db agnostic > tests > >This patch updates our unit tests to be more agnostic to prior database >state during testing by mocking more of the preferences. > >We also add more tests to ensure we fully cover the new preferences and >their options. >--- > t/db_dependent/Koha/Notice/Message.t | 150 ++++++++++++++++++++++++++- > 1 file changed, 148 insertions(+), 2 deletions(-) > >diff --git a/t/db_dependent/Koha/Notice/Message.t b/t/db_dependent/Koha/Notice/Message.t >index 03027662a9f..e18779ff233 100755 >--- a/t/db_dependent/Koha/Notice/Message.t >+++ b/t/db_dependent/Koha/Notice/Message.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 3; >+use Test::More tests => 4; > > use C4::Letters qw( GetPreparedLetter EnqueueLetter ); > >@@ -145,7 +145,14 @@ subtest 'html_content() tests' => sub { > } > ); > >- t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); >+ # Mock all CSS preferences to ensure clean test state >+ t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '' ); >+ > my $css_import = ''; > my $message = Koha::Notice::Messages->find($message_id); > my $wrapped_compare = <<"WRAPPED"; >@@ -190,6 +197,15 @@ WRAPPED > ); > > $template->is_html(0)->store; >+ >+ # Reset all preferences for plaintext test >+ t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '' ); >+ > $prepared_letter = GetPreparedLetter( > ( > module => 'test', >@@ -220,4 +236,134 @@ WRAPPED > $schema->storage->txn_rollback; > }; > >+subtest 'stylesheets() tests' => sub { >+ plan tests => 8; >+ >+ $schema->storage->txn_begin; >+ >+ my $template = $builder->build_object( >+ { >+ class => 'Koha::Notice::Templates', >+ value => { >+ module => 'test', >+ code => 'TEST', >+ message_transport_type => 'email', >+ is_html => '1', >+ name => 'test notice template', >+ title => 'Test Title', >+ content => 'Test content', >+ branchcode => "", >+ lang => 'default', >+ } >+ } >+ ); >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ my $prepared_letter = GetPreparedLetter( >+ ( >+ module => 'test', >+ letter_code => 'TEST', >+ tables => { >+ borrowers => $patron->id, >+ }, >+ ) >+ ); >+ >+ # Test with no stylesheets set >+ t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '' ); >+ >+ my $message_id = EnqueueLetter( >+ { >+ letter => $prepared_letter, >+ borrowernumber => $patron->id, >+ message_transport_type => 'email' >+ } >+ ); >+ my $message = Koha::Notice::Messages->find($message_id); >+ >+ is( $message->stylesheets, '', "No stylesheets when all preferences are empty" ); >+ >+ # Test AllNoticeStylesheet only >+ t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', 'https://example.com/all.css' ); >+ is( >+ $message->stylesheets, '<link rel="stylesheet" type="text/css" href="https://example.com/all.css">', >+ "AllNoticeStylesheet works correctly" >+ ); >+ >+ # Test AllNoticeCSS only >+ t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'AllNoticeCSS', 'body { color: red; }' ); >+ is( $message->stylesheets, '<style type="text/css">body { color: red; }</style>', "AllNoticeCSS works correctly" ); >+ >+ # Test email-specific stylesheet for email transport >+ t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', 'https://example.com/email.css' ); >+ is( >+ $message->stylesheets, '<link rel="stylesheet" type="text/css" href="https://example.com/email.css">', >+ "EmailNoticeStylesheet works for email transport" >+ ); >+ >+ # Test email-specific CSS for email transport >+ t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '.email { font-weight: bold; }' ); >+ is( >+ $message->stylesheets, '<style type="text/css">.email { font-weight: bold; }</style>', >+ "EmailNoticeCSS works for email transport" >+ ); >+ >+ # Test combined all + email styles >+ t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', 'https://example.com/all.css' ); >+ t::lib::Mocks::mock_preference( 'AllNoticeCSS', 'body { margin: 0; }' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', 'https://example.com/email.css' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '.email { color: blue; }' ); >+ >+ my $expected_combined = >+ '<link rel="stylesheet" type="text/css" href="https://example.com/all.css">' . "\n" >+ . '<style type="text/css">body { margin: 0; }</style>' >+ . '<link rel="stylesheet" type="text/css" href="https://example.com/email.css">' . "\n" >+ . '<style type="text/css">.email { color: blue; }</style>'; >+ is( $message->stylesheets, $expected_combined, "Combined all and email styles work correctly" ); >+ >+ # Test print transport type >+ $message_id = EnqueueLetter( >+ { >+ letter => $prepared_letter, >+ borrowernumber => $patron->id, >+ message_transport_type => 'print' >+ } >+ ); >+ $message = Koha::Notice::Messages->find($message_id); >+ >+ # Reset email preferences and set print preferences >+ t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', 'https://example.com/print.css' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '.print { page-break-after: always; }' ); >+ >+ my $expected_print = >+ '<link rel="stylesheet" type="text/css" href="https://example.com/all.css">' . "\n" >+ . '<style type="text/css">body { margin: 0; }</style>' >+ . '<link rel="stylesheet" type="text/css" href="https://example.com/print.css">' . "\n" >+ . '<style type="text/css">.print { page-break-after: always; }</style>'; >+ is( $message->stylesheets, $expected_print, "Print transport type uses correct stylesheets" ); >+ >+ # Test that email styles are NOT included for print transport >+ t::lib::Mocks::mock_preference( 'AllNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'AllNoticeCSS', '' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeStylesheet', 'https://example.com/email.css' ); >+ t::lib::Mocks::mock_preference( 'EmailNoticeCSS', '.email { color: blue; }' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeStylesheet', '' ); >+ t::lib::Mocks::mock_preference( 'PrintNoticeCSS', '' ); >+ >+ is( $message->stylesheets, '', "Print transport does not include email-specific styles" ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > 1; >-- >2.50.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35267
:
172414
|
172415
|
172416
|
172417
|
172418
|
172457
|
172458
|
172459
|
172460
|
172461
|
172462
|
172463
|
172474
|
172475
|
172476
|
172477
|
172478
|
172479
|
172480
|
172485
|
172486
|
172487
|
172488
|
172489
|
172490
|
172491
|
175531
|
175532
|
175533
|
175534
|
175535
|
175536
|
175706
|
175707
|
175708
|
175709
|
175710
|
175711
|
175715
|
175716
|
175717
|
175718
|
175719
|
175721
|
175723
|
175724
|
175725
|
175726
|
175727
|
175728
|
175729
|
178485
|
178486
|
178487
|
178488
|
178489
|
178490
|
178491
|
180574
|
180575
|
180576
|
180577
|
180578
|
180579
|
180580
|
180963
|
180964
|
180965
|
180966
|
180967
|
180968
|
180969
|
180970
|
180971
|
184037
|
184038
|
184039
|
184040
|
184041
|
184042
|
184043
|
184044
|
184045
| 184046