MustachePragmaTest.php 1.8 KB

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