From f89d178b063698b643c62b38b93924039b722d94 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 8 Nov 2023 09:38:18 +0000 Subject: [PATCH] Bug 30287: (follow-up) Unit test for html_content This patch adds a unit test for the new `html_content` method introduced to Koha::Notice::Template in the previous patch. Test 1) Run the new unit test ;P Signed-off-by: David Nind Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer (cherry picked from commit c260f4a374c3e3fcb335e997842ffb2fa1bd444a) Signed-off-by: Fridolin Somers --- t/db_dependent/Koha/Notice/Message.t | 119 +++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100755 t/db_dependent/Koha/Notice/Message.t diff --git a/t/db_dependent/Koha/Notice/Message.t b/t/db_dependent/Koha/Notice/Message.t new file mode 100755 index 0000000000..27265987fd --- /dev/null +++ b/t/db_dependent/Koha/Notice/Message.t @@ -0,0 +1,119 @@ +#!/usr/bin/perl + +# Copyright 2023 Koha Development team +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see + +use Modern::Perl; + +use Test::More tests => 1; + +use C4::Letters qw( GetPreparedLetter EnqueueLetter ); + +use t::lib::Mocks; +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; + +subtest 'html_content() tests' => sub { + plan tests => 2; + + $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 => '[% borrower.firstname %]', + content => 'This is a test template using borrower [% borrower.id %]', + branchcode => "", + lang => 'default', + } + } + ); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + my $firstname = $patron->firstname; + my $borrowernumber = $patron->id; + + my $prepared_letter = GetPreparedLetter( + ( + module => 'test', + letter_code => 'TEST', + tables => { + borrowers => $patron->id, + }, + ) + ); + + my $message_id = EnqueueLetter( + { + letter => $prepared_letter, + borrowernumber => $patron->id, + message_transport_type => 'email' + } + ); + + my $message = Koha::Notice::Messages->find($message_id); + my $wrapped_compare = <<"WRAPPED"; + + + + $firstname + + + + + This is a test template using borrower $borrowernumber + + +WRAPPED + + is( $message->html_content, $wrapped_compare, "html_content returned the correct html wrapped letter" ); + + my $css_sheet = 'https://localhost/shiny.css'; + t::lib::Mocks::mock_preference( 'NoticeCSS', $css_sheet ); + + $wrapped_compare = <<"WRAPPED"; + + + + $firstname + + + + + This is a test template using borrower $borrowernumber + + +WRAPPED + + is( + $message->html_content, $wrapped_compare, + "html_content returned the correct html wrapped letter including stylesheet" + ); + + $schema->storage->txn_rollback; +}; + +1; -- 2.39.5