34 lines
1.2 KiB
PHP
34 lines
1.2 KiB
PHP
<?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');
|
|
}
|
|
|
|
} |