Changeset 1000

Show
Ignore:
Timestamp:
06/21/08 17:55:53 (2 months ago)
Author:
laurentj
Message:

added some tests for jTplCompiler and added an alias for 'assign' : eval

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/tpl/jTplCompiler.class.php

    r998 r1000  
    346346 
    347347            case 'assign': 
     348            case 'eval': 
    348349                $res = $this->_parseFinal($args,$this->_allowedAssign).';'; 
    349350                break; 
  • trunk/testapp/modules/jelix_tests/tests/jtpl.expressions_parsing.html_cli.php

    r998 r1000  
    1111 
    1212require_once(JELIX_LIB_PATH.'tpl/jTplCompiler.class.php'); 
     13define('TEST_JTPL_COMPILER_ASSIGN',1); 
    1314 
    1415class testJtplCompiler extends jTplCompiler { 
     
    109110 
    110111 
    111  
    112  
    113112    function testVarExprTrustedMode() { 
    114113        $compil = new testJtplCompiler(); 
     
    289288    } 
    290289 
     290 
     291    protected $varAssign = array( 
     292        '$aa=$bb'=>'$t->_vars[\'aa\']=$t->_vars[\'bb\']', 
     293        '$aa+=$bb'=>'$t->_vars[\'aa\']+=$t->_vars[\'bb\']', 
     294        '$aa-=$bb'=>'$t->_vars[\'aa\']-=$t->_vars[\'bb\']', 
     295        '$aa/=$bb'=>'$t->_vars[\'aa\']/=$t->_vars[\'bb\']', 
     296        '$aa*=$bb'=>'$t->_vars[\'aa\']*=$t->_vars[\'bb\']', 
     297        'TEST_JTPL_COMPILER_ASSIGN'=>'TEST_JTPL_COMPILER_ASSIGN' 
     298    ); 
     299 
     300    protected $varAssignUnTrustedMode = array( 
     301        'TEST_JTPL_COMPILER_ASSIGN'=>array('jelix~errors.tpl.tag.constant.notallowed',array('','TEST_JTPL_COMPILER_ASSIGN','')), 
     302    ); 
     303 
     304 
     305    function testAssign() { 
     306        $compil = new testJtplCompiler(); 
     307        $compil->trusted = true; 
     308 
     309        foreach($this->varAssign as $k=>$t){ 
     310            try{ 
     311                $res = $compil->testParseAssignExpr($k); 
     312                $this->assertEqualOrDiff($t, $res); 
     313            }catch(jException $e){ 
     314                $this->fail("Test '$k', Unknown Jelix Exception : ".$e->getMessage().' ('.$e->getLocaleKey().')'); 
     315            }catch(Exception $e){ 
     316                $this->fail("Test '$k', Unknown Exception: ".$e->getMessage()); 
     317            } 
     318        } 
     319 
     320        $compil->trusted = false; 
     321 
     322        foreach($this->varAssignUnTrustedMode as $k=>$t){ 
     323            try{ 
     324                $res = $compil->testParseAssignExpr($k); 
     325                $this->fail("No Exception for this test '$k' "); 
     326            }catch(jException $e){ 
     327                $this->assertEqualOrDiff($t[0], $e->getLocaleKey()); 
     328                $this->assertEqual($t[1], $e->getLocaleParameters()); 
     329            }catch(Exception $e){ 
     330                $this->pass("Unknown Exception: ".$e->getMessage()); 
     331            } 
     332 
     333        } 
     334    } 
     335 
     336 
    291337} 
    292338 
Download in other formats: Unified Diff Zip Archive