Bug 21393: Add line nubmers to ease fixing
[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 [%END%]
60 INPUT
61
62 my @expected_errors = (
63     {
64         error => q{missing_filter},
65         line =>
66 q{        [% just_a_var %] A N D [% another_one_on_same_line %]},
67         line_number => 6,
68     },
69     {
70         error => q{missing_filter},
71         line =>
72 q{        [% just_a_var %] A N D [% another_one_on_same_line %]},
73         line_number => 6,
74     },
75     {
76         error => q{missing_filter},
77         line =>
78 q{    [% IF ( patron.othernames | html ) %]&ldquo;[% patron.othernames %]&rdquo;[% END %]},
79         line_number => 12,
80     },
81     {
82         error       => q{asset_must_be_raw},
83         line        => q{    [% Asset.css("css/datatables.css").raw %]},
84         line_number => 13,
85     },
86     {
87         error => q{missing_filter},
88         line  => q{<a href="tel:[% patron.phone %]">[% patron.phone %]</a>},
89         line_number => 16,
90     },
91     {
92         error => q{missing_filter},
93         line  => q{<a href="tel:[% patron.phone %]">[% patron.phone %]</a>},
94         line_number => 16,
95     },
96     {
97         error => q{missing_filter},
98         line =>
99 q{<a title="[% patron.emailpro %]" href="mailto:[% patron.emailpro | uri %]">[% patron.emailpro %]</a>},
100         line_number => 17,
101     },
102     {
103         error => q{missing_filter},
104         line =>
105 q{<a title="[% patron.emailpro %]" href="mailto:[% patron.emailpro | uri %]">[% patron.emailpro %]</a>},
106         line_number => 17,
107     },
108     {
109         error       => q{missing_filter},
110         line        => q{[% patron_message.get_column('manager_surname') %]},
111         line_number => 18,
112     },
113     {
114         error       => q{missing_filter},
115         line        => q{[%- var -%]},
116         line_number => 29,
117     },
118     {
119         error       => q{missing_filter},
120         line        => q{[% - var - %]},
121         line_number => 30,
122     },
123     {
124         error       => q{missing_filter},
125         line        => q{[%~ var ~%]},
126         line_number => 31,
127     },
128     {
129         error       => q{missing_filter},
130         line        => q{[% ~ var ~ %]},
131         line_number => 32,
132     }
133 );
134
135 my @get = t::lib::QA::TemplateFilters::missing_filters($input);
136 is_deeply( \@get, \@expected_errors);