MT 1587 : CSV export for cart and shelves, with the ability to define different expor...
[koha.git] / xt / author / valid-templates.t
1 #!/usr/bin/perl
2
3 # Copyright (C) 2009 LibLime
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use warnings;
22
23 =head1 NAME
24
25 valid-templates.t
26
27 =head1 DESCRIPTION
28
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.
33
34 This test currently ignores error messages of the form
35
36 EXPR:at pos n: non-initialized variable foo
37
38 However, note that TMPL_IF EXPR is currently discouraged for use in Koha
39 templates.
40
41 =cut
42
43 use Test::More qw/no_plan/;
44 use File::Find;
45 use File::Spec;
46 use FindBin;
47 use IPC::Open3;
48
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");
52    
53     my $template_test = gen_template_test($include_dir);
54     find({ wanted => $template_test, no_chdir => 1 }, $template_dir, $include_dir);
55 }
56
57 sub gen_template_test {
58     my $include_dir = shift;
59     return sub {
60         return unless -f $File::Find::name;
61
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
67         local *CHILD_IN;
68         local *CHILD_OUT;
69         my $pid = open3(\*CHILD_IN, \*CHILD_OUT, \*CHILD_ERR, 
70                         "$FindBin::Bin/test_template.pl", $File::Find::name, $include_dir);
71         my @errors = ();
72         while (<CHILD_ERR>) {
73             push @errors, $_;
74         }
75         waitpid($pid, 0);
76
77         @errors = grep { ! /^EXPR:.*non-initialized variable/ } @errors; # ignoring EXPR errors for now
78         my $rel_filename = File::Spec->abs2rel($File::Find::name);
79         ok(@errors == 0, "no errors in $rel_filename") or diag(join("", @errors) );
80     }
81
82 }
83
84 =head1 AUTHOR
85
86 Koha Developement team <info@koha.org>
87
88 Galen Charlton <galen.charlton@liblime.com>
89
90 =cut