Made dot-notation pragma toggleable, added test cases.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
require_once '../Mustache.php';
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
|
||||
class MustachePragmaDotNotationTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testDotTraversal() {
|
||||
$m = new Mustache('', array('foo' => array('bar' => 'this worked')));
|
||||
|
||||
$this->assertEquals($m->render('{{foo.bar}}'), '',
|
||||
'Dot notation not enabled, variable should have been replaced with nothing');
|
||||
$this->assertEquals($m->render('{{%DOT-NOTATION}}{{foo.bar}}'), 'this worked',
|
||||
'Dot notation enabled, variable should have been replaced by "this worked"');
|
||||
}
|
||||
|
||||
public function testDeepTraversal() {
|
||||
$data = array(
|
||||
'foo' => array('bar' => array('baz' => array('qux' => array('quux' => 'WIN!')))),
|
||||
'a' => array('b' => array('c' => array('d' => array('e' => 'abcs')))),
|
||||
'one' => array(
|
||||
'one' => 'one-one',
|
||||
'two' => 'one-two',
|
||||
'three' => 'one-three',
|
||||
),
|
||||
);
|
||||
|
||||
$m = new Mustache('', $data);
|
||||
$this->assertEquals($m->render('{{%DOT-NOTATION}}{{foo.bar.baz.qux.quux}}'), 'WIN!');
|
||||
$this->assertEquals($m->render('{{%DOT-NOTATION}}{{a.b.c.d.e}}'), 'abcs');
|
||||
$this->assertEquals($m->render('{{%DOT-NOTATION}}{{one.one}}|{{one.two}}|{{one.three}}'), 'one-one|one-two|one-three');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user