Revert "Bug 10606: Remove MySQLism in GetUpcomingDueIssues"
[koha.git] / xt / tt_valid.t
blob507210f6a5077042fd97d0a9b43d5e7a6182f6c0
1 #!/usr/bin/perl
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>.
20 use warnings;
21 use strict;
22 use Test::More tests => 2;
23 use File::Find;
24 use Cwd;
25 use C4::TTParser;
27 my @themes;
29 # OPAC themes
30 my $opac_dir = 'koha-tmpl/opac-tmpl';
31 opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
32 for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
33 push @themes, "$opac_dir/$theme/en";
35 close $dh;
37 # STAFF themes
38 my $staff_dir = 'koha-tmpl/intranet-tmpl';
39 opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
40 for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
41 push @themes, "$staff_dir/$theme/en";
43 close $dh;
45 my @files_with_directive_in_tag = do {
46 my @files;
47 find( sub {
48 my $dir = getcwd();
49 return if $dir =~ /blib/;
50 return unless /\.(tt|inc)$/;
51 my $name = $_;
52 my $parser = C4::TTParser->new;
53 $parser->build_tokens( $name );
54 my @lines;
55 while ( my $token = $parser->next_token ) {
56 my $attr = $token->{_attr};
57 next unless $attr;
58 push @lines, $token->{_lc} if $attr->{'[%'} or $attr->{'[%-'};
60 ($dir) = $dir =~ /koha-tmpl\/(.*)$/;
61 push @files, { name => "$dir/$name", lines => \@lines } if @lines;
62 }, @themes
64 @files;
68 ok( !@files_with_directive_in_tag, "TT syntax: not using TT directive within HTML tag" )
69 or diag(
70 "Files list: \n",
71 join( "\n", map { $_->{name} . ': ' . join(', ', @{$_->{lines}})
72 } @files_with_directive_in_tag )
75 my $testtoken = 0;
76 my $ttparser = C4::TTParser->new();
77 $ttparser->unshift_token($testtoken);
78 my $testtokenagain = C4::TTParser::next_token();
79 is( $testtoken, $testtokenagain, "Token received same as original put on stack");
82 =head1 NAME
84 tt_valid.t
86 =head1 DESCRIPTION
88 This test validate Template Toolkit (TT) Koha files.
90 For the time being an unique validation is done: Test if TT files contain TT
91 directive within HTML tag. For example:
93 <li[% IF
95 This kind of constuction MUST be avoided because it break Koha translation
96 process.
98 =head1 USAGE
100 From Koha root directory:
102 prove -v xt/tt_valid.t
104 =cut