comparison _test/Test/Web/View.pm @ 191:78a18a2b6266

IMPL::Web::View improvements (unstable)
author cin
date Thu, 05 Apr 2012 17:51:51 +0400
parents cd1ff7029a63
children 4d0e1962161c
comparison
equal deleted inserted replaced
190:cd1ff7029a63 191:78a18a2b6266
106 my ($this) = @_; 106 my ($this) = @_;
107 107
108 my $loader = $this->CreateLoader(); 108 my $loader = $this->CreateLoader();
109 109
110 my $doc = $loader->document('simple'); 110 my $doc = $loader->document('simple');
111 $doc->templateVars(data => ['one','two','hello world']);
112 111
113 assert(defined $doc); 112 assert(defined $doc);
114 113
115 my $factory = $doc->require('My/Org/Panel'); 114 my $factory = $doc->require('My/Org/Panel');
116 115
119 118
120 assert($factory->context->stash != $doc->context->stash); 119 assert($factory->context->stash != $doc->context->stash);
121 120
122 assert($factory == $doc->require('My/Org/Panel'), "Control should be loaded only once"); 121 assert($factory == $doc->require('My/Org/Panel'), "Control should be loaded only once");
123 122
124 my $ctl = $factory->new('information', { visualClass => 'simple' } ); 123 my $ctl = $factory->new('information', { visualClass => 'simple', data => ['one','two','hello world'] } );
125 124
126 assert(defined $ctl); 125 assert(defined $ctl);
127 126
128 assert($ctl->nodeName eq 'information', "Created control should have a name", "Got: ".$ctl->nodeName, "Expected: information"); 127 assert($ctl->nodeName eq 'information', "Created control should have a name", "Got: ".$ctl->nodeName, "Expected: information");
129 128
131 130
132 assert($factory->instances == 1); 131 assert($factory->instances == 1);
133 132
134 $doc->appendChild($ctl); 133 $doc->appendChild($ctl);
135 134
135 assert($doc->templateVars('dojo.require'));
136 assert(ref $doc->templateVars('dojo.require') eq 'ARRAY');
137 assert($doc->templateVars('dojo.require')->[0] eq 'dijit.form.Input' );
138
139 my $text = $ctl->Render();
140
141 my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'Panel.txt'), binmode => ':utf8');
142 assert($text eq $expected, '$ctl->Render(): Bad output', "Got: $text", "Expected: $expected");
136 143
137 144
138 my $text = $ctl->Render();
139 my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'Panel.txt'), binmode => ':utf8');
140 145
141 assert($text eq $expected, '$ctl->Render(): Bad output', "Got: $text", "Expected: $expected"); 146 };
147
148 test TestDocumentLayout => sub {
149 my ($this) = @_;
142 150
151 my $loader = $this->CreateLoader();
152
153 my $doc = $loader->document('complex');
154 assert($doc->layout eq 'Layout/default');
155
156 my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'complex.default.txt'), binmode => ':utf8' );
157
158 assert($doc->templateVars('dojo.require')->[0]);
159
160 my $text = $doc->Render({ data => [qw(one two three)] });
161
162 assert($text eq $expected, '$doc->Render(): Bad output', "Got: $text", "Expected: $expected");
143 }; 163 };
144 164
145 test TestMemoryLeaks => sub { 165 test TestMemoryLeaks => sub {
146 my ($this) = @_; 166 my ($this) = @_;
147 167
155 AssertMemoryLeak(sub { 175 AssertMemoryLeak(sub {
156 my $doc = $loader->document('simple'); 176 my $doc = $loader->document('simple');
157 $doc->Render( { self => $doc } ); 177 $doc->Render( { self => $doc } );
158 }); 178 });
159 179
180 $loader->template('Layout/default');
160 $loader->template('My/Org/Panel'); 181 $loader->template('My/Org/Panel');
161 $loader->template('My/Org/TextPreview'); 182 $loader->template('My/Org/TextPreview');
162 AssertMemoryLeak(sub { 183 AssertMemoryLeak(sub {
163 my $doc = $loader->document('simple'); 184 my $doc = $loader->document('simple');
164 my $factory = $doc->require('My/Org/Panel'); 185 my $factory = $doc->require('My/Org/Panel');