3 # This file is part of Koha.
5 # Copyright (C) 2011 Tamil s.a.r.l.
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>.
21 use Test::More tests => 3;
29 my $opac_dir = 'koha-tmpl/opac-tmpl';
30 opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
31 for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) {
32 push @themes, "$opac_dir/$theme/en";
37 my $staff_dir = 'koha-tmpl/intranet-tmpl';
38 opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
39 for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
40 push @themes, "$staff_dir/$theme/en";
46 description => 'TT syntax: not using TT directive within HTML tag',
48 my ($self, $name, $token) = @_;
49 my $attr = $token->{_attr};
51 push @{$self->{errors}->{$name}}, $token->{_lc} if $attr->{'[%'} or $attr->{'[%-'};
56 description => '<body> tag with id and class attributes',
58 my ($self, $name, $token) = @_;
59 return if $name =~ /bodytag\.inc/;
60 my $tag = $token->{_string};
61 push @{$self->{errors}->{$name}}, $token->{_lc}
62 if $tag =~ /^<body/ &&
63 ($tag !~ /id=".+"/ || $tag !~ /class=".+"/);
70 return if $dir =~ /blib/;
71 return unless /\.(tt|inc)$/;
72 ($dir) = $dir =~ /koha-tmpl\/(.*)$/;
74 my $parser = C4::TTParser->new;
75 $parser->build_tokens( $name );
76 while ( my $token = $parser->next_token ) {
77 my $attr = $token->{_attr};
79 for my $checker (@$checkers) {
80 $checker->{check}->($checker, "$dir/$name", $token);
86 for my $check (@$checkers) {
87 my @files = sort keys %{$check->{errors}};
88 ok( !@files, $check->{description} )
91 join( "\n", map { "$_: " . join(', ', @{$check->{errors}->{$_}})
97 my $ttparser = C4::TTParser->new();
98 $ttparser->unshift_token($testtoken);
99 my $testtokenagain = C4::TTParser::next_token();
100 is( $testtoken, $testtokenagain, "Token received same as original put on stack");
109 This test validate Template Toolkit (TT) Koha files.
111 For the time being, two validations are done:
113 [1] Test if TT files contain TT directive within HTML tag. For example:
117 This kind of construction MUST be avoided because it breaks Koha translation
120 [2] Test tag <body> tags have both attibutes 'id' and 'class'
124 From Koha root directory:
126 prove -v xt/tt_valid.t