004template.t 3.38 KB
Newer Older
1 2 3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
#
5 6
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
7 8 9

#################
#Bugzilla Test 4#
10
####Templates####
11

12
use strict;
13 14 15 16

use lib 't';

use Support::Templates;
17

18 19 20
# Bug 137589 - Disable command-line input of CGI.pm when testing
use CGI qw(-no_debug);

21
use File::Spec;
22
use Template;
23
use Test::More tests => ( scalar(@referenced_files) + $num_actual_files );
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38
# Capture the TESTOUT from Test::More or Test::Builder for printing errors.
# This will handle verbosity for us automatically.
my $fh;
{
    local $^W = 0;  # Don't complain about non-existent filehandles
    if (-e \*Test::More::TESTOUT) {
        $fh = \*Test::More::TESTOUT;
    } elsif (-e \*Test::Builder::TESTOUT) {
        $fh = \*Test::Builder::TESTOUT;
    } else {
        $fh = \*STDOUT;
    }
}

39 40 41 42
# Check to make sure all templates that are referenced in Bugzilla
# exist in the proper place in the English template directory.
# All other languages may or may not include any template as Bugzilla will
# fall back to English if necessary.
43

44
foreach my $file (@referenced_files) {
45 46
    my $path = File::Spec->catfile($english_default_include_path, $file);
    if (-e $path) {
47 48
        ok(1, "$path exists");
    } else {
49
        ok(0, "$path cannot be located --ERROR");
50 51 52
    }
}

53 54 55
foreach my $include_path (@include_paths) {
    # Processes all the templates to make sure they have good syntax
    my $provider = Template::Provider->new(
56
    {
57 58 59
        INCLUDE_PATH => $include_path ,
        # Need to define filters used in the codebase, they don't
        # actually have to function in this test, just be defined.
60
        # See Template.pm for the actual codebase definitions.
61 62

        # Initialize templates (f.e. by loading plugins like Hook).
63
        PRE_PROCESS => "global/variables.none.tmpl",
64

65 66 67
        FILTERS =>
        {
            html_linebreak => sub { return $_; },
68
            no_break => sub { return $_; } ,
69
            js        => sub { return $_ } ,
70
            base64   => sub { return $_ } ,
71 72 73
            inactive => [ sub { return sub { return $_; } }, 1] ,
            closed => [ sub { return sub { return $_; } }, 1] ,
            obsolete => [ sub { return sub { return $_; } }, 1] ,
74
            url_quote => sub { return $_ } ,
75
            css_class_quote => sub { return $_ } ,
76 77 78 79
            xml       => sub { return $_ } ,
            quoteUrls => sub { return $_ } ,
            bug_link => [ sub { return sub { return $_; } }, 1] ,
            csv       => sub { return $_ } ,
80
            unitconvert => sub { return $_ },
81
            time      => sub { return $_ } ,
82
            wrap_comment => sub { return $_ },
83
            none      => sub { return $_ } ,
84
            ics       => [ sub { return sub { return $_; } }, 1] ,
85 86 87 88 89 90
        },
    }
    );

    foreach my $file (@{$actual_files{$include_path}}) {
        my $path = File::Spec->catfile($include_path, $file);
91 92 93 94 95 96 97

        # These are actual files, so there's no need to check for existence.

        my ($data, $err) = $provider->fetch($file);

        if (!$err) {
            ok(1, "$path syntax ok");
98 99
        }
        else {
100 101
            ok(0, "$path has bad syntax --ERROR");
            print $fh $data . "\n";
102 103
        }
    }
104
}
105 106

exit 0;