Author: Raymond Bosman
Date: 2007-02-15 12:15:54 +0100 (Thu, 15 Feb 2007)
New Revision: 4655

Log:
- The cache key variables should be {use} variables. Added a test for this.

Modified:
   trunk/Template/src/error_messages.php
   trunk/Template/src/parsers/source_to_tst/implementations/cache.php
   
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
   trunk/Template/tests/cache_test.php

Modified: trunk/Template/src/error_messages.php
===================================================================
--- trunk/Template/src/error_messages.php       2007-02-15 10:19:58 UTC (rev 
4654)
+++ trunk/Template/src/error_messages.php       2007-02-15 11:15:54 UTC (rev 
4655)
@@ -28,6 +28,7 @@
     const MSG_EXPECT_MODULO                     = "Expecting a modulo";
     const MSG_EXPECT_NON_MODIFYING_OPERAND      = "Expecting an operand 
without a pre- or post operator.";
     const MSG_EXPECT_VARIABLE                   = "Expecting a variable";
+    const MSG_EXPECT_USE_VARIABLE               = "Expecting a variable that 
is defined with {use}";
 
     const MSG_EXPECT_VALUE                      = "Expected two operands that 
are not an array.";
 
@@ -113,6 +114,7 @@
 
 
 
+
     // Runtime errors
     const RT_IMPORT_VALUE_MISSING               = "The use variable '%s' is 
not set."; 
     

Modified: trunk/Template/src/parsers/source_to_tst/implementations/cache.php
===================================================================
--- trunk/Template/src/parsers/source_to_tst/implementations/cache.php  
2007-02-15 10:19:58 UTC (rev 4654)
+++ trunk/Template/src/parsers/source_to_tst/implementations/cache.php  
2007-02-15 11:15:54 UTC (rev 4655)
@@ -112,7 +112,6 @@
                     {
                         throw new ezcTemplateParserException( 
$this->parser->source, $this->startCursor, $this->currentCursor, 
ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_VARIABLE );
                     }
-
                     $cacheNode->keys[] = $this->lastParser->elements[0];
                     $this->findNextElement( $cursor );
                 } 

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 10:19:58 UTC (rev 4654)
+++ 
trunk/Template/src/parsers/tst_to_ast/implementations/tst_to_ast_cached_transformer.php
     2007-02-15 11:15:54 UTC (rev 4655)
@@ -597,8 +597,17 @@
 
             foreach ( $type->keys as $key )
             {
+                
                 // Translate the 'old' variableName to the new name.
                 $k = $key->accept($this);
+
+
+                if( $this->parser->symbolTable->retrieve($key->name) !== 
ezcTemplateSymbolTable::IMPORT)
+                {
+                    
+                    throw new ezcTemplateParserException( $type->source, 
$type->endCursor, $type->endCursor, 
ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_USE_VARIABLE );
+                }
+
                 $this->programNode->cacheKeys[] = $k->name;
             }
 

Modified: trunk/Template/tests/cache_test.php
===================================================================
--- trunk/Template/tests/cache_test.php 2007-02-15 10:19:58 UTC (rev 4654)
+++ trunk/Template/tests/cache_test.php 2007-02-15 11:15:54 UTC (rev 4655)
@@ -237,6 +237,26 @@
         $this->assertEquals( "\n[Guybrush Threepwood]\n", $out );
     }
 
+
+    public function testCacheKeyFromNonUse()
+    {
+        // Should call a function, if it's defined.
+        $t = new ezcTemplate();
+        try
+        {
+            $out = $t->process( "cache_wrong_key.tpl");
+            $this->fail("Expected an exception");
+        } 
+        catch( ezcTemplateParserException $e)
+        {
+            if( strpos($e->getMessage(), 
ezcTemplateSourceToTstErrorMessages::MSG_EXPECT_USE_VARIABLE) === false)
+            {
+                $this->fail("Expected an exception");
+            }
+
+        }
+    }
+
     // 
/////////////////////////////////////////////////////////////////////////////////////////////////
     // Test TTL
 

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

Reply via email to