3 # Copyright 2023 Koha Development team
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>
22 use Test::More tests => 1;
24 use C4::Letters qw( GetPreparedLetter EnqueueLetter );
27 use t::lib::TestBuilder;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 subtest 'html_content() tests' => sub {
35 $schema->storage->txn_begin;
37 my $template = $builder->build_object(
39 class => 'Koha::Notice::Templates',
43 message_transport_type => 'email',
45 name => 'test notice template',
46 title => '[% borrower.firstname %]',
47 content => 'This is a test template using borrower [% borrower.id %]',
53 my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
54 my $firstname = $patron->firstname;
55 my $borrowernumber = $patron->id;
57 my $prepared_letter = GetPreparedLetter(
60 letter_code => 'TEST',
62 borrowers => $patron->id,
67 my $message_id = EnqueueLetter(
69 letter => $prepared_letter,
70 borrowernumber => $patron->id,
71 message_transport_type => 'email'
75 t::lib::Mocks::mock_preference( 'NoticeCSS', '' );
77 my $message = Koha::Notice::Messages->find($message_id);
78 my $wrapped_compare = <<"WRAPPED";
79 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
80 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
81 <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
83 <title>$firstname</title>
84 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
88 This is a test template using borrower $borrowernumber
93 is( $message->html_content, $wrapped_compare, "html_content returned the correct html wrapped letter" );
95 my $css_sheet = 'https://localhost/shiny.css';
96 t::lib::Mocks::mock_preference( 'NoticeCSS', $css_sheet );
97 $css_import = qq{<link rel="stylesheet" type="text/css" href="$css_sheet">};
99 $wrapped_compare = <<"WRAPPED";
100 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
101 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
102 <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
104 <title>$firstname</title>
105 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
109 This is a test template using borrower $borrowernumber
115 $message->html_content, $wrapped_compare,
116 "html_content returned the correct html wrapped letter including stylesheet"
119 $schema->storage->txn_rollback;