MustachePragmaTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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("\n", $m->render("\n{{%DOT-NOTATION}}\n"), 'Too many newlines removed with pragma tag');
  30. $this->assertEquals("1\n23", $m->render("1\n2{{%DOT-NOTATION}}\n3"), 'Wrong newline removed with pragma tag');
  31. }
  32. public function testPragmaReset() {
  33. $m = new Mustache('', array('symbol' => '>>>'));
  34. $this->assertEquals('>>>', $m->render('{{{symbol}}}'));
  35. $this->assertEquals('>>>', $m->render('{{%UNESCAPED}}{{symbol}}'));
  36. $this->assertEquals('>>>', $m->render('{{{symbol}}}'));
  37. }
  38. }