MustachePragmaDotNotationTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. require_once '../Mustache.php';
  3. require_once 'PHPUnit/Framework.php';
  4. class MustachePragmaDotNotationTest extends PHPUnit_Framework_TestCase {
  5. public function testDotTraversal() {
  6. $m = new Mustache('', array('foo' => array('bar' => 'this worked')));
  7. $this->assertEquals($m->render('{{foo.bar}}'), '',
  8. 'Dot notation not enabled, variable should have been replaced with nothing');
  9. $this->assertEquals($m->render('{{%DOT-NOTATION}}{{foo.bar}}'), 'this worked',
  10. 'Dot notation enabled, variable should have been replaced by "this worked"');
  11. }
  12. public function testDeepTraversal() {
  13. $data = array(
  14. 'foo' => array('bar' => array('baz' => array('qux' => array('quux' => 'WIN!')))),
  15. 'a' => array('b' => array('c' => array('d' => array('e' => 'abcs')))),
  16. 'one' => array(
  17. 'one' => 'one-one',
  18. 'two' => 'one-two',
  19. 'three' => 'one-three',
  20. ),
  21. );
  22. $m = new Mustache('', $data);
  23. $this->assertEquals($m->render('{{%DOT-NOTATION}}{{foo.bar.baz.qux.quux}}'), 'WIN!');
  24. $this->assertEquals($m->render('{{%DOT-NOTATION}}{{a.b.c.d.e}}'), 'abcs');
  25. $this->assertEquals($m->render('{{%DOT-NOTATION}}{{one.one}}|{{one.two}}|{{one.three}}'), 'one-one|one-two|one-three');
  26. }
  27. }