Merge branch 'new/bug_4330' into kcmaster
[koha.git] / xt / tt_valid.t
1 #!/usr/bin/perl
2
3 # Copyright (C) 2011 Tamil s.a.r.l.
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use warnings;
21 use strict;
22 use Test::More tests => 1;
23 use File::Find;
24 use Cwd;
25 use C4::TTParser;
26
27
28 my @files_with_directive_in_tag = do {
29     my @files;
30     find( sub {
31         my $dir = getcwd();
32         return if $dir =~ /blib/;
33         return unless /\.(tt|inc)$/;
34         my $name = $_;
35         my $parser = C4::TTParser->new;
36         $parser->build_tokens( $name );  
37         my @lines;
38         while ( my $token = $parser->next_token ) {
39             my $attr = $token->{_attr};
40             next unless $attr;
41             push @lines, $token->{_lc} if $attr->{'[%'};
42         }
43         ($dir) = $dir =~ /koha-tmpl\/(.*)$/;
44         push @files, { name => "$dir/$name", lines => \@lines } if @lines;
45       }, ( "./koha-tmpl/opac-tmpl/prog/en",
46            "./koha-tmpl/intranet-tmpl/prog/en" )
47     );
48     @files;
49 };
50
51
52 ok( !@files_with_directive_in_tag, "TT syntax: not using TT directive within HTML tag" )
53     or diag(
54           "Files list: \n",
55           join( "\n", map { $_->{name} . ': ' . join(', ', @{$_->{lines}})
56               } @files_with_directive_in_tag )
57        );
58
59
60
61 =head1 NAME
62
63 tt_valid.t
64
65 =head1 DESCRIPTION
66
67 This test validate Template Toolkit (TT) Koha files.
68
69 For the time being an unique validation is done: Test if TT files contain TT
70 directive within HTML tag. For example:
71
72   <li[% IF
73
74 This kind of constuction MUST be avoided because it break Koha translation
75 process.
76
77 =head1 USAGE
78
79 From Koha root directory:
80
81 prove -v xt/tt_valid.t
82
83 =cut
84