Bug 13242: Add a UT to t/DateUtils.t for testing DateTime bug
[koha.git] / xt / tt_valid.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright (C) 2011 Tamil s.a.r.l.
6 #
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.
11 #
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.
16 #
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>.
19
20 use warnings;
21 use strict;
22 use Test::More tests => 2;
23 use File::Find;
24 use Cwd;
25 use C4::TTParser;
26
27 my @themes;
28
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";
34 }
35 close $dh;
36
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";
42 }
43 close $dh;
44
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->{'[%-'};
59         }
60         ($dir) = $dir =~ /koha-tmpl\/(.*)$/;
61         push @files, { name => "$dir/$name", lines => \@lines } if @lines;
62       }, @themes
63     );
64     @files;
65 };
66
67
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 )
73        );
74
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");
80
81
82 =head1 NAME
83
84 tt_valid.t
85
86 =head1 DESCRIPTION
87
88 This test validate Template Toolkit (TT) Koha files.
89
90 For the time being an unique validation is done: Test if TT files contain TT
91 directive within HTML tag. For example:
92
93   <li[% IF
94
95 This kind of constuction MUST be avoided because it break Koha translation
96 process.
97
98 =head1 USAGE
99
100 From Koha root directory:
101
102 prove -v xt/tt_valid.t
103
104 =cut
105