File: 09_precompile_dir.t

package info (click to toggle)
libcgi-application-plugin-tt-perl 1.05%2B~cs1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 440 kB
  • sloc: perl: 806; makefile: 17
file content (53 lines) | stat: -rw-r--r-- 1,597 bytes parent folder | download | duplicates (5)
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
use strict;
use lib './t';
use Test::More tests => 6;
use TestAppPrecompile;
use File::Spec::Functions qw(catdir catfile rel2abs);

# get a temp directory that we can later look into
# to find the pre-compiled templates
my $tt_dir = catdir('t', 'include1', 'TestAppIncludePath');
my $file   = rel2abs(catfile($tt_dir, 'test_mode.tmpl'));

test_success('tmpl');
test_success(qr/\.(tt|tmpl|html)$/);
test_success(sub { rel2abs($_[0]) eq $file });

test_failure('nottmpl');
test_failure(qr/\.(nottmpl)$/);
test_failure(sub { rel2abs($_[0]) eq 'blahblah' });


sub test_success {
    my $cgiapp = TestAppPrecompile->new(PARAMS => {
            TEMPLATE_PRECOMPILE_FILETEST => shift,
            TT_DIR => $tt_dir,
    });
    my $tt     = $cgiapp->tt_obj;

    # make sure we have this internally cached in our TT obj
    # This is kinda dirty since we are peeking pretty far into TT's internals
    # but it doesn't expose this stuff externally
    is(
        rel2abs($tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0]->{HEAD}->[1]),
        $file,
        'file is cached'
    );
}

sub test_failure {
    my $cgiapp = TestAppPrecompile->new(PARAMS => {
            TEMPLATE_PRECOMPILE_FILETEST => shift,
            TT_DIR => $tt_dir,
    });
    my $tt     = $cgiapp->tt_obj;

    # make sure we have this internally cached in our TT obj
    # This is kinda dirty since we are peeking pretty far into TT's internals
    # but it doesn't expose this stuff externally
    is(
        $tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0]->{HEAD}->[1],
        undef,
        'file is not cached'
    );
}