004template.t 2.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code are the Bugzilla tests.
#
# The Initial Developer of the Original Code is Jacob Steenhagen.
# Portions created by Jacob Steenhagen are
# Copyright (C) 2001 Jacob Steenhagen. All
# Rights Reserved.
#
# Contributor(s): Jacob Steenhagen <jake@acutex.net>
21
#                   Zach Lipton <zach@zachlipton.com>
22 23 24 25
#

#################
#Bugzilla Test 4#
26
####Templates####
27 28 29

BEGIN { use lib "t/"; }
BEGIN { use Support::Templates; }
30
BEGIN { $tests = @Support::Templates::testitems * 3; }
31 32
BEGIN { use Test::More tests => $tests; }

33
use strict;
34 35 36
use Template;

my @testitems = @Support::Templates::testitems;
37
my $include_path = $Support::Templates::include_path;
38 39 40
# Capture the TESTERR from Test::More for printing errors.
# This will handle verbosity for us automatically
*TESTOUT = \*Test::More::TESTOUT;
41 42 43

# Check to make sure all templates that are referenced in
# Bugzilla exist in the proper place.
44

45
my %exists;
46
foreach my $file(@testitems) {
47
    if (-e $include_path . "/" . $file) {
48
        ok(1, "$file exists");
49
        $exists{$file} = 1;
50
    } else {
51
        ok(0, "$file does not exist --ERROR");
52 53 54 55
    }
}

# Processes all the templates to make sure they have good syntax
56 57 58 59 60 61 62
my $template = Template->new(
{
    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.
    FILTERS =>
    {
63 64
        strike => sub { return $_ } ,
        js     => sub { return $_ }
65
    },
66 67
}
);
68 69

open SAVEOUT, ">&STDOUT";     # stash the original output stream
70
open SAVEERR, ">&STDERR";
71
open STDOUT, "> /dev/null";   # discard all output
72
open STDERR, "> /dev/null";
73
foreach my $file(@testitems) {
74 75 76 77 78 79 80 81 82 83
    if ($exists{$file}) {
        if ($template->process($file)) {
            ok(1, "$file syntax ok");
        }
        else {
            print TESTOUT $template->error() . "\n";
            ok(0, "$file has bad syntax --ERROR");
        }
    }
    else {
84
        ok(1, "$file doesn't exist, skipping test");
85 86 87
    }
}
open STDOUT, ">&SAVEOUT";     # redirect back to original stream
88
open STDERR, ">&SAVEERR";
89
close SAVEOUT;
90
close SAVEERR;
91 92 93 94 95 96 97 98 99 100 101 102 103

# check to see that all templates have a version string:

foreach my $file(@testitems) {
    open(TMPL,"$include_path/$file");
    my $firstline = <TMPL>;
    if ($firstline =~ /<!-- \d+\.\d+\@[\w\._]+ -->/) {
        ok(1,"$file has a version string");
    } else {
        ok(0,"$file does not have a version string --ERROR");
    }
    close(TMPL);
}