Mercurial > pub > Impl
comparison _test/Test/Web/View.pm @ 289:85572f512abc
*TTView refactoring
author | cin |
---|---|
date | Wed, 20 Feb 2013 02:25:30 +0400 |
parents | 3a9cfea098dd |
children | aeeb57a12046 |
comparison
equal
deleted
inserted
replaced
288:3a9cfea098dd | 289:85572f512abc |
---|---|
85 | 85 |
86 # document should inherit loader's context | 86 # document should inherit loader's context |
87 assert( $doc->context->stash->get('user') eq 'test_user'); | 87 assert( $doc->context->stash->get('user') eq 'test_user'); |
88 | 88 |
89 # document should not have 'this' template variable | 89 # document should not have 'this' template variable |
90 assert( not $doc->templateVars('this') ); | |
91 | 90 |
92 assert( $doc->context != $loader->context); # document should have an own context | 91 assert( $doc->context != $loader->context); # document should have an own context |
93 }; | 92 }; |
94 | 93 |
95 test TTDocumentTests => sub { | 94 test TTDocumentTests => sub { |
106 assert($doc->title eq 'test document'); | 105 assert($doc->title eq 'test document'); |
107 | 106 |
108 assert(not $doc->can('notexists')); # autoloaded property should be ignored | 107 assert(not $doc->can('notexists')); # autoloaded property should be ignored |
109 assert(not defined $doc->notexists); # nonexisting property | 108 assert(not defined $doc->notexists); # nonexisting property |
110 assert($doc->template->version == 10); # static metadata | 109 assert($doc->template->version == 10); # static metadata |
111 assert($doc->templateVars('notexists') eq ''); #nonexisting template variable | |
112 assert($doc->templateVars('user') eq 'test_user'); # global data | |
113 assert($doc->templateVars('templateVar') eq ''); # defined in CTOR block, should be local | |
114 assert($doc->templateVars('dynamic') eq 'this is a dynamic value'); | |
115 assert($doc->context->stash->get('user') eq 'test_user' ); # runtime context should be derived from documentContext | 110 assert($doc->context->stash->get('user') eq 'test_user' ); # runtime context should be derived from documentContext |
116 $doc->context->stash->set('user', 'nobody'); | |
117 assert($doc->templateVars('user') eq 'test_user'); # isolated | |
118 $doc->context->stash->set('user', 'test_user'); | |
119 | 111 |
120 my $text = $doc->Render(); | 112 my $text = $doc->Render(); |
121 my $expected = read_file($this->GetResourceFile('Resources','TTView.Output','simple.txt'), binmode => ':utf8'); | 113 my $expected = read_file($this->GetResourceFile('Resources','TTView.Output','simple.txt'), binmode => ':utf8'); |
122 | 114 |
123 assert($text eq $expected, "Bad Render() output","Got: $text", "Expected: $expected"); | 115 assert($text eq $expected, "Bad Render() output","Got: $text", "Expected: $expected"); |
124 | |
125 }; | |
126 | |
127 test TTControlTests => sub { | |
128 my ($this) = @_; | |
129 | |
130 my $loader = $this->CreateLoader(); | |
131 | |
132 my $doc = $loader->document('simple'); | |
133 | |
134 assert(defined $doc); | |
135 | |
136 my $factory = $doc->RequireControl('My/Org/Panel'); | |
137 | |
138 assert(defined $factory); | |
139 | |
140 # control factory shares document scope to perform an initialization on demand | |
141 assert($factory->context->stash == $doc->context->stash); | |
142 | |
143 assert($factory == $doc->RequireControl('My/Org/Panel'), "Control should be loaded only once"); | |
144 | |
145 my $ctl = $factory->new('information', { visualClass => 'simple', data => ['one','two','hello world'] } ); | |
146 | |
147 assert(defined $ctl); | |
148 | |
149 assert($ctl->name eq 'information', "Created control should have a name", "Got: ".$ctl->name, "Expected: information"); | |
150 | |
151 assert($ctl->GetAttribute('visualClass') eq 'simple'); | |
152 | |
153 assert($factory->instances == 1); | |
154 | |
155 $doc->childNodes([$ctl]); | |
156 | |
157 assert($doc->templateVars('dojo.require')); | |
158 assert(ref $doc->templateVars('dojo.require') eq 'ARRAY'); | |
159 assert($doc->templateVars('dojo.require')->[0] eq 'dijit.form.Input' ); | |
160 | |
161 my $text = $ctl->Render(); | |
162 | |
163 my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'Panel.txt'), binmode => ':utf8'); | |
164 assert($text eq $expected, '$ctl->Render(): Bad output', "Got: $text", "Expected: $expected"); | |
165 | |
166 | |
167 my $doc2 = $loader->document('simple'); | |
168 | |
169 assert( $doc2->documentContext->stash->get( ['require',['My/Org/Panel'] ] ) ); | |
170 print Dumper($doc2->context->stash); | |
171 assert( $doc2->context->stash->get( ['require',['My/Org/Panel'] ] ) ); | |
172 | |
173 | 116 |
174 }; | 117 }; |
175 | 118 |
176 test TestDocumentLayout => sub { | 119 test TestDocumentLayout => sub { |
177 my ($this) = @_; | 120 my ($this) = @_; |
206 my $doc = $loader->document('simple'); | 149 my $doc = $loader->document('simple'); |
207 | 150 |
208 assert(ref $loader->context->stash->get([ 'dojo', 0, 'require', 0]) eq 'ARRAY'); | 151 assert(ref $loader->context->stash->get([ 'dojo', 0, 'require', 0]) eq 'ARRAY'); |
209 assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]); | 152 assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]); |
210 assert($loader->context->stash != $doc->context->stash); | 153 assert($loader->context->stash != $doc->context->stash); |
211 assert($loader->context->stash != $doc->documentContext->stash); | |
212 assert($doc->context->stash != $doc->documentContext->stash); | |
213 | 154 |
214 assert(defined $doc); | 155 assert(defined $doc); |
215 | 156 |
216 # only root stash variables can be localized, to avoid modifying dojo we | 157 # only root stash variables can be localized, to avoid modifying dojo we |
217 # need to replace it completely | 158 # need to replace it completely |
249 my $loader = $this->CreateLoader(); | 190 my $loader = $this->CreateLoader(); |
250 $loader->document('simple'); # force loader initialization | 191 $loader->document('simple'); # force loader initialization |
251 | 192 |
252 AssertMemoryLeak(sub { | 193 AssertMemoryLeak(sub { |
253 my $doc = $loader->document('simple'); | 194 my $doc = $loader->document('simple'); |
254 }); | 195 },'dump'); |
255 | 196 |
256 AssertMemoryLeak(sub { | 197 AssertMemoryLeak(sub { |
257 my $doc = $loader->document('simple'); | 198 my $doc = $loader->document('simple'); |
258 $doc->Render( { self => $doc } ); | 199 $doc->Render( { self => $doc } ); |
259 }); | 200 },'dump'); |
260 | 201 |
261 $loader->template('Layout/default'); | 202 $loader->template('Layout/default'); |
262 $loader->template('My/Org/Panel'); | 203 $loader->template('My/Org/Panel'); |
263 $loader->template('My/Org/TextPreview'); | 204 $loader->template('My/Org/TextPreview'); |
264 AssertMemoryLeak(sub { | |
265 my $doc = $loader->document('simple'); | |
266 my $factory = $doc->RequireControl('My/Org/Panel'); | |
267 my $ctl = $doc->childNodes($factory->new('information', { visualClass => 'complex' }) ); | |
268 },'dump'); | |
269 | 205 |
270 $loader->template('complex'); | 206 $loader->template('complex'); |
271 AssertMemoryLeak(sub { | 207 AssertMemoryLeak(sub { |
272 my $doc = $loader->document('complex'); | 208 my $doc = $loader->document('complex'); |
273 $doc->Render(); | 209 $doc->Render(); |