Bug 11897: (QA follow-up) Fixes for JS12
[koha.git] / t / template_filters.t
1 # Copyright 2018 Koha Development Team
2 #
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19 use Test::More tests => 1;
20 use t::lib::QA::TemplateFilters;
21
22 my $input = <<INPUT;
23 [% USE Asset %]
24 [% INCLUDE 'doc-head-open.inc' %]
25 <title>Koha &rsaquo; Patrons &rsaquo;
26     [% UNLESS blocking_error %]
27         Patron details for [% INCLUDE 'patron-title.inc' no_html = 1 %]
28         [% just_a_var %] A N D [% another_one_on_same_line %]
29         [% just_a_var_filtered|html %]
30         [% just_a_var_filtered |html %]
31         [% just_a_var_filtered| html %]
32         [% just_a_var_filtered | html %]
33     [% END %]
34     [% IF ( patron.othernames | html ) %]&ldquo;[% patron.othernames %]&rdquo;[% END %]
35     [% Asset.css("css/datatables.css").raw %]
36     [% Asset.css("css/datatables.css") | \$raw %]
37 </title>
38 <a href="tel:[% patron.phone %]">[% patron.phone %]</a>
39 <a title="[% patron.emailpro %]" href="mailto:[% patron.emailpro | uri %]">[% patron.emailpro %]</a>
40 [% patron_message.get_column('manager_surname') %]
41 [%# do_nothing %]
42 [% # do_nothing %]
43 [% SWITCH var %]
44 [% CASE 'foo' %]foo
45 [% CASE %]
46 [% END %]
47 [%- SWITCH var -%]
48 [%- CASE 'foo' -%]foo
49 [%- CASE -%]
50 [%- END -%]
51 [%- var -%]
52 [% - var - %]
53 [%~ var ~%]
54 [% ~ var ~ %]
55 [% var | \$raw %]
56 [% foo UNLESS bar %]
57 [% SET var = val %]
58 [% var = val %]
59 [% var | \$Price %]
60 [%END%]
61 INPUT
62
63 my @expected_errors = (
64     {
65         error => q{missing_filter},
66         line =>
67 q{        [% just_a_var %] A N D [% another_one_on_same_line %]},
68         line_number => 6,
69     },
70     {
71         error => q{missing_filter},
72         line =>
73 q{        [% just_a_var %] A N D [% another_one_on_same_line %]},
74         line_number => 6,
75     },
76     {
77         error => q{missing_filter},
78         line =>
79 q{    [% IF ( patron.othernames | html ) %]&ldquo;[% patron.othernames %]&rdquo;[% END %]},
80         line_number => 12,
81     },
82     {
83         error       => q{asset_must_be_raw},
84         line        => q{    [% Asset.css("css/datatables.css").raw %]},
85         line_number => 13,
86     },
87     {
88         error => q{missing_filter},
89         line  => q{<a href="tel:[% patron.phone %]">[% patron.phone %]</a>},
90         line_number => 16,
91     },
92     {
93         error => q{missing_filter},
94         line  => q{<a href="tel:[% patron.phone %]">[% patron.phone %]</a>},
95         line_number => 16,
96     },
97     {
98         error => q{missing_filter},
99         line =>
100 q{<a title="[% patron.emailpro %]" href="mailto:[% patron.emailpro | uri %]">[% patron.emailpro %]</a>},
101         line_number => 17,
102     },
103     {
104         error => q{missing_filter},
105         line =>
106 q{<a title="[% patron.emailpro %]" href="mailto:[% patron.emailpro | uri %]">[% patron.emailpro %]</a>},
107         line_number => 17,
108     },
109     {
110         error       => q{missing_filter},
111         line        => q{[% patron_message.get_column('manager_surname') %]},
112         line_number => 18,
113     },
114     {
115         error       => q{missing_filter},
116         line        => q{[%- var -%]},
117         line_number => 29,
118     },
119     {
120         error       => q{missing_filter},
121         line        => q{[% - var - %]},
122         line_number => 30,
123     },
124     {
125         error       => q{missing_filter},
126         line        => q{[%~ var ~%]},
127         line_number => 31,
128     },
129     {
130         error       => q{missing_filter},
131         line        => q{[% ~ var ~ %]},
132         line_number => 32,
133     }
134 );
135
136 my @get = t::lib::QA::TemplateFilters::missing_filters($input);
137 is_deeply( \@get, \@expected_errors);