1 # -*- Mode: perl; indent-tabs-mode: nil -*-
 
   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/
 
   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.
 
  13 # The Original Code are the Bugzilla tests.
 
  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
 
  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>
 
  34 use Support::Templates;
 
  36 # Bug 137589 - Disable command-line input of CGI.pm when testing
 
  37 use CGI qw(-no_debug);
 
  41 use Test::More tests => ( scalar(@referenced_files) * scalar(@languages)
 
  42                         + $num_actual_files  );
 
  44 # Capture the TESTOUT from Test::More or Test::Builder for printing errors.
 
  45 # This will handle verbosity for us automatically.
 
  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;
 
  58 # Checks whether one of the passed files exists
 
  60   foreach my $file (@_) {
 
  61     return $file  if -e $file;
 
  66 # Check to make sure all templates that are referenced in
 
  67 # Bugzilla exist in the proper place.
 
  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");
 
  76             ok(0, "$file cannot be located --ERROR");
 
  77             print $fh "Looked in:\n  " . join("\n  ", @path) . "\n";
 
  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(
 
  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.
 
  91         # Initialize templates (f.e. by loading plugins like Hook).
 
  92         PRE_PROCESS => "global/initialize.none.tmpl",
 
  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] ,
 
 118     foreach my $file (@{$actual_files{$include_path}}) {
 
 119         my $path = File::Spec->catfile($include_path, $file);
 
 121             my ($data, $err) = $provider->fetch($file);
 
 124                 ok(1, "$file syntax ok");
 
 127                 ok(0, "$file has bad syntax --ERROR");
 
 128                 print $fh $data . "\n";
 
 132             ok(1, "$path doesn't exist, skipping test");
 
 136     # check to see that all templates have a version string:
 
 137     # disabled for lx-office
 
 139 #    foreach my $file (@{$actual_files{$include_path}}) {
 
 140 #        my $path = File::Spec->catfile($include_path, $file);
 
 142 #        my $firstline = <TMPL>;
 
 143 #        if ($firstline =~ /\d+\.\d+\@[\w\.-]+/) {
 
 144 #            ok(1,"$file has a version string");
 
 146 #            ok(0,"$file does not have a version string --ERROR");