Mercurial > pub > Impl
changeset 186:6c0fee769b0c
IMPL::Web::View::TTControl tests, fixes
author | cin |
---|---|
date | Fri, 30 Mar 2012 16:40:34 +0400 |
parents | ae8072f2f2a3 |
children | 927653d01f4f |
files | Lib/IMPL/Object/Factory.pm Lib/IMPL/Web/View/TTControl.pm Lib/IMPL/Web/View/TTDocument.pm Lib/IMPL/Web/View/TTFactory.pm _test/Resources/TTView.Output/Panel.txt _test/Resources/TTView/My/Org/Panel.tt _test/Resources/TTView/global.tt _test/Test/Web/View.pm |
diffstat | 8 files changed, 79 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/IMPL/Object/Factory.pm Thu Mar 29 18:22:15 2012 +0400 +++ b/Lib/IMPL/Object/Factory.pm Fri Mar 30 16:40:34 2012 +0400 @@ -46,7 +46,7 @@ if (my $method = $this->method) { $this->factory->$method($this->MergeParameters(@_)); } else { - $this->factory->new($this->MergeParemeters(@_)); + $this->factory->new($this->MergeParameters(@_)); } }
--- a/Lib/IMPL/Web/View/TTControl.pm Thu Mar 29 18:22:15 2012 +0400 +++ b/Lib/IMPL/Web/View/TTControl.pm Fri Mar 30 16:40:34 2012 +0400 @@ -59,7 +59,7 @@ my $res = $_[0]->template->$method(); - return defined($res) ? $res : $_[0]->context->stash->get($method); + return defined($res) ? $res : $_[0]->context->stash->get($method); }
--- a/Lib/IMPL/Web/View/TTDocument.pm Thu Mar 29 18:22:15 2012 +0400 +++ b/Lib/IMPL/Web/View/TTDocument.pm Fri Mar 30 16:40:34 2012 +0400 @@ -44,26 +44,30 @@ sub require { my ($this, $control) = @_; - if (! $this->controls->{$control}) { + if (my $factory = $this->controls->{$control}) { + return $factory; + } else { - (my $path = $control) =~ tr/\./\//; + my $path = $control; if ( my $template = $this->loader->template($path) ) { - my $opts = ${$this->opts}; + my $opts = { %{$this->opts} }; $opts->{STASH} = $this->context->stash->clone(); my $ctx = new Template::Context($opts); - my $factory = new IMPL::Web::View::TTFactory( + $factory = new IMPL::Web::View::TTFactory( typeof IMPL::Web::View::TTControl, $template, $ctx, $opts ); - my @parts = split(/\.+/,$control); + my @parts = split(/\/+/,$control); + $this->controls->{$control} = $factory; $this->context->stash->set([map { $_, 0 } @parts], $factory); - + + return $factory; } else { die new IMPL::KeyNotFoundException($control); }
--- a/Lib/IMPL/Web/View/TTFactory.pm Thu Mar 29 18:22:15 2012 +0400 +++ b/Lib/IMPL/Web/View/TTFactory.pm Fri Mar 30 16:40:34 2012 +0400 @@ -28,7 +28,7 @@ $this->template($template); $this->context($context || new Template::Context($options)); - $this->opts($options); + $this->opts($options || {}); $this->nodeProperties($nodeProps || {}); $this->instances(0); @@ -45,7 +45,7 @@ sub MergeParameters { my ($this,$name,$refProps) = @_; - my $opts = { $this->opts }; + my $opts = { %{ $this->opts } }; $opts->{STASH} = $opts->{STASH}->clone() if $opts->{STASH}; my $ctx = new Template::Context($opts);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/_test/Resources/TTView.Output/Panel.txt Fri Mar 30 16:40:34 2012 +0400 @@ -0,0 +1,1 @@ +<div class="simple" data-dojo-type="dijit.form.Input"></div>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/_test/Resources/TTView/My/Org/Panel.tt Fri Mar 30 16:40:34 2012 +0400 @@ -0,0 +1,15 @@ +[% + META version = 1; + BLOCK INIT; + dojoDefaultClass = 'dijit.form.Input'; + dojo.require.push( dojoDefaultClass ); + END; + BLOCK CTOR; + controlObject = this; + dojoClass = dojoDefaultClass; + visualClass = this.nodeProperty('visualClass') || 'classic'; + END; +%] +[% BLOCK RENDER %] +<div class="$visualClass" data-dojo-type="$dojoClass">$this.nodeValue</div> +[% END %] \ No newline at end of file
--- a/_test/Resources/TTView/global.tt Thu Mar 29 18:22:15 2012 +0400 +++ b/_test/Resources/TTView/global.tt Fri Mar 30 16:40:34 2012 +0400 @@ -1,5 +1,6 @@ [% META version = 1; user = 'test_user'; + dojo.require = []; %] \ No newline at end of file
--- a/_test/Test/Web/View.pm Thu Mar 29 18:22:15 2012 +0400 +++ b/_test/Test/Web/View.pm Fri Mar 30 16:40:34 2012 +0400 @@ -82,4 +82,52 @@ }; +test TTControlTests => sub { + my ($this) = @_; + + my $loader = TTLoader->new( + { + INCLUDE_PATH => [ + $this->templatesDir + ], + INTERPOLATE => 1, + POST_CHOMP => 1, + ENCODING => 'utf8' + }, + ext => '.tt', + initializer => 'global.tt' + ); + + my $doc = $loader->document('simple'); + + assert(defined $doc); + + my $factory = $doc->require('My/Org/Panel'); + + assert(defined $factory); + + assert($factory == $doc->require('My/Org/Panel'), "Control should be loaded only once"); + + my $ctl = $factory->new('information', { visualClass => 'simple' } ); + + assert(defined $ctl); + + + assert($ctl->nodeName eq 'information', "Created control should have a name", "Got: ".$ctl->nodeName, "Expected: information"); + + assert($ctl->nodeProperty('visualClass') eq 'simple'); + + assert($ctl->controlObject == $ctl); + + assert($factory->instances == 1); + + assert($doc->context->stash->get('My.Org.Panel') == $factory); + + my $text = $ctl->Render(); + my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'Panel.txt'), binmode => ':utf8'); + + assert($text eq $expected, '$ctl->Render(): Bad output', "Got: $text", "Expected: $expected"); + +}; + 1; \ No newline at end of file