Author: Raymond Bosman Date: 2007-02-16 14:39:09 +0100 (Fri, 16 Feb 2007) New Revision: 4660
Log: - Fixed a problem that some {use} variables were not moved to the top of the template when cache is enabled. 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/src/template.php trunk/Template/tests/cache_manager_test.php trunk/Template/tests/cache_test.php trunk/Template/tests/configuration_test.php trunk/Template/tests/suite.php 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-02-15 15:07:32 UTC (rev 4659) +++ trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php 2007-02-16 13:39:09 UTC (rev 4660) @@ -248,12 +248,9 @@ { // Translate the 'old' variableName to the new name. $k = $value->accept($this); - $cacheKeys[str_replace( "this->send->", "use:" , $k->name )] = $k->name; } - //$this->cacheSystem->setCacheKeys( $cacheKeys ); - $ttl = null; if ( $this->cacheInfo->ttl !== null ) { @@ -261,10 +258,6 @@ //$this->cacheSystem->setTTL( $ttl ); } - //$this->cacheSystem->setStream( $this->parser->template->stream ); - //$this->cacheSystem->initializeCache(); - - $dir = $this->template->configuration->compilePath . DIRECTORY_SEPARATOR . $this->template->configuration->cachedTemplatesPath; if ( !file_exists( $dir ) ) @@ -275,14 +268,6 @@ $this->deleteOldCache(); - - - // $cacheFileName = "/tmp/cache/" . str_replace( '/', "-", $this->template->stream ); - - // Get the code for the: 'cache exists'. Determining whether the cache data is available. - //$cacheExists = $this->cacheSystem->getCacheExists(); - //$ifCondition = array_pop( $cacheExists ); - // $ifCondition = $this->notFileExistsCache(); @@ -298,7 +283,6 @@ // Inside. - /// startCaching(); $cplen = strlen( $this->parser->template->configuration->compilePath ); if ($this->template->configuration->cacheManager !== false ) @@ -438,9 +422,6 @@ { $programNode->appendStatement(new ezcTemplatePhpCodeAstNode( '$_ezcTemplateCache = \'' . $this->getCacheBaseName() . "';\n" ) ); } - - //$code = '$_ezcTemplateCache = \'' . $this->getCacheBaseName() . '-\' '. ( $hasCacheKey ? ' . implode("-", array_map("md5", array_map("var_export",$_ezcCacheKeys), array_fill(0, sizeof($_ezcCacheKeys), true ) ) )' : '' ) . ";\n"; - //$programNode->appendStatement(new ezcTemplatePhpCodeAstNode( $code ) ); } protected function checkTTL( $ttl, $cacheKeys ) @@ -631,7 +612,6 @@ } else { - var_dump ($type ); $cb = new ezcTemplateCacheBlockAstNode( $type->elements->accept($this) ); return $cb; Modified: trunk/Template/src/parsers/tst_to_tst/implementations/cache_preparation.php =================================================================== --- trunk/Template/src/parsers/tst_to_tst/implementations/cache_preparation.php 2007-02-15 15:07:32 UTC (rev 4659) +++ trunk/Template/src/parsers/tst_to_tst/implementations/cache_preparation.php 2007-02-16 13:39:09 UTC (rev 4660) @@ -28,38 +28,14 @@ public function visitDeclarationTstNode( ezcTemplateDeclarationTstNode $node ) { $symbolTable = ezcTemplateSymbolTable::getInstance(); + + if ( $symbolTable->retrieve( $node->variable->name ) == ezcTemplateSymbolTable::IMPORT ) { - // Move to the top of the program. - - // var_dump ($this->statements ); - // var_dump ($this->nodePath[0] ); + // Move the {use} nodes. + $this->useVariableTst[] = $this->nodePath[0]->elements[0]; + array_splice( $this->nodePath[0]->elements, 0, 1 ); - - // Remove the "USE". - // XXX Fix offset, fix test. (multiple use deletion) - - $tmp = $this->nodePath[0]->elements[ $this->statements[0] ]; - array_splice( $this->nodePath[0]->elements, $this->statements[0], 1); - - // Insert the "USE". - // array_splice( $this->nodePath[0]->elements, 0, 0, array($tmp)); - // - - $this->useVariableTst[] = $tmp; - - - /* - $offset = $this->statements[0] + $this->offset[0]; - - // Remove the declaration of the USE variables. - array_splice( $this->nodePath[0]->statements, $offset, 1 ); - $this->offset[0] -= 1; - - // XXX: 2nd, because the 'if' produces also a nodePath. - array_unshift( $this->nodePath[2]->statements, $node ); - // $this->offset[2] += 1; - */ } $this->acceptAndUpdate( $node->variable ); Modified: trunk/Template/src/template.php =================================================================== --- trunk/Template/src/template.php 2007-02-15 15:07:32 UTC (rev 4659) +++ trunk/Template/src/template.php 2007-02-16 13:39:09 UTC (rev 4660) @@ -306,6 +306,7 @@ // Check if caching is needed. if ( $fetchCacheInfo->cacheTst !== null ) { + //XXX No cache prep. $cachePreparation = new ezcTemplateCachePreparation(); $this->properties["tstTree"]->accept( $cachePreparation ); Modified: trunk/Template/tests/cache_manager_test.php =================================================================== --- trunk/Template/tests/cache_manager_test.php 2007-02-15 15:07:32 UTC (rev 4659) +++ trunk/Template/tests/cache_manager_test.php 2007-02-16 13:39:09 UTC (rev 4660) @@ -16,7 +16,7 @@ * @package Template * @subpackage Tests */ -class ezcTemplateCacheTest extends ezcTestCase +class ezcTemplateCacheManagerTest extends ezcTestCase { private $tempDir; private $basePath; @@ -223,28 +223,4 @@ } - -class TestUser -{ - public $firstName; - public $lastName; - public $name; - public $id; - - public function cacheKey() - { - return $this->id; - } - - public function __construct($firstName, $lastName, $id = 1 ) - { - $this->firstName = $firstName; - $this->lastName = $lastName; - $this->name = $firstName . " " . $lastName; - $this->id = $id; - } -} - - - ?> Modified: trunk/Template/tests/cache_test.php =================================================================== --- trunk/Template/tests/cache_test.php 2007-02-15 15:07:32 UTC (rev 4659) +++ trunk/Template/tests/cache_test.php 2007-02-16 13:39:09 UTC (rev 4660) @@ -57,7 +57,7 @@ $this->fail( "Expected the directory to exists: " . $cacheDir ); } } - + // ///////////////////////////////////////////////////////////////////////////////////////// // Cache block is not implemented, and should give an exception. @@ -75,6 +75,13 @@ { } } + + public function testCacheBlockWithBeginText() + { + $t = new ezcTemplate( ); + $out = $t->process( "cache_block_with_begin_text.tpl"); + $this->assertEquals( "\nfoo <--> bar\n", $out); + } @@ -440,6 +447,7 @@ // $this->assertEquals( "I am rubber, you are glue.", $t->receive->quote); } + } class TestUser Modified: trunk/Template/tests/configuration_test.php =================================================================== --- trunk/Template/tests/configuration_test.php 2007-02-15 15:07:32 UTC (rev 4659) +++ trunk/Template/tests/configuration_test.php 2007-02-16 13:39:09 UTC (rev 4660) @@ -28,12 +28,13 @@ $this->templateStorePath = $this->basePath . 'stored_templates/'; } - public function testDelayedInit() - { - ezcBaseInit::setCallback( 'ezcInitTemplateConfiguration', 'testDelayedInitTemplateConfiguration' ); - $config = ezcTemplateConfiguration::getInstance(); - $this->assertEquals( new ezcTemplateNoContext, $config->context ); - } +// Doesn't work if other tests are run as well. +// public function testDelayedInit() +// { +// ezcBaseInit::setCallback( 'ezcInitTemplateConfiguration', 'testDelayedInitTemplateConfiguration' ); +// $config = ezcTemplateConfiguration::getInstance(); +// $this->assertEquals( new ezcTemplateNoContext, $config->context ); +// } public function testDefault() { Modified: trunk/Template/tests/suite.php =================================================================== --- trunk/Template/tests/suite.php 2007-02-15 15:07:32 UTC (rev 4659) +++ trunk/Template/tests/suite.php 2007-02-16 13:39:09 UTC (rev 4660) @@ -37,6 +37,8 @@ require_once 'cache_test.php'; require_once 'regression_test.php'; +require_once 'cache_test.php'; +require_once 'cache_manager_test.php'; /** * @package Template @@ -76,6 +78,8 @@ $this->addTest( ezcTemplateCompiledCodeTest::suite() ); $this->addTest( ezcTemplateConfigurationTest::suite() ); + $this->addTest( ezcTemplateCacheTest::suite() ); + $this->addTest( ezcTemplateCacheManagerTest::suite() ); $this->addTest( ezcTemplateTest::suite() ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components