3 # Copyright (C) 2009 LibLime
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
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.
29 This test checks all staff and OPAC templates and includes for syntax errors
30 by running a helper script that loads each template into a HTML::Template::Pro
31 object and calls the output() method, which forces the template to be parsed.
32 HTML::Template::Pro currently reports any syntax errors to STDERR.
34 This test currently ignores error messages of the form
36 EXPR:at pos n: non-initialized variable foo
38 However, note that TMPL_IF EXPR is currently discouraged for use in Koha
43 use Test::More qw/no_plan/;
49 foreach my $type qw(intranet opac) {
50 my $template_dir = File::Spec->rel2abs("koha-tmpl/$type-tmpl/prog/en/modules");
51 my $include_dir = File::Spec->rel2abs("koha-tmpl/$type-tmpl/prog/en/includes");
53 my $template_test = gen_template_test($include_dir);
54 find({ wanted => $template_test, no_chdir => 1 }, $template_dir, $include_dir);
57 sub gen_template_test {
58 my $include_dir = shift;
60 return unless -f $File::Find::name;
62 # We're starting a seprate process to test the template
63 # because some of the error messages we're interested in
64 # are written directly to STDERR in HTML::Template::Pro's
65 # XS code. I haven't found any other way to capture
66 # those messages. --gmc
69 my $pid = open3(\*CHILD_IN, \*CHILD_OUT, \*CHILD_ERR,
70 "$FindBin::Bin/test_template.pl", $File::Find::name, $include_dir);
73 #FIXME: This is here just to ensure that STDOUT is read which avoids a deadlock in some instances, but probably not all
74 #FIXME: The real solution probably lies within the information found here: http://www.perlmonks.org/?node_id=150748
80 @errors = grep { ! /^EXPR:.*non-initialized variable/ } @errors; # ignoring EXPR errors for now
81 my $rel_filename = File::Spec->abs2rel($File::Find::name);
82 ok(@errors == 0, "no errors in $rel_filename") or diag(join("", @errors) );
89 Koha Developement Team <http://koha-community.org>
91 Galen Charlton <galen.charlton@liblime.com>