Bug 11936: (QA follow-up) Consistent log message for item insert
[koha.git] / xt / author / valid-templates.t
blobd31b01e10dca62861c56680d4a296ff1aff77341
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2011 Catalyst IT
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 Modern::Perl;
22 =head1 NAME
24 valid-templates.t
26 =head1 DESCRIPTION
28 This test checks all staff and OPAC templates and includes for syntax errors
30 =cut
33 use File::Find;
34 use File::Spec;
35 use Template;
36 use Test::More;
38 my @themes;
40 # OPAC themes
41 my $opac_dir = 'koha-tmpl/opac-tmpl';
42 opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
43 for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) {
44 push @themes, {
45 type => "opac",
46 theme => $theme,
47 modules => "$opac_dir/$theme/en/modules",
48 includes => "$opac_dir/$theme/en/includes",
51 close $dh;
53 # STAFF themes
54 my $staff_dir = 'koha-tmpl/intranet-tmpl';
55 opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
56 for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
57 push @themes, {
58 type => "staff",
59 theme => $theme,
60 modules => "$staff_dir/$theme/en/modules",
61 includes => "$staff_dir/$theme/en/includes",
64 close $dh;
66 # Tests
67 foreach my $theme ( @themes ) {
68 print "Testing $theme->{'type'} $theme->{'theme'} templates\n";
69 if ( $theme->{'theme'} eq 'bootstrap' ) {
70 run_template_test(
71 $theme->{'modules'},
72 $theme->{'includes'},
73 # templates to exclude from testing because
74 # they cannot stand alone
75 'doc-head-close.inc',
76 'opac-bottom.inc',
79 else {
80 run_template_test(
81 $theme->{'modules'},
82 $theme->{'includes'},
87 done_testing();
89 sub run_template_test {
90 my $template_path = shift;
91 my $include_path = shift;
92 my @exclusions = @_;
93 my $template_dir = File::Spec->rel2abs($template_path);
94 my $include_dir = File::Spec->rel2abs($include_path);
95 my $template_test = create_template_test($include_dir, @exclusions);
96 find( { wanted => $template_test, no_chdir => 1 },
97 $template_dir, $include_dir );
100 sub create_template_test {
101 my $includes = shift;
102 my @exclusions = @_;
103 return sub {
104 my $tt = Template->new(
106 ABSOLUTE => 1,
107 INCLUDE_PATH => $includes,
108 PLUGIN_BASE => 'Koha::Template::Plugin',
111 foreach my $exclusion (@exclusions) {
112 if ($_ =~ /${exclusion}$/) {
113 diag("excluding template $_ because it cannot stand on its own");
114 return;
117 my $vars;
118 my $output;
119 if ( ! -d $_ ) { # skip dirs
120 if ( !ok( $tt->process( $_, $vars, \$output ), $_ ) ) {
121 diag( $tt->error );
127 =head1 AUTHOR
129 Koha Development Team <http://koha-community.org>
131 Chris Cormack <chrisc@catalyst.net.nz>
133 =cut