Author: Raymond Bosman
Date: 2007-03-05 14:48:48 +0100 (Mon, 05 Mar 2007)
New Revision: 4713

Log:
- Fixed some issues with the cache_blocks.

Added:
   trunk/Template/tests/templates/cache_block_with_local_keys.tpl
   trunk/Template/tests/templates/show_users_cache_block.ezt
Modified:
   
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
   trunk/Template/src/parsers/tst_to_tst/implementations/cache_preparation.php
   trunk/Template/tests/cache_manager_test.php
   trunk/Template/tests/cache_test.php
   trunk/Template/tests/suite.php
   trunk/Template/tests/templates/cache_block_in_cache_block.tpl
   trunk/Template/tests/templates/cache_block_in_cache_template.tpl

Modified: 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
===================================================================
--- 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
     2007-03-05 11:43:00 UTC (rev 4712)
+++ 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
     2007-03-05 13:48:48 UTC (rev 4713)
@@ -35,6 +35,7 @@
      * True when in {cache_template} or inside a {cache_block}.
      */
     private $isInCacheBlock = false;
+    private $cacheLevel = 0;
 
     private $cacheBaseName = null;
 
@@ -69,6 +70,11 @@
         }
     }
 
+    protected function getFp()
+    {
+        return $this->createVariableNode( "fp" . $this->cacheLevel );
+    }
+
     /**
      *  Returns the ast tree:  include( $_ezcTemplateCache ); 
      */
@@ -82,7 +88,7 @@
      */
     protected function _fopenCacheFileWriteMode()
     {
-        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateAssignmentOperatorAstNode( $this->createVariableNode( "fp" ), new 
ezcTemplateFunctionCallAstNode( "fopen", array( new ezcTemplateVariableAstNode( 
"_ezcTemplateCache" ), new ezcTemplateLiteralAstNode( "w")  )) ) );
+        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateAssignmentOperatorAstNode( $this->getFp(), new 
ezcTemplateFunctionCallAstNode( "fopen", array( new ezcTemplateVariableAstNode( 
"_ezcTemplateCache" ), new ezcTemplateLiteralAstNode( "w")  )) ) );
 
     }
 
@@ -91,7 +97,7 @@
      */
     protected function _fwritePhpOpen()
     {
-        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fwrite", array( $this->createVariableNode( 
"fp" ),  new ezcTemplateConcatOperatorAstNode( new 
ezcTemplateLiteralAstNode('<'), new ezcTemplateLiteralAstNode("?php\n" ) ) ) ) 
);
+        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fwrite", array( $this->getFp(),  new 
ezcTemplateConcatOperatorAstNode( new ezcTemplateLiteralAstNode('<'), new 
ezcTemplateLiteralAstNode("?php\n" ) ) ) ) );
     }
 
     /**
@@ -124,7 +130,7 @@
      */
     protected function _fwriteLiteral( $literalValue )
     {
-        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fwrite", array( $this->createVariableNode( 
"fp" ), new ezcTemplateLiteralAstNode( $literalValue ) ) ) );  
+        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fwrite", array( $this->getFp(), new 
ezcTemplateLiteralAstNode( $literalValue ) ) ) );  
 
     }
 
@@ -133,7 +139,7 @@
      */
     protected function _fwriteVariable( $variableName )
     {
-        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fwrite", array( $this->createVariableNode( 
"fp" ), $this->createVariableNode( $variableName ) ) ) );  
+        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fwrite", array( $this->getFp(), 
$this->createVariableNode( $variableName ) ) ) );  
     }
 
 
@@ -155,7 +161,7 @@
      */
     protected function _fwriteVarExportVariable( $variableName, $concat, 
$fwritePhpClose = false )
     {
-        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fwrite", 
array($this->createVariableNode("fp"),  new ezcTemplateConcatOperatorAstNode( 
new ezcTemplateLiteralAstNode("\$".$variableName." ". ($concat ? ".=" : "=") ." 
"), new ezcTemplateConcatOperatorAstNode( new ezcTemplateFunctionCallAstNode(  
"var_export", array( $this->createVariableNode("$variableName"), new 
ezcTemplateLiteralAstNode(true) ) ), new ezcTemplateLiteralAstNode(";\n" . 
($fwritePhpClose ? " ?>" : "" )) ) ) ) ) );
+        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fwrite", array($this->getFp(),  new 
ezcTemplateConcatOperatorAstNode( new 
ezcTemplateLiteralAstNode("\$".$variableName." ". ($concat ? ".=" : "=") ." "), 
new ezcTemplateConcatOperatorAstNode( new ezcTemplateFunctionCallAstNode(  
"var_export", array( $this->createVariableNode("$variableName"), new 
ezcTemplateLiteralAstNode(true) ) ), new ezcTemplateLiteralAstNode(";\n" . 
($fwritePhpClose ? " ?>" : "" )) ) ) ) ) );
     }
 
     /**
@@ -171,7 +177,7 @@
      */
     protected function _fclose()
     {
-        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fclose", array( $this->createVariableNode( 
"fp" ) ) ) ) ;
+        return new ezcTemplateGenericStatementAstNode( new 
ezcTemplateFunctionCallAstNode( "fclose", array( $this->getFp() ) ) ) ;
     }
 
     protected function getCacheBaseName()
@@ -246,7 +252,20 @@
         {
             // Translate the 'old' variableName to the new name.
             $k = $value->accept($this);
-            $cacheKeys[str_replace( "this->send->", "use:" , $k->name )] = 
$k->name;
+
+            $type = $this->parser->symbolTable->retrieve($k->name);
+            if( substr( $k->name, 0, 12) == "this->send->")
+            {
+                $cacheKeys[str_replace( "this->send->", "use:" , $k->name )] = 
$k->name;
+            }
+            elseif (substr( $k->name, 0, 2) == "t_" )
+            {
+                $cacheKeys[ "var:" . substr($k->name, 2)] = $k->name;
+            }
+            else
+            {
+                $cacheKeys[$k->name] = $k->name;
+            }
         }
 
         return $cacheKeys;
@@ -284,10 +303,8 @@
         $cb->appendStatement( $this->_fopenCacheFileWriteMode() ); // $fp = 
fopen( $this->cache, "w" ); 
 
         $cb->appendStatement( $this->_fwritePhpOpen() );                 // 
fwrite( $fp, "<" . "?php\n" );
-        $cb->appendStatement( $this->_assignEmptyString("total") );      // 
$total = ""
-        //$cb->appendStatement( $this->_fwriteLiteral( "\$" . 
self::INTERNAL_PREFIX . "output = '';\n") );
-        //$cb->appendStatement( $this->_assign( self::INTERNAL_PREFIX. 
"output") );      // $total = ""
-        $cb->appendStatement( $this->_assignEmptyString( 
self::INTERNAL_PREFIX. "output") );      // $total = ""
+        $cb->appendStatement( $this->_assignEmptyString("total" . 
$this->cacheLevel) );      // $total = ""
+        $cb->appendStatement( $this->_assignEmptyString( 
self::INTERNAL_PREFIX. "output") );
     }
 
     // TEST VERSION for cacheblock.
@@ -304,10 +321,8 @@
 
         $cb->appendStatement( $this->_fwritePhpOpen() );                 // 
fwrite( $fp, "<" . "?php\n" );
         //$cb->appendStatement( $this->_assignEmptyString("total") );      // 
$total = ""
-        $cb->appendStatement( $this->_assignVariable(self::INTERNAL_PREFIX . 
"output", "total") );      // $total = ""
-        //$cb->appendStatement( $this->_fwriteLiteral( "\$" . 
self::INTERNAL_PREFIX . "output = '';\n") );
-        //$cb->appendStatement( $this->_assign( self::INTERNAL_PREFIX. 
"output") );      // $total = ""
-        $cb->appendStatement( $this->_assignEmptyString( 
self::INTERNAL_PREFIX. "output") );      // $total = ""
+        $cb->appendStatement( $this->_assignVariable(self::INTERNAL_PREFIX . 
"output", "total".$this->cacheLevel) );
+        $cb->appendStatement( $this->_assignEmptyString( 
self::INTERNAL_PREFIX. "output") );
 
     }
 
@@ -336,13 +351,13 @@
         $cb->appendStatement( $this->_fwriteVarExportVariable( 
self::INTERNAL_PREFIX . "output", true, true) );
 
         // $total .= $_ezcTemplate_output;
-        $cb->appendStatement( $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total") );
+        $cb->appendStatement( $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total".$this->cacheLevel) );
             
         // fclose($fp);  
         $cb->appendStatement( $this->_fclose() );
 
         // $_ezcTemplate_output = $total;
-        $cb->appendStatement( $this->_assignVariable( "total", 
self::INTERNAL_PREFIX . "output" ) );
+        $cb->appendStatement( $this->_assignVariable( 
"total".$this->cacheLevel, self::INTERNAL_PREFIX . "output" ) );
         if ($addReturn)
         { 
             $cb->appendStatement( new ezcTemplateReturnAstNode( 
$this->outputVariable->getAst()) );
@@ -356,6 +371,7 @@
         foreach ( $this->preparedCache->useVariableTst as $useVariable)
         {
             $use = $useVariable->accept($this);
+
             if( is_array( $use ) )
             {
                 foreach ( $use as $u )
@@ -381,14 +397,14 @@
         }
 
         // Cache the whole template.
-        $this->isInCacheBlock = true;
+        $this->cacheLevel++;
 
 
         $this->prepareProgram(); // Program operations, nothing to do with 
caching.
 
+        $this->addUseVariables();
         $cacheKeys = $this->translateCacheKeys($this->cacheTemplate->keys);
 
-        $this->addUseVariables();
         $this->addCacheKeys( $this->programNode, $cacheKeys );
             
         $ttl = $this->translateTTL($this->cacheTemplate->ttl);
@@ -544,13 +560,13 @@
         $astNodes[] = $this->_fwriteVarExportVariable( self::INTERNAL_PREFIX . 
"output", true, true);
 
         // $total .= $_ezcTemplate_output;
-        $astNodes[] = $this->_concatAssignVariable( self::INTERNAL_PREFIX . 
"output", "total");
+        $astNodes[] = $this->_concatAssignVariable( self::INTERNAL_PREFIX . 
"output", "total".$this->cacheLevel);
             
         // fclose($fp);  
         $astNodes[] = $this->_fclose();
 
         // $_ezcTemplate_output = $total;
-        $astNodes[] = $this->_assignVariable( "total", self::INTERNAL_PREFIX . 
"output" );
+        $astNodes[] = $this->_assignVariable( "total".$this->cacheLevel, 
self::INTERNAL_PREFIX . "output" );
 
 
 
@@ -577,7 +593,7 @@
         $newStatement[] = $this->_comment(" ---> start {dynamic}");
         
         // $total .= $_ezcTemplate_output
-        $newStatement[] = $this->_concatAssignVariable( self::INTERNAL_PREFIX 
. "output", "total");
+        $newStatement[] = $this->_concatAssignVariable( self::INTERNAL_PREFIX 
. "output", "total".$this->cacheLevel);
 
         // fwrite( $fp, "\\\<variableName> .= " . var_export( <variableName>, 
true) . ";" ); 
         $newStatement[] = $this->_fwriteVarExportVariable( 
self::INTERNAL_PREFIX . "output", true, false);
@@ -586,7 +602,7 @@
         $newStatement[] = $this->_assignEmptyString( self::INTERNAL_PREFIX . 
"output" );
 
         // $output .= $_ezcTemplate_output;
-        $newStatement[] = $this->_concatAssignVariable( self::INTERNAL_PREFIX 
. "output", "total");
+        $newStatement[] = $this->_concatAssignVariable( self::INTERNAL_PREFIX 
. "output", "total".$this->cacheLevel);
 
         // Place everything in the code block.
         $newStatement[] = new ezcTemplatePhpCodeAstNode( "\$code = '" );
@@ -609,7 +625,7 @@
             new ezcTemplateFunctionCallAstNode( "eval", array( 
$this->createVariableNode( "code" ) ) ) );
 
         // $total .= _ezcTemplate_output
-        $newStatement[] = $this->_concatAssignVariable( self::INTERNAL_PREFIX 
. "output", "total" ); 
+        $newStatement[] = $this->_concatAssignVariable( self::INTERNAL_PREFIX 
. "output", "total".$this->cacheLevel ); 
 
         // $ezcTemplate_output = "";
         $newStatement[] = $this->_assignEmptyString( self::INTERNAL_PREFIX . 
"output" ); 
@@ -666,12 +682,7 @@
             throw new ezcTemplateParserException( $type->source, 
$type->endCursor, $type->endCursor, 
ezcTemplateSourceToTstErrorMessages::MSG_CACHE_BLOCK_IN_DYNAMIC_BLOCK );
         }
 
-        if( $this->isInCacheBlock )
-        {
-            throw new ezcTemplateParserException( $type->source, 
$type->endCursor, $type->endCursor, 
ezcTemplateSourceToTstErrorMessages::MSG_CACHE_BLOCK_IN_CACHE_BLOCK );
-        }
-
-        $this->isInCacheBlock = true;
+        $this->cacheLevel++;
  
         $statements = new ezcTemplateBodyAstNode();
 
@@ -723,136 +734,10 @@
         //$statements->appendStatement( new ezcTemplateReturnAstNode( 
$this->outputVariable->getAst()) );
 
 
-        $this->isInCacheBlock = false;
+        $this->cacheLevel--;
 
         return $statements->statements;
 
-
-
-
-
-
-
-
-
-
-        /*
-        $newStatement = array();
-        $newStatement[] = $this->_comment(" ---> start {cache_block}");
-
-
-
-
-        $ifCondition = $this->notFileExistsCache();
-
-        $if = new ezcTemplateIfAstNode();
-        $if->conditions[] = $cb = new ezcTemplateConditionBodyAstNode();
-
-        $cb->condition = $ifCondition;
-        $cb->body = new ezcTemplateBodyAstNode();
-
-        foreach ( $type->elements as $element )
-        {
-            $astNode = $element->accept( $this );
-            if ( is_array( $astNode ) )
-            {
-                foreach ( $astNode as $ast )
-                {
-                    $cb->body->statements[] = $ast;
-                }
-            }
-            else
-            {
-                $cb->body->statements[] = $astNode;
-            }
-        }
-        
-        // Create the 'else' part. The else should 'include' (and execute) the 
cached file. 
-        $if->conditions[] = $else = new ezcTemplateConditionBodyAstNode();
-        $else->body = new ezcTemplateBodyAstNode();
-
-        $else->body->statements = array();
-        $else->body->statements[] =  $this->_includeCache();
-
-            if ($this->template->configuration->cacheManager !== false )
-            {
-                $cb->body->appendStatement( new 
ezcTemplateGenericStatementAstNode( new ezcTemplateFunctionCallAstNode( 
"\$this->template->configuration->cacheManager->stopCaching", array() )));
-            }
- 
-        
-            $cb->body->appendStatement( $this->_fwriteVarExportVariable( 
self::INTERNAL_PREFIX . "output", true, true) );
-
-            // $total .= $_ezcTemplate_output;
-            $cb->body->appendStatement( $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total") );
-                
-            // fclose($fp);  
-            $cb->body->appendStatement( $this->_fclose() );
-
-            // $_ezcTemplate_output = $total;
-            $cb->body->appendStatement( $this->_assignVariable( "total", 
self::INTERNAL_PREFIX . "output" ) );
-
-
-            $cb->body->appendStatement( new ezcTemplateReturnAstNode( 
$this->outputVariable->getAst()) );
-
-
-// SKIP STUFF
-            $cacheKeys = array();
-            echo ("JAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
-            $this->addCacheKeys( $myNode, $cacheKeys );
-
-            var_dump($myNode);
-
-            $newStatement[] = $if;
-
-            return $newStatement;
-
-
-
-
-
-        
-//        // $total .= $_ezcTemplate_output
-//        $newStatement[] = $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total");
-//
-//        // fwrite( $fp, "\\\<variableName> .= " . var_export( 
<variableName>, true) . ";" ); 
-//        $newStatement[] = $this->_fwriteVarExportVariable( 
self::INTERNAL_PREFIX . "output", true, false);
-//
-//        // $_ezcTemplate_output = "";
-//        $newStatement[] = $this->_assignEmptyString( self::INTERNAL_PREFIX . 
"output" );
-//
-//        // $output .= $_ezcTemplate_output;
-//        $newStatement[] = $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total");
-//
-//        // Place everything in the code block.
-//        $newStatement[] = new ezcTemplatePhpCodeAstNode( "\$code = '" );
-//
-//       
-//        $this->isInDynamicBlock = true;
-//        $tmp = new ezcTemplateDynamicBlockAstNode( $this->createBody( 
$node->elements ) );
-//        $tmp->escapeSingleQuote = true;
-//        $newStatement[] = $tmp;
-//        $this->isInDynamicBlock = false;
-//
-//        // $newStatement = array();
-//        $newStatement[] = new ezcTemplatePhpCodeAstNode( "';\n" );
-//
-//        // fwrite( $fp, $code );
-//        $newStatement[] = $this->_fwriteVariable( "code" ); 
-//
-//        // eval( $code );
-//        $newStatement[] = new ezcTemplateGenericStatementAstNode( 
-//            new ezcTemplateFunctionCallAstNode( "eval", array( 
$this->createVariableNode( "code" ) ) ) );
-//
-//        // $total .= _ezcTemplate_output
-//        $newStatement[] = $this->_concatAssignVariable( 
self::INTERNAL_PREFIX . "output", "total" ); 
-//
-//        // $ezcTemplate_output = "";
-//        $newStatement[] = $this->_assignEmptyString( self::INTERNAL_PREFIX . 
"output" ); 
-
-        $newStatement[] = $this->_comment(" <--- stop {/cache_block}");
-
-        return $newStatement;
-         */
     }
 
 }

Modified: 
trunk/Template/src/parsers/tst_to_tst/implementations/cache_preparation.php
===================================================================
--- trunk/Template/src/parsers/tst_to_tst/implementations/cache_preparation.php 
2007-03-05 11:43:00 UTC (rev 4712)
+++ trunk/Template/src/parsers/tst_to_tst/implementations/cache_preparation.php 
2007-03-05 13:48:48 UTC (rev 4713)
@@ -9,7 +9,6 @@
  * @access private
  */
 /**
- * The entire TST tree, doing nothing.
  * 
  * @package Template
  * @version //autogen//
@@ -32,10 +31,9 @@
 
         if ( $symbolTable->retrieve( $node->variable->name ) == 
ezcTemplateSymbolTable::IMPORT )
         {
-            // Move the {use} nodes.
-            $this->useVariableTst[] = $this->nodePath[0]->elements[0];
-            array_splice( $this->nodePath[0]->elements, 0, 1 ); 
-
+            $this->useVariableTst[] = 
$this->nodePath[0]->elements[$this->statements[0] + $this->offset[0]];   
//$this->nodePath[0]->elements[0];
+            array_splice( $this->nodePath[0]->elements, $this->statements[0] + 
$this->offset[0], 1 ); 
+            $this->offset[0] -= 1;
         }
 
         $this->acceptAndUpdate( $node->variable );
@@ -45,7 +43,6 @@
             $this->acceptAndUpdate( $node->expression );
         }
     }
-
 }
 
 ?>

Modified: trunk/Template/tests/cache_manager_test.php
===================================================================
--- trunk/Template/tests/cache_manager_test.php 2007-03-05 11:43:00 UTC (rev 
4712)
+++ trunk/Template/tests/cache_manager_test.php 2007-03-05 13:48:48 UTC (rev 
4713)
@@ -184,8 +184,29 @@
         $this->assertEquals( "\nCached:\n\n\n\n\n1 Raymond sunRay\n\n2 Derick 
Tiger\n\n3 Jan Amos\n", $r );
     }
  
+    public function testCacheBlock()
+    {
+        $t = new ezcTemplate();
+        $t->configuration->addExtension("Fetch");
 
+        $r = $t->process("show_users_cache_block.ezt");
+        $this->assertEquals( "\n\n\n\n1 Raymond sunRay\n\n2 Derick Tiger\n\n3 
Jan Amos\n", $r );
 
+        // Update a single user. 
+        $db = ezcDbInstance::get(); 
+        $db->exec( 'UPDATE user SET nickname="bla" WHERE id=1' );
+
+        // Still cached.
+        $r =  $t->process("show_users_cache_block.ezt");
+        $this->assertEquals( "\n\n\n\n1 Raymond sunRay\n\n2 Derick Tiger\n\n3 
Jan Amos\n", $r );
+
+        // Send a update signal to the configuration manager.
+        ezcTemplateConfiguration::getInstance()->cacheManager->update("user", 
1 );
+
+        $r = $t->process("show_users_cache_block.ezt");
+        $this->assertEquals( "\n\n\n\n1 Raymond bla\n\n2 Derick Tiger\n\n3 Jan 
Amos\n", $r );
+    }
+
     public function testCacheKeys()
     {
         $t = new ezcTemplate();
@@ -196,9 +217,6 @@
         $r = $t->process("cache_manager_with_keys.tpl");
 
 
-
-
-
 /*
         $this->assertEquals( "\n\n\n\n1 Raymond sunRay\n\n2 Derick Tiger\n\n3 
Jan Amos\n", $r );
 
@@ -216,11 +234,12 @@
         $r = $t->process("show_users.ezt");
         $this->assertEquals( "\n\n\n\n1 Raymond bla\n\n2 Derick Tiger\n\n3 Jan 
Amos\n", $r );
  */
-
     }
 
 
 
+
+
 }
 
 ?>

Modified: trunk/Template/tests/cache_test.php
===================================================================
--- trunk/Template/tests/cache_test.php 2007-03-05 11:43:00 UTC (rev 4712)
+++ trunk/Template/tests/cache_test.php 2007-03-05 13:48:48 UTC (rev 4713)
@@ -57,28 +57,11 @@
             $this->fail( "Expected the directory to exists: " . $cacheDir );
         }
     }
-  
+    
     // 
/////////////////////////////////////////////////////////////////////////////////////////
-    // Cache block is not implemented, and should give an exception.
-
+    // Cache blocks
     
     
-//    public function testCacheBlock()
-//    {
-//        $t = new ezcTemplate( );
-//        $t->send->user = new TestUser( "Bernard", "Black" );
-//
-//        try
-//        {
-//            $out = $t->process( "cache_block.tpl");
-//            $this->fail( "{cache_block} should throw an exception");
-//        }
-//        catch ( ezcTemplateParserException $e )
-//        {
-//        }
-//    }
-     
-    
     public function testCacheBlock()
     {
         $t = new ezcTemplate();
@@ -193,35 +176,142 @@
 
         $t->send->user = new TestUser( "Bart", "Simpson" , 2); // New ID, 
cache key no longer valid.
         $out = $t->process( "cache_block_with_keys.tpl");
+
         $this->assertEquals( "\n[Bart Simpson]\n", $out);
     }
 
+    public function testCacheBlockWithLocalKeys()
+    {
+        $t = new ezcTemplate();
+        $t->send->user = new TestUser( "Homer", "Simpson" );
+
+        $out = $t->process( "cache_block_with_local_keys.tpl");
+        $this->assertEquals( "\n\n[Homer Simpson]\n", $out);
+
+        $t->send->user = new TestUser( "Bart", "Simpson" );
+        $out = $t->process( "cache_block_with_local_keys.tpl");
+        $this->assertEquals( "\n\n[Bart Simpson]\n", $out);  // No Id given.
+    }
+
+
     public function testCacheBlockInCacheBlock()
     {
         $t = new ezcTemplate();
         $t->send->user = new TestUser( "Homer", "Simpson" );
+        $out = $t->process( "cache_block_in_cache_block.tpl");
+        $this->assertEquals( <<<EOM
 
-        try
-        {
-            $out = $t->process( "cache_block_in_cache_block.tpl");
-            $this->fail("Expected an exception");
-        }
-        catch( ezcTemplateParserException $e )
-        {
-        }
+Outside: Homer Simpson
 
-        try
-        {
-            $out = $t->process( "cache_block_in_cache_template.tpl");
-            $this->fail("Expected an exception");
-        }
-        catch( ezcTemplateParserException $e )
-        {
-        }
+Outer: Homer Simpson
+Inner: Homer Simpson
+
+EOM
+, $out);
+
+        $this->isInCacheBlock = false;
+        
+        $t->send->user = new TestUser( "Bart", "Simpson", 2 );
+        $out = $t->process( "cache_block_in_cache_block.tpl");
+        $this->assertEquals( <<<EOM
+
+Outside: Bart Simpson
+
+Outer: Bart Simpson
+Inner: Homer Simpson
+
+EOM
+, $out);
+
+    
+        $t->send->user = new TestUser( "Lisa", "Simpson", 2); // It has the 
same key as the "Bart Simpson".
+        $t->send->flushInner = true;
+        $out = $t->process( "cache_block_in_cache_block.tpl");
+        $this->assertEquals( <<<EOM
+
+Outside: Lisa Simpson
+
+Outer: Bart Simpson
+Inner: Homer Simpson
+
+EOM
+, $out);
+
+        $t->send->user = new TestUser( "Lisa", "Simpson", 3); // New key
+        $t->send->flushInner = true;
+        $out = $t->process( "cache_block_in_cache_block.tpl");
+        $this->assertEquals( <<<EOM
+
+Outside: Lisa Simpson
+
+Outer: Lisa Simpson
+Inner: Lisa Simpson
+
+EOM
+, $out);
+
     }
 
+    public function testCacheBlockInCacheTemplate()
+    {
+        $t = new ezcTemplate();
+        $t->send->user = new TestUser( "Homer", "Simpson" );
+        $out = $t->process( "cache_block_in_cache_template.tpl");
+        $this->assertEquals( <<<EOM
 
+TC: Homer Simpson
 
+CB1: Homer Simpson
+CB2: Homer Simpson
+
+EOM
+, $out);
+
+        $t->send->user = new TestUser( "Bart", "Simpson", 2 );
+        $out = $t->process( "cache_block_in_cache_template.tpl");
+
+        $this->assertEquals( <<<EOM
+
+TC: Bart Simpson
+
+CB1: Homer Simpson
+CB2: Homer Simpson
+
+EOM
+, $out);
+
+        $t->send->user = new TestUser( "Lisa", "Simpson", 3 );
+        $t->send->flushCB1 = true;
+        $out = $t->process( "cache_block_in_cache_template.tpl");
+
+        $this->assertEquals( <<<EOM
+
+TC: Lisa Simpson
+
+CB1: Lisa Simpson
+CB2: Homer Simpson
+
+EOM
+, $out);
+
+        $t->send->user = new TestUser( "Marge", "Simpson", 4 );
+        $t->send->flushCB1 = 4;  // True is taken.
+        $t->send->flushCB2 = 4;
+        $out = $t->process( "cache_block_in_cache_template.tpl");
+
+        $this->assertEquals( <<<EOM
+
+TC: Marge Simpson
+
+CB1: Marge Simpson
+CB2: Marge Simpson
+
+EOM
+, $out);
+
+    }
+
+
     public function testCacheBlockIndependently()
     {
         $t = new ezcTemplate();
@@ -309,6 +399,15 @@
 
 
 
+
+
+
+//        // FIX THE order of the {use} stuff.
+//        echo "\n" . $t->configuration->compilePath . "\n";
+//        exit();
+
+
+
     // 
/////////////////////////////////////////////////////////////////////////////////////////
     // Test the dynamic block.
     // Tested in the regression_test:
@@ -382,7 +481,7 @@
     // Declare a variable under the first dynamic block.
     public function testDynamicBlockImplicitVariableDeclaration()
     {
-        $t = new ezcTemplate( );
+        $t = new ezcTemplate();
         $t->send->number = 22; 
         $t->process( "cache_dynamic_implicit_declaration.tpl");
 

Modified: trunk/Template/tests/suite.php
===================================================================
--- trunk/Template/tests/suite.php      2007-03-05 11:43:00 UTC (rev 4712)
+++ trunk/Template/tests/suite.php      2007-03-05 13:48:48 UTC (rev 4713)
@@ -52,8 +52,6 @@
         $this->setName( "Template" );
         $this->addTest( ezcTemplateRegressionTest::suite() );
 
-        $this->addTest( ezcTemplateCacheTest::suite() );
-
         $this->addTest( ezcTemplateParserTest::suite() );
 
         $this->addTest( ezcTemplateFileExceptionTest::suite() );

Modified: trunk/Template/tests/templates/cache_block_in_cache_block.tpl
===================================================================
--- trunk/Template/tests/templates/cache_block_in_cache_block.tpl       
2007-03-05 11:43:00 UTC (rev 4712)
+++ trunk/Template/tests/templates/cache_block_in_cache_block.tpl       
2007-03-05 13:48:48 UTC (rev 4713)
@@ -1,8 +1,10 @@
-{use $user}
+{use $user, $flushInner = false}
 
-Hello
-{cache_block}
-       {cache_block}
-               {$user->name}
-       {/cache_block}
+Outside: {$user->name}
+
+{cache_block keys $user}
+    Outer: {$user->name}
+    {cache_block keys $flushInner}
+        Inner: {$user->name}
+    {/cache_block}
 {/cache_block}

Modified: trunk/Template/tests/templates/cache_block_in_cache_template.tpl
===================================================================
--- trunk/Template/tests/templates/cache_block_in_cache_template.tpl    
2007-03-05 11:43:00 UTC (rev 4712)
+++ trunk/Template/tests/templates/cache_block_in_cache_template.tpl    
2007-03-05 13:48:48 UTC (rev 4713)
@@ -1,7 +1,10 @@
-{use $user}
-{cache_template}
+{use $user, $flushCB1 = false, $flushCB2 = false}
+{cache_template keys $user}
+TC: {$user->name}
 
-Hello
-{cache_block}
-    {$user->name}
+{cache_block keys $flushCB1}
+    CB1: {$user->name}
+    {cache_block keys $flushCB2}
+        CB2: {$user->name}
+    {/cache_block}
 {/cache_block}

Added: trunk/Template/tests/templates/cache_block_with_local_keys.tpl
===================================================================
--- trunk/Template/tests/templates/cache_block_with_local_keys.tpl      
2007-03-05 11:43:00 UTC (rev 4712)
+++ trunk/Template/tests/templates/cache_block_with_local_keys.tpl      
2007-03-05 13:48:48 UTC (rev 4713)
@@ -0,0 +1,9 @@
+{use $user}
+
+{var $id = $user->name}
+{cycle $c = array(1,2)}
+
+{cache_block keys $id, $c}
+[{$user->name}]
+{/cache_block}
+


Property changes on: 
trunk/Template/tests/templates/cache_block_with_local_keys.tpl
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/Template/tests/templates/show_users_cache_block.ezt
===================================================================
--- trunk/Template/tests/templates/show_users_cache_block.ezt   2007-03-05 
11:43:00 UTC (rev 4712)
+++ trunk/Template/tests/templates/show_users_cache_block.ezt   2007-03-05 
13:48:48 UTC (rev 4713)
@@ -0,0 +1,11 @@
+{use $offset = 0, $limit = 4}
+
+{var $a}
+
+{cache_block keys $offset, $limit}
+{$a = fetch_user_list($offset, $limit)}
+
+{foreach $a as $b}
+       {include "user_info.ezt" send $b}
+{/foreach}
+{/cache_block}


Property changes on: trunk/Template/tests/templates/show_users_cache_block.ezt
___________________________________________________________________
Name: svn:eol-style
   + native

-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to