MustachePragmaTest.php 1.8 KB

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