Merge branch 'master' of ssh://lx-office/~/lx-office-erp
[kivitendo-erp.git] / t / 004template.t
1 # -*- Mode: perl; indent-tabs-mode: nil -*-
2 #
3 # The contents of this file are subject to the Mozilla Public
4 # License Version 1.1 (the "License"); you may not use this file
5 # except in compliance with the License. You may obtain a copy of
6 # the License at http://www.mozilla.org/MPL/
7 #
8 # Software distributed under the License is distributed on an "AS
9 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 # implied. See the License for the specific language governing
11 # rights and limitations under the License.
12 #
13 # The Original Code are the Bugzilla tests.
14 #
15 # The Initial Developer of the Original Code is Jacob Steenhagen.
16 # Portions created by Jacob Steenhagen are
17 # Copyright (C) 2001 Jacob Steenhagen. All
18 # Rights Reserved.
19 #
20 # Contributor(s): Jacob Steenhagen <jake@bugzilla.org>
21 #                 Zach Lipton <zach@zachlipton.com>
22 #                 David D. Kilzer <ddkilzer@kilzer.net>
23 #                 Tobias Burnus <burnus@net-b.de>
24 #
25
26 #################
27 #Bugzilla Test 4#
28 ####Templates####
29
30 use strict;
31
32 use lib 't';
33
34 use Support::Templates;
35
36 # Bug 137589 - Disable command-line input of CGI.pm when testing
37 use CGI qw(-no_debug);
38
39 use File::Spec;
40 use Template;
41 use Test::More tests => ( scalar(@referenced_files) * scalar(@languages)
42                         + $num_actual_files  );
43
44 # Capture the TESTOUT from Test::More or Test::Builder for printing errors.
45 # This will handle verbosity for us automatically.
46 my $fh;
47 {
48     local $^W = 0;  # Don't complain about non-existent filehandles
49     if (-e \*Test::More::TESTOUT) {
50         $fh = \*Test::More::TESTOUT;
51     } elsif (-e \*Test::Builder::TESTOUT) {
52         $fh = \*Test::Builder::TESTOUT;
53     } else {
54         $fh = \*STDOUT;
55     }
56 }
57
58 # Checks whether one of the passed files exists
59 sub existOnce {
60   foreach my $file (@_) {
61     return $file  if -e $file;
62   }
63   return 0;
64 }
65
66 # Check to make sure all templates that are referenced in
67 # Bugzilla exist in the proper place.
68
69 foreach my $lang (@languages) {
70     foreach my $file (@referenced_files) {
71         my @path = map(File::Spec->catfile($_, $file),
72                        split(':', $include_path{$lang} . ":" . $include_path{"en"}));
73         if (my $path = existOnce(@path)) {
74             ok(1, "$path exists");
75         } else {
76             ok(0, "$file cannot be located --ERROR");
77             print $fh "Looked in:\n  " . join("\n  ", @path) . "\n";
78         }
79     }
80 }
81
82 foreach my $include_path (@include_paths) {
83     # Processes all the templates to make sure they have good syntax
84     my $provider = Template::Provider->new(
85     {
86         INCLUDE_PATH => $include_path ,
87         # Need to define filters used in the codebase, they don't
88         # actually have to function in this test, just be defined.
89         # See Template.pm for the actual codebase definitions.
90
91         # Initialize templates (f.e. by loading plugins like Hook).
92         PRE_PROCESS => "global/initialize.none.tmpl",
93
94         FILTERS =>
95         {
96             html_linebreak => sub { return $_; },
97             no_break => sub { return $_; } ,
98             js        => sub { return $_ } ,
99             base64   => sub { return $_ } ,
100             inactive => [ sub { return sub { return $_; } }, 1] ,
101             closed => [ sub { return sub { return $_; } }, 1] ,
102             obsolete => [ sub { return sub { return $_; } }, 1] ,
103             url_quote => sub { return $_ } ,
104             css_class_quote => sub { return $_ } ,
105             xml       => sub { return $_ } ,
106             quoteUrls => sub { return $_ } ,
107             bug_link => [ sub { return sub { return $_; } }, 1] ,
108             csv       => sub { return $_ } ,
109             unitconvert => sub { return $_ },
110             time      => sub { return $_ } ,
111             wrap_comment => sub { return $_ },
112             none      => sub { return $_ } ,
113             ics       => [ sub { return sub { return $_; } }, 1] ,
114         },
115     }
116     );
117
118     foreach my $file (@{$actual_files{$include_path}}) {
119         my $path = File::Spec->catfile($include_path, $file);
120         if (-e $path) {
121             my ($data, $err) = $provider->fetch($file);
122
123             if (!$err) {
124                 ok(1, "$file syntax ok");
125             }
126             else {
127                 ok(0, "$file has bad syntax --ERROR");
128                 print $fh $data . "\n";
129             }
130         }
131         else {
132             ok(1, "$path doesn't exist, skipping test");
133         }
134     }
135
136     # check to see that all templates have a version string:
137     # disabled for lx-office
138
139 #    foreach my $file (@{$actual_files{$include_path}}) {
140 #        my $path = File::Spec->catfile($include_path, $file);
141 #        open(TMPL, $path);
142 #        my $firstline = <TMPL>;
143 #        if ($firstline =~ /\d+\.\d+\@[\w\.-]+/) {
144 #            ok(1,"$file has a version string");
145 #        } else {
146 #            ok(0,"$file does not have a version string --ERROR");
147 #        }
148 #        close(TMPL);
149 #    }
150 }
151
152 exit 0;