annotate _test/Test/Web/View.pm @ 288:3a9cfea098dd

*TTView refactoring: removed RequireControl method, etc.
author sergey
date Tue, 19 Feb 2013 19:58:27 +0400
parents 2d253e6e4a88
children 85572f512abc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
1 package Test::Web::View;
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
2 use IMPL::Profiler::Memory;
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
3 use strict;
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
4 use warnings;
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
5 use utf8;
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
6
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
7 use parent qw(IMPL::Test::Unit);
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
8 __PACKAGE__->PassThroughArgs;
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
9
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
10 use File::Slurp;
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
11 use Scalar::Util qw(weaken);
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
12 use Data::Dumper;
280
c6d0f889ef87 +IMPL::declare now supports meta attributes
cin
parents: 263
diff changeset
13 use IMPL::lang;
286
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
14 use IMPL::Test qw(assert assertarray test GetCallerSourceLine);
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
15 use IMPL::Web::View::TTLoader();
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
16
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
17 use constant {
280
c6d0f889ef87 +IMPL::declare now supports meta attributes
cin
parents: 263
diff changeset
18 TTLoader => 'IMPL::Web::View::TTLoader',
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
19 MProfiler => 'IMPL::Profiler::Memory'
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
20 };
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
21
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
22 sub AssertMemoryLeak {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
23 my $code = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
24 my $dump = shift;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
25
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
26 my $data = MProfiler->Monitor($code);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
27
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
28 if ($data->isLeak and $dump) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
29 write_file("dump.out", { binmode => ':utf8' }, $data->Dump() );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
30 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
31
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
32 assert( not($data->isLeak), "Memory leak detected", GetCallerSourceLine() , @{$data->{objects}} );
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
33 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
34
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
35 sub templatesDir {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
36 $_[0]->GetResourceDir('Resources','TTView');
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
37 }
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
38
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
39 sub CreateLoader {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
40 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
41
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
42 my $loader = TTLoader->new(
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
43 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
44 INCLUDE_PATH => [
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
45 $this->templatesDir
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
46 ],
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
47 INTERPOLATE => 1,
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
48 POST_CHOMP => 1,
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
49 ENCODING => 'utf-8'
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
50 },
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
51 ext => '.tt',
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
52 initializer => 'global.tt',
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
53 globals => {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
54 site => {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
55 name => 'Test Site'
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
56 },
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
57 date => {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
58 now => sub { localtime(time); }
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
59 },
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
60 dynamic => sub { 'this is a dynamic value' },
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
61 view => {
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
62 }
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
63 },
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
64 layoutBase => 'Layout'
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
65 );
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
66 }
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
67
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
68 test TTLoaderTests => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
69 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
70
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
71 my $loader = $this->CreateLoader();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
72
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
73 # test the loader to be able to find a desired resource
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
74 assert( defined($loader->template('simple') ) );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
75
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
76 # loader should be initialized on demand
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
77 assert( not $loader->isInitialized );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
78
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
79 # loader should be able to load a document
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
80 my $doc = $loader->document('simple');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
81 assert(defined $doc);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
82
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
83 assert( $loader->isInitialized );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
84 assert( $loader->context->stash->get('user') eq 'test_user');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
85
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
86 # document should inherit loader's context
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
87 assert( $doc->context->stash->get('user') eq 'test_user');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
88
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
89 # document should not have 'this' template variable
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
90 assert( not $doc->templateVars('this') );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
91
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
92 assert( $doc->context != $loader->context); # document should have an own context
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
93 };
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
94
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
95 test TTDocumentTests => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
96 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
97 my $loader = $this->CreateLoader();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
98
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
99 my $doc = $loader->document('simple');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
100
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
101 assert(defined $doc);
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
102
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
103 $doc->title('test document');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
104
238
b8c724f6de36 DOM model refactoring
sergey
parents: 195
diff changeset
105 assert($doc->name eq 'document');
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
106 assert($doc->title eq 'test document');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
107
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
108 assert(not $doc->can('notexists')); # autoloaded property should be ignored
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
109 assert(not defined $doc->notexists); # nonexisting property
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
110 assert($doc->template->version == 10); # static metadata
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
111 assert($doc->templateVars('notexists') eq ''); #nonexisting template variable
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
112 assert($doc->templateVars('user') eq 'test_user'); # global data
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
113 assert($doc->templateVars('templateVar') eq ''); # defined in CTOR block, should be local
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
114 assert($doc->templateVars('dynamic') eq 'this is a dynamic value');
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
115 assert($doc->context->stash->get('user') eq 'test_user' ); # runtime context should be derived from documentContext
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
116 $doc->context->stash->set('user', 'nobody');
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
117 assert($doc->templateVars('user') eq 'test_user'); # isolated
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
118 $doc->context->stash->set('user', 'test_user');
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
119
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
120 my $text = $doc->Render();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
121 my $expected = read_file($this->GetResourceFile('Resources','TTView.Output','simple.txt'), binmode => ':utf8');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
122
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
123 assert($text eq $expected, "Bad Render() output","Got: $text", "Expected: $expected");
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
124
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
125 };
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
126
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
127 test TTControlTests => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
128 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
129
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
130 my $loader = $this->CreateLoader();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
131
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
132 my $doc = $loader->document('simple');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
133
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
134 assert(defined $doc);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
135
238
b8c724f6de36 DOM model refactoring
sergey
parents: 195
diff changeset
136 my $factory = $doc->RequireControl('My/Org/Panel');
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
137
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
138 assert(defined $factory);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
139
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 238
diff changeset
140 # control factory shares document scope to perform an initialization on demand
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 238
diff changeset
141 assert($factory->context->stash == $doc->context->stash);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
142
238
b8c724f6de36 DOM model refactoring
sergey
parents: 195
diff changeset
143 assert($factory == $doc->RequireControl('My/Org/Panel'), "Control should be loaded only once");
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
144
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
145 my $ctl = $factory->new('information', { visualClass => 'simple', data => ['one','two','hello world'] } );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
146
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
147 assert(defined $ctl);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
148
238
b8c724f6de36 DOM model refactoring
sergey
parents: 195
diff changeset
149 assert($ctl->name eq 'information', "Created control should have a name", "Got: ".$ctl->name, "Expected: information");
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
150
238
b8c724f6de36 DOM model refactoring
sergey
parents: 195
diff changeset
151 assert($ctl->GetAttribute('visualClass') eq 'simple');
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
152
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
153 assert($factory->instances == 1);
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
154
238
b8c724f6de36 DOM model refactoring
sergey
parents: 195
diff changeset
155 $doc->childNodes([$ctl]);
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
156
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
157 assert($doc->templateVars('dojo.require'));
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
158 assert(ref $doc->templateVars('dojo.require') eq 'ARRAY');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
159 assert($doc->templateVars('dojo.require')->[0] eq 'dijit.form.Input' );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
160
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
161 my $text = $ctl->Render();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
162
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
163 my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'Panel.txt'), binmode => ':utf8');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
164 assert($text eq $expected, '$ctl->Render(): Bad output', "Got: $text", "Expected: $expected");
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
165
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
166
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
167 my $doc2 = $loader->document('simple');
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
168
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
169 assert( $doc2->documentContext->stash->get( ['require',['My/Org/Panel'] ] ) );
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
170 print Dumper($doc2->context->stash);
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
171 assert( $doc2->context->stash->get( ['require',['My/Org/Panel'] ] ) );
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
172
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
173
191
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 190
diff changeset
174 };
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 190
diff changeset
175
78a18a2b6266 IMPL::Web::View improvements (unstable)
cin
parents: 190
diff changeset
176 test TestDocumentLayout => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
177 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
178
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
179 my $loader = $this->CreateLoader();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
180
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
181 my $doc = $loader->document(
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
182 'complex',
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
183 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
184 data => [qw(one two three)],
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
185 site => {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
186 name => 'Test Site'
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
187 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
188 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
189 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
190
195
7a920771fd8e IMPL::Web::View changed document layout handling, docs, examples
cin
parents: 194
diff changeset
191 assert($doc->layout eq 'default');
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
192
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
193 my $text = $doc->Render();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
194 my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'complex.default.txt'), binmode => ':utf8' );
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
195 my ($text_raw,$expected_raw) = ($text, $expected);
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
196 $text_raw =~ s/\s+//g;
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
197 $expected_raw =~ s/\s+//g;
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
198 assert($text_raw eq $expected_raw, '$doc->Render(): Bad output', "Got: $text", "Expected: $expected");
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
199 };
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
200
286
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
201 test TestDocumentsIsolation => sub {
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
202 my $this = shift;
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
203
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
204 my $loader = $this->CreateLoader();
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
205
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
206 my $doc = $loader->document('simple');
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
207
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
208 assert(ref $loader->context->stash->get([ 'dojo', 0, 'require', 0]) eq 'ARRAY');
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
209 assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]);
288
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
210 assert($loader->context->stash != $doc->context->stash);
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
211 assert($loader->context->stash != $doc->documentContext->stash);
3a9cfea098dd *TTView refactoring: removed RequireControl method, etc.
sergey
parents: 287
diff changeset
212 assert($doc->context->stash != $doc->documentContext->stash);
286
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
213
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
214 assert(defined $doc);
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
215
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
216 # only root stash variables can be localized, to avoid modifying dojo we
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
217 # need to replace it completely
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
218 $doc->context->process(\q{
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
219 [% SET dojo = { require => [] } %]
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
220 [% dojo.require.push('dijit/form/TextBox') %]
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
221 [% SET user = 'dummy guy' %]
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
222 });
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
223
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
224 assert($doc->context->stash->get('user') eq 'dummy guy');
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
225 assert($loader->context->stash->get('user') eq 'test_user');
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
226 assertarray($doc->context->stash->get([ 'dojo', 0, 'require', 0]),['dijit/form/TextBox']);
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
227 assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]);
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
228
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
229 my $text = $doc->Render();
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
230
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
231 my $doc2 = $loader->document('complex');
286
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
232
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
233 assertarray($doc2->context->stash->get([ 'dojo', 0, 'require', 0]),[]);
287
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
234
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
235 # This document has a layout ehich will replace 'dojo' global variable.
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
236 # The layout contains INIT block which runs first in the context of the
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
237 # document, then RenderContent is called and then the layout is applied
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
238 $doc2->Render();
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
239
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
240 assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]);
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
241
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
242 # TODO: to be able to rendered multiple times, Render shouldn't affect the context of the document
2d253e6e4a88 *TTView refactoring
cin
parents: 286
diff changeset
243 #assertarray($doc2->context->stash->get([ 'dojo', 0, 'require', 0]),[]);
286
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
244 };
d357b5d85d25 *TTView refactoring
sergey
parents: 280
diff changeset
245
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
246 test TestMemoryLeaks => sub {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
247 my ($this) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
248
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
249 my $loader = $this->CreateLoader();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
250 $loader->document('simple'); # force loader initialization
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
251
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
252 AssertMemoryLeak(sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
253 my $doc = $loader->document('simple');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
254 });
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
255
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
256 AssertMemoryLeak(sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
257 my $doc = $loader->document('simple');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
258 $doc->Render( { self => $doc } );
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
259 });
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
260
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
261 $loader->template('Layout/default');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
262 $loader->template('My/Org/Panel');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
263 $loader->template('My/Org/TextPreview');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
264 AssertMemoryLeak(sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
265 my $doc = $loader->document('simple');
238
b8c724f6de36 DOM model refactoring
sergey
parents: 195
diff changeset
266 my $factory = $doc->RequireControl('My/Org/Panel');
b8c724f6de36 DOM model refactoring
sergey
parents: 195
diff changeset
267 my $ctl = $doc->childNodes($factory->new('information', { visualClass => 'complex' }) );
263
0f59b2de72af *fixed IMPL::DOM::Schema circular module references
sergey
parents: 238
diff changeset
268 },'dump');
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
269
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
270 $loader->template('complex');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
271 AssertMemoryLeak(sub {
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
272 my $doc = $loader->document('complex');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
273 $doc->Render();
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
274 },'dump');
4d0e1962161c Replaced tabs with spaces
cin
parents: 191
diff changeset
275
188
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
276 };
029c9610528c Memory leak tests in IMPL::Web::View
cin
parents: 186
diff changeset
277
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
278 1;