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
|
186
|
85 test TTControlTests => sub {
|
|
86 my ($this) = @_;
|
|
87
|
|
88 my $loader = TTLoader->new(
|
|
89 {
|
|
90 INCLUDE_PATH => [
|
|
91 $this->templatesDir
|
|
92 ],
|
|
93 INTERPOLATE => 1,
|
|
94 POST_CHOMP => 1,
|
|
95 ENCODING => 'utf8'
|
|
96 },
|
|
97 ext => '.tt',
|
|
98 initializer => 'global.tt'
|
|
99 );
|
|
100
|
|
101 my $doc = $loader->document('simple');
|
|
102
|
|
103 assert(defined $doc);
|
|
104
|
|
105 my $factory = $doc->require('My/Org/Panel');
|
|
106
|
|
107 assert(defined $factory);
|
|
108
|
|
109 assert($factory == $doc->require('My/Org/Panel'), "Control should be loaded only once");
|
|
110
|
|
111 my $ctl = $factory->new('information', { visualClass => 'simple' } );
|
|
112
|
|
113 assert(defined $ctl);
|
|
114
|
|
115
|
|
116 assert($ctl->nodeName eq 'information', "Created control should have a name", "Got: ".$ctl->nodeName, "Expected: information");
|
|
117
|
|
118 assert($ctl->nodeProperty('visualClass') eq 'simple');
|
|
119
|
|
120 assert($ctl->controlObject == $ctl);
|
|
121
|
|
122 assert($factory->instances == 1);
|
|
123
|
|
124 assert($doc->context->stash->get('My.Org.Panel') == $factory);
|
|
125
|
|
126 my $text = $ctl->Render();
|
|
127 my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'Panel.txt'), binmode => ':utf8');
|
|
128
|
|
129 assert($text eq $expected, '$ctl->Render(): Bad output', "Got: $text", "Expected: $expected");
|
|
130
|
|
131 };
|
|
132
|
183
|
133 1; |