183
|
1 package Test::Web::View;
|
|
2 use strict;
|
|
3 use warnings;
|
185
|
4 use utf8;
|
183
|
5
|
|
6 use parent qw(IMPL::Test::Unit);
|
|
7 __PACKAGE__->PassThroughArgs;
|
|
8
|
185
|
9 use File::Slurp;
|
|
10
|
183
|
11 use IMPL::Test qw(assert test);
|
|
12 use IMPL::Web::View::TTLoader();
|
|
13
|
|
14 use constant {
|
|
15 TTLoader => typeof IMPL::Web::View::TTLoader
|
|
16 };
|
|
17
|
185
|
18 sub templatesDir {
|
|
19 $_[0]->GetResourceDir('Resources','TTView');
|
|
20 }
|
|
21
|
|
22 test TTLoaderTests => sub {
|
183
|
23 my ($this) = @_;
|
|
24
|
|
25 my $loader = TTLoader->new(
|
|
26 {
|
|
27 INCLUDE_PATH => [
|
185
|
28 $this->templatesDir
|
183
|
29 ]
|
|
30 },
|
184
|
31 ext => '.tt',
|
|
32 initializer => 'global.tt'
|
183
|
33 );
|
|
34
|
184
|
35 # test the loader to be able to find a desired resource
|
|
36 assert( defined($loader->template('simple') ) );
|
|
37
|
|
38 # loader should be initialized on demand
|
|
39 assert( not $loader->isInitialized );
|
183
|
40
|
184
|
41 # loader should be able to load a document
|
|
42 my $doc = $loader->document('simple');
|
|
43 assert(defined $doc);
|
|
44
|
|
45 assert( $loader->isInitialized );
|
|
46 assert( $loader->context->stash->get('user') eq 'test_user');
|
|
47
|
|
48 # document should inherit loader's context
|
|
49 assert( $doc->context->stash->get('user') eq 'test_user');
|
183
|
50 };
|
|
51
|
185
|
52 test TTDocumentTests => sub {
|
|
53 my ($this) = @_;
|
|
54 my $loader = TTLoader->new(
|
|
55 {
|
|
56 INCLUDE_PATH => [
|
|
57 $this->templatesDir
|
|
58 ],
|
|
59 INTERPOLATE => 1,
|
|
60 POST_CHOMP => 1,
|
|
61 ENCODING => 'utf-8'
|
|
62 },
|
|
63 ext => '.tt',
|
|
64 initializer => 'global.tt'
|
|
65 );
|
|
66
|
|
67 my $doc = $loader->document('simple');
|
|
68
|
|
69 assert(defined $doc);
|
|
70
|
|
71 assert($doc->nodeName eq 'document');
|
|
72 assert(not $doc->can('notexists')); # autoloaded property should be ignored
|
|
73 assert($doc->notexists eq ''); # nonexisting property
|
|
74 assert($doc->version == 10); # static metadata
|
|
75 assert($doc->user eq 'test_user'); # global data
|
|
76 assert($doc->templateVar eq 'initialized by the constructor'); # defined in CTOR block
|
|
77
|
|
78 my $text = $doc->Render();
|
|
79 my $expected = read_file($this->GetResourceFile('Resources','TTView.Output','simple.txt'), binmode => ':utf8');
|
|
80
|
|
81 assert($text eq $expected, "Bad Render() output","Got: $text", "Expected: $expected");
|
|
82
|
|
83 };
|
|
84
|
183
|
85 1; |