Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2023 Koha Development team |
4 |
# |
5 |
# This file is part of Koha |
6 |
# |
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. |
11 |
# |
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. |
16 |
# |
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> |
19 |
|
20 |
use Modern::Perl; |
21 |
|
22 |
use Test::More tests => 1; |
23 |
|
24 |
use C4::Letters qw( GetPreparedLetter EnqueueLetter ); |
25 |
|
26 |
use t::lib::Mocks; |
27 |
use t::lib::TestBuilder; |
28 |
|
29 |
my $schema = Koha::Database->new->schema; |
30 |
my $builder = t::lib::TestBuilder->new; |
31 |
|
32 |
subtest 'html_content() tests' => sub { |
33 |
plan tests => 2; |
34 |
|
35 |
$schema->storage->txn_begin; |
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 => '1', |
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 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
54 |
my $firstname = $patron->firstname; |
55 |
my $borrowernumber = $patron->id; |
56 |
|
57 |
my $prepared_letter = GetPreparedLetter( |
58 |
( |
59 |
module => 'test', |
60 |
letter_code => 'TEST', |
61 |
tables => { |
62 |
borrowers => $patron->id, |
63 |
}, |
64 |
) |
65 |
); |
66 |
|
67 |
my $message_id = EnqueueLetter( |
68 |
{ |
69 |
letter => $prepared_letter, |
70 |
borrowernumber => $patron->id, |
71 |
message_transport_type => 'email' |
72 |
} |
73 |
); |
74 |
|
75 |
my $message = Koha::Notice::Messages->find($message_id); |
76 |
my $wrapped_compare = <<"WRAPPED"; |
77 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
78 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
79 |
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> |
80 |
<head> |
81 |
<title>$firstname</title> |
82 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
83 |
|
84 |
</head> |
85 |
<body> |
86 |
This is a test template using borrower $borrowernumber |
87 |
</body> |
88 |
</html> |
89 |
WRAPPED |
90 |
|
91 |
is( $message->html_content, $wrapped_compare, "html_content returned the correct html wrapped letter" ); |
92 |
|
93 |
my $css_sheet = 'https://localhost/shiny.css'; |
94 |
t::lib::Mocks::mock_preference('NoticeCSS', $css_sheet); |
95 |
|
96 |
$wrapped_compare = <<"WRAPPED"; |
97 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
98 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
99 |
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> |
100 |
<head> |
101 |
<title>$firstname</title> |
102 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
103 |
<link rel="stylesheet" type="text/css" href="$css_sheet"> |
104 |
</head> |
105 |
<body> |
106 |
This is a test template using borrower $borrowernumber |
107 |
</body> |
108 |
</html> |
109 |
WRAPPED |
110 |
|
111 |
is( $message->html_content, $wrapped_compare, "html_content returned the correct html wrapped letter including stylesheet" ); |
112 |
|
113 |
$schema->storage->txn_rollback; |
114 |
}; |
115 |
|
116 |
1; |