File: 24-tt_opts.t

package info (click to toggle)
libcgi-application-plugin-anytemplate-perl 0.18-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 772 kB
  • sloc: perl: 1,073; sh: 8; makefile: 2
file content (111 lines) | stat: -rwxr-xr-x 2,539 bytes parent folder | download | duplicates (4)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 2;

my %Expected_Output;

$Expected_Output{'wrapper'} = qq{wrapper-begin
--begin--
var1:value1
var2:value2
var3:value3
--end--

wrapper-end};

$Expected_Output{'no_wrapper'} = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF


{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;

        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->template('no_wrapper')->config( # for templates not requiring wrapper
          type          => 'TemplateToolkit',
          include_paths => 't/tmpl',
        );

        $self->template('wrapper')->config( # default AnyTemplate config
          type => 'TemplateToolkit',
          include_paths   => 't/tmpl',
          TemplateToolkit => {
            WRAPPER => 'wrapper.tmpl',
          },
        );
    }

    sub simple {
        my $self = shift;

        # named config 'wrapper'
        my $expected_output = $Expected_Output{'wrapper'};

        my $output = $self->template('wrapper')->fill({
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        });
        $output = $$output if ref $output eq 'SCALAR';
        is($output, $expected_output, "(wrapper) Got expected output");


        # named config 'no_wrapper'
        $expected_output = $Expected_Output{'no_wrapper'};

        $output = $self->template('no_wrapper')->fill({
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        });
        $output = $$output if ref $output eq 'SCALAR';
        is($output, $expected_output, "(no_wrapper) Got expected output");
        '';
    }
}

SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}