# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
-use Test::More tests => 5;
+use Test::More tests => 6;
use t::lib::QA::TemplateFilters;
subtest 'Asset must use raw' => sub {
my $new_content = t::lib::QA::TemplateFilters::fix_filters($input);
is( $new_content . "\n", $expected, );
- my $missing_filters = t::lib::QA::TemplateFilters::search_missing_filters($input);
+ my @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
is_deeply(
- $missing_filters,
+ \@missing_filters,
[
{
error => "asset_must_be_raw",
my $new_content = t::lib::QA::TemplateFilters::fix_filters($input);
is( $new_content . "\n", $expected, );
- my $missing_filters = t::lib::QA::TemplateFilters::search_missing_filters($input);
+ my @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
is_deeply(
- $missing_filters,
+ \@missing_filters,
[{
error => "missing_filter",
line => " [% just_a_var %]",
my $new_content = t::lib::QA::TemplateFilters::fix_filters($input);
is( $new_content . "\n", $expected, );
- my $missing_filters = t::lib::QA::TemplateFilters::search_missing_filters($input);
+ my @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
is_deeply(
- $missing_filters,[],);
+ \@missing_filters,[],);
};
subtest 'Preserve pre/post chomps' => sub {
plan tests => 1;
my $input = <<INPUT;
-[% USE raw %]
+[%- USE raw -%]
[%- var -%]
[% - var - %]
[%~ var ~%]
[%~ var | uri ~%]
INPUT
my $expected = <<EXPECTED;
-[% USE raw %]
+[%- USE raw -%]
[%- var | html -%]
[%- var | html -%]
[%~ var | html ~%]
};
subtest 'Use uri filter if needed' => sub {
- plan tests => 3;
+ plan tests => 4;
my $input = <<INPUT;
<a href="tel:[% patron.phone %]">[% patron.phone %]</a>
<a href="mailto:[% patron.emailpro %]" title="[% patron.emailpro %]">[% patron.emailpro %]</a>
<a href="[% myuri | uri %]" title="[% myuri %]">[% myuri %]</a>
<a href="[% myurl | html %]" title="[% myurl %]">[% myurl %]</a>
<a href="[% myurl | url %]" title="[% myurl %]">[% myurl %]</a>
+<a href="[% myurl | html_entity %]" title="[% myurl %]">[% myurl %]</a>
+<a href="/cgi-bin/koha/acqui/newordersuggestion.pl?booksellerid=[% booksellerid %]&basketno=[% basketno %]">[% another_var %]</a>
+<a href="/cgi-bin/koha/acqui/newordersuggestion.pl?booksellerid=[% booksellerid %]&basketno=[% basketno | html %]" title="[% a_title %]>[% another_var %]</a>
INPUT
# Note: [% myurl %] will be uri escaped, we cannot know url should be used
<a href="[% myuri | uri %]" title="[% myuri | html %]">[% myuri | html %]</a>
<a href="[% myurl | uri %]" title="[% myurl | html %]">[% myurl | html %]</a>
<a href="[% myurl | url %]" title="[% myurl | html %]">[% myurl | html %]</a>
+<a href="[% myurl | html_entity %]" title="[% myurl | html %]">[% myurl | html %]</a>
+<a href="/cgi-bin/koha/acqui/newordersuggestion.pl?booksellerid=[% booksellerid | uri %]&basketno=[% basketno | uri %]">[% another_var | html %]</a>
+<a href="/cgi-bin/koha/acqui/newordersuggestion.pl?booksellerid=[% booksellerid | uri %]&basketno=[% basketno | uri %]" title="[% a_title | html %]>[% another_var | html %]</a>
EXPECTED
my $new_content = t::lib::QA::TemplateFilters::fix_filters($input);
$input = <<INPUT;
<a href="[% wrong_filter | html %]">[% var | html %]</a>
INPUT
- my $missing_filters = t::lib::QA::TemplateFilters::search_missing_filters($input);
+ my @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
is_deeply(
- $missing_filters,
+ \@missing_filters,
[
{
error => "wrong_html_filter",
$input = <<INPUT;
<a href="[% good_raw_filter | \$raw %]">[% var | html %]</a>
INPUT
- $missing_filters = t::lib::QA::TemplateFilters::search_missing_filters($input);
- is_deeply( $missing_filters, [], );
+ @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
+ is_deeply( \@missing_filters, [], );
+
+ $input = <<INPUT;
+<a href="[% good_filter | html_entity %]">[% var | html %]</a>
+INPUT
+ @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
+ is_deeply( \@missing_filters, [], 'html_entity is a valid filter for href' );
+};
+
+subtest 'Do not escape KohaDates|Prices|HtmlTags output' => sub {
+ plan tests => 2;
+ my $input = <<INPUT;
+[% var | \$KohaDates %]
+[% var | \$KohaDates with_hours => 1 %]
+[% var | \$KohaDates | html %]
+[% var | \$KohaDates with_hours => 1 | html %]
+[% var | \$Price %]
+[% var | \$HtmlTags %]
+INPUT
+
+ my $expected = <<EXPECTED;
+[% var | \$KohaDates %]
+[% var | \$KohaDates with_hours => 1 %]
+[% var | \$KohaDates %]
+[% var | \$KohaDates with_hours => 1 %]
+[% var | \$Price %]
+[% var | \$HtmlTags %]
+EXPECTED
+
+ my $new_content = t::lib::QA::TemplateFilters::fix_filters($input);
+ is( $new_content . "\n", $expected, );
+
+
+ my @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
+ is_deeply(
+ \@missing_filters,
+ [
+ {
+ error => "extra_filter_not_needed",
+ line => "[% var | \$KohaDates | html %]",
+ line_number => 3,
+ },
+ {
+ error => "extra_filter_not_needed",
+ line => "[% var | \$KohaDates with_hours => 1 | html %]",
+ line_number => 4,
+ }
+ ]
+ );
+
};