File: 06_dyn_include.t

package info (click to toggle)
libhtml-template-compiled-perl 0.97-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 756 kB
  • sloc: perl: 4,504; makefile: 5
file content (73 lines) | stat: -rw-r--r-- 1,859 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl HTML-Template-Compiled.t'
# $Id: 06_dyn_include.t 1069 2008-07-26 11:04:03Z tinita $

use lib 'blib/lib';
use Test::More tests => 10;
BEGIN { use_ok('HTML::Template::Compiled') };
#$HTML::Template::Compiled::NEW_CHECK = 2;

my $htc = HTML::Template::Compiled->new(
	path => 't/templates',
	filename => 'dyn_include.htc',
	debug => 0,
);
#exit;
for my $ix (1..2,undef) {
	$htc->param(
        file => (defined $ix? "dyn_included$ix.htc" : undef),
		test => 23,
	);
    my $out;
    eval {
        $out = $htc->output;
    };
    if (defined $ix) {
        #print $out;
        $out =~ s/\r\n|\r/\n/g;
        cmp_ok($out, "=~",
            "Dynamic include:", "dynamic include $ix.1");
        cmp_ok($out, "=~", "This is dynamically included file $ix\.", "dynamic include $ix.2");
        cmp_ok($out, "=~", "23", "dynamic include $ix.3");
    }
    else {
        #print "Error: $@\n";
        #print "out: $out\n";
        cmp_ok($out, "=~", 'Dynamic include:\s+$', "undefined filename");
    }
}

{
    my $htc = HTML::Template::Compiled->new(
        scalarref => \<<'EOM',
inc: <%include_string foo %>
EOM
        debug => 0,
    );
    $htc->param(
        foo => 'included=<%= bar%>',
        bar => 'real',
    );
    my $out = $htc->output;
    #print "out: $out\n";
    my $exp = 'inc: included=real';
    cmp_ok($out, '=~', $exp, "include_string");
}

{
    my $htc;
    eval {
        $htc = HTML::Template::Compiled->new(
            filename => 'user_template.html',
            path => 't/templates',
            no_includes => 1,
        );
    };
    my $error = "$@";
    cmp_ok($error, '=~', 'Syntax error.*near.*include', "no_includes");
}

__END__
Dynamic include:
This is dynamically included file 1.
23