MustachePragmaImplicitIteratorTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. require_once '../Mustache.php';
  3. require_once 'PHPUnit/Framework.php';
  4. class MustachePragmaImplicitIteratorTest extends PHPUnit_Framework_TestCase {
  5. public function testEnablePragma() {
  6. $m = $this->getMock('Mustache', array('_renderPragma'), array('{{%IMPLICIT-ITERATOR}}'));
  7. $m->expects($this->exactly(1))
  8. ->method('_renderPragma')
  9. ->with(array('{{%IMPLICIT-ITERATOR}}', 'IMPLICIT-ITERATOR', null));
  10. $m->render();
  11. }
  12. public function testImplicitIterator() {
  13. $m1 = new Mustache('{{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}', array('items' => array('a', 'b', 'c')));
  14. $this->assertEquals('abc', $m1->render());
  15. $m2 = new Mustache('{{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}', array('items' => array(1, 2, 3)));
  16. $this->assertEquals('123', $m2->render());
  17. }
  18. public function testDotNotationCollision() {
  19. $m = new Mustache(null, array('items' => array('foo', 'bar', 'baz')));
  20. $this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR}}{{%DOT-NOTATION}}{{#items}}{{.}}{{/items}}'));
  21. $this->assertEquals('foobarbaz', $m->render('{{%DOT-NOTATION}}{{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}'));
  22. }
  23. public function testCustomIterator() {
  24. $m = new Mustache(null, array('items' => array('foo', 'bar', 'baz')));
  25. $this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR}}{{#items}}{{.}}{{/items}}'));
  26. $this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR iterator=i}}{{#items}}{{i}}{{/items}}'));
  27. $this->assertEquals('foobarbaz', $m->render('{{%IMPLICIT-ITERATOR iterator=items}}{{#items}}{{items}}{{/items}}'));
  28. }
  29. }