diff _test/Test/Web/View.pm @ 286:d357b5d85d25

*TTView refactoring
author sergey
date Mon, 18 Feb 2013 14:46:06 +0400
parents c6d0f889ef87
children 2d253e6e4a88
line wrap: on
line diff
--- a/_test/Test/Web/View.pm	Mon Feb 18 02:55:59 2013 +0400
+++ b/_test/Test/Web/View.pm	Mon Feb 18 14:46:06 2013 +0400
@@ -11,7 +11,7 @@
 use Scalar::Util qw(weaken);
 
 use IMPL::lang;
-use IMPL::Test qw(assert test GetCallerSourceLine);
+use IMPL::Test qw(assert assertarray test GetCallerSourceLine);
 use IMPL::Web::View::TTLoader();
 
 use constant {
@@ -186,6 +186,39 @@
     #assert($text eq $expected, '$doc->Render(): Bad output', "Got:      $text", "Expected: $expected"); 
 };
 
+test TestDocumentsIsolation => sub {
+	my $this = shift;
+	
+	my $loader = $this->CreateLoader();
+    
+    my $doc = $loader->document('simple');
+    
+    assert(ref $loader->context->stash->get([ 'dojo', 0, 'require', 0]) eq 'ARRAY');
+    assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]);
+    assert($loader->context->stash != $doc->stash);
+    
+    assert(defined $doc);
+    
+    # only root stash variables can be localized, to avoid modifying dojo we
+    # need to replace it completely 
+    $doc->context->process(\q{
+    	[% SET dojo = { require => [] } %]
+    	[% dojo.require.push('dijit/form/TextBox') %]
+    	[% SET user = 'dummy guy' %]
+    });
+    
+    assert($doc->context->stash->get('user') eq 'dummy guy');
+    assert($loader->context->stash->get('user') eq 'test_user');
+    assertarray($doc->context->stash->get([ 'dojo', 0, 'require', 0]),['dijit/form/TextBox']);
+    assertarray($loader->context->stash->get([ 'dojo', 0, 'require', 0]),[]);
+    
+    my $text = $doc->Render();
+    
+    my $doc2 = $loader->document('simple');
+    
+    assertarray($doc2->context->stash->get([ 'dojo', 0, 'require', 0]),[]);
+};
+
 test TestMemoryLeaks => sub {
     my ($this) = @_;