# HG changeset patch # User cin # Date 1333111234 -14400 # Node ID 6c0fee769b0cdd6061bd32b80915ed8f9cf8e22d # Parent ae8072f2f2a33f0c01a9d1ed77ca9b5fe8d9e352 IMPL::Web::View::TTControl tests, fixes diff -r ae8072f2f2a3 -r 6c0fee769b0c Lib/IMPL/Object/Factory.pm --- 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(@_)); } } diff -r ae8072f2f2a3 -r 6c0fee769b0c Lib/IMPL/Web/View/TTControl.pm --- 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); } diff -r ae8072f2f2a3 -r 6c0fee769b0c Lib/IMPL/Web/View/TTDocument.pm --- 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); } diff -r ae8072f2f2a3 -r 6c0fee769b0c Lib/IMPL/Web/View/TTFactory.pm --- 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); diff -r ae8072f2f2a3 -r 6c0fee769b0c _test/Resources/TTView.Output/Panel.txt --- /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 @@ +
diff -r ae8072f2f2a3 -r 6c0fee769b0c _test/Resources/TTView/My/Org/Panel.tt --- /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 %] +
$this.nodeValue
+[% END %] \ No newline at end of file diff -r ae8072f2f2a3 -r 6c0fee769b0c _test/Resources/TTView/global.tt --- 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 diff -r ae8072f2f2a3 -r 6c0fee769b0c _test/Test/Web/View.pm --- 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