Bug 10541: enable cross-browser AJAX in additem.js
[koha.git] / xt / tt_valid.t
blobf71085eea13c8476af659c27f559ca9f892bf920
1 #!/usr/bin/perl
3 # Copyright (C) 2011 Tamil s.a.r.l.
5 # This file is part of Koha.
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.
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.
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.
20 use warnings;
21 use strict;
22 use Test::More tests => 2;
23 use File::Find;
24 use Cwd;
25 use C4::TTParser;
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->{'[%'};
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" )
48 @files;
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 )
59 my $testtoken = 0;
60 my $ttparser = C4::TTParser->new();
61 $ttparser->unshift_token($testtoken);
62 my $testtokenagain = C4::TTParser::next_token();
63 is( $testtoken, $testtokenagain, "Token received same as original put on stack");
66 =head1 NAME
68 tt_valid.t
70 =head1 DESCRIPTION
72 This test validate Template Toolkit (TT) Koha files.
74 For the time being an unique validation is done: Test if TT files contain TT
75 directive within HTML tag. For example:
77 <li[% IF
79 This kind of constuction MUST be avoided because it break Koha translation
80 process.
82 =head1 USAGE
84 From Koha root directory:
86 prove -v xt/tt_valid.t
88 =cut