MustachePragmaTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require_once '../Mustache.php';
  3. require_once 'PHPUnit/Framework.php';
  4. class MustachePragmaTest extends PHPUnit_Framework_TestCase {
  5. public function testUnknownPragmaException() {
  6. $m = new Mustache();
  7. try {
  8. $m->render('{{%I-HAVE-THE-GREATEST-MUSTACHE}}');
  9. } catch (MustacheException $e) {
  10. $this->assertEquals(MustacheException::UNKNOWN_PRAGMA, $e->getCode(), 'Caught exception code was not MustacheException::UNKNOWN_PRAGMA');
  11. return;
  12. }
  13. $this->fail('Mustache should have thrown an unknown pragma exception');
  14. }
  15. public function testPragmaReplace() {
  16. $m = new Mustache();
  17. $this->assertEquals($m->render('{{%DOT-NOTATION}}'), '', 'Pragma tag not removed');
  18. }
  19. public function testPragmaReplaceMultiple() {
  20. $m = new Mustache();
  21. $this->assertEquals('', $m->render('{{% DOT-NOTATION }}'), 'Pragmas should allow whitespace');
  22. $this->assertEquals('', $m->render('{{% DOT-NOTATION foo=bar }}'), 'Pragmas should allow whitespace');
  23. $this->assertEquals($m->render("{{%DOT-NOTATION}}\n{{%DOT-NOTATION}}"), '', 'Multiple pragma tags not removed');
  24. $this->assertEquals($m->render('{{%DOT-NOTATION}} {{%DOT-NOTATION}}'), ' ', 'Multiple pragma tags not removed');
  25. }
  26. public function testPragmaReplaceNewline() {
  27. $m = new Mustache();
  28. $this->assertEquals($m->render("{{%DOT-NOTATION}}\n"), '', 'Trailing newline after pragma tag not removed');
  29. $this->assertEquals($m->render("\n{{%DOT-NOTATION}}\n"), "\n", 'Too many newlines removed with pragma tag');
  30. $this->assertEquals($m->render("1\n2{{%DOT-NOTATION}}\n3"), "1\n23", 'Wrong newline removed with pragma tag');
  31. }
  32. }