| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- require_once '../Mustache.php';
- class MustacheExceptionTest extends PHPUnit_Framework_TestCase {
- const TEST_CLASS = 'Mustache';
- protected $pickyMustache;
- protected $slackerMustache;
-
- public function setUp() {
- $this->pickyMustache = new PickyMustache();
- $this->slackerMustache = new SlackerMustache();
- }
- /**
- * @group interpolation
- * @expectedException MustacheException
- */
- public function testThrowsUnknownVariableException() {
- $this->pickyMustache->render('{{not_a_variable}}');
- }
- /**
- * @group sections
- * @expectedException MustacheException
- */
- public function testThrowsUnclosedSectionException() {
- $this->pickyMustache->render('{{#unclosed}}');
- }
- /**
- * @group sections
- * @expectedException MustacheException
- */
- public function testThrowsUnclosedInvertedSectionException() {
- $this->pickyMustache->render('{{^unclosed}}');
- }
- /**
- * @group sections
- * @expectedException MustacheException
- */
- public function testThrowsUnexpectedCloseSectionException() {
- $this->pickyMustache->render('{{/unopened}}');
- }
- /**
- * @group partials
- * @expectedException MustacheException
- */
- public function testThrowsUnknownPartialException() {
- $this->pickyMustache->render('{{>impartial}}');
- }
- /**
- * @group pragmas
- * @expectedException MustacheException
- */
- public function testThrowsUnknownPragmaException() {
- $this->pickyMustache->render('{{%SWEET-MUSTACHE-BRO}}');
- }
- /**
- * @group sections
- */
- public function testDoesntThrowUnclosedSectionException() {
- $this->assertEquals('', $this->slackerMustache->render('{{#unclosed}}'));
- }
- /**
- * @group sections
- */
- public function testDoesntThrowUnexpectedCloseSectionException() {
- $this->assertEquals('', $this->slackerMustache->render('{{/unopened}}'));
- }
- /**
- * @group partials
- */
- public function testDoesntThrowUnknownPartialException() {
- $this->assertEquals('', $this->slackerMustache->render('{{>impartial}}'));
- }
- /**
- * @group pragmas
- * @expectedException MustacheException
- */
- public function testGetPragmaOptionsThrowsExceptionsIfItThinksYouHaveAPragmaButItTurnsOutYouDont() {
- $mustache = new TestableMustache();
- $mustache->testableGetPragmaOptions('PRAGMATIC');
- }
- }
- class PickyMustache extends Mustache {
- protected $_throwsExceptions = array(
- MustacheException::UNKNOWN_VARIABLE => true,
- MustacheException::UNCLOSED_SECTION => true,
- MustacheException::UNEXPECTED_CLOSE_SECTION => true,
- MustacheException::UNKNOWN_PARTIAL => true,
- MustacheException::UNKNOWN_PRAGMA => true,
- );
- }
- class SlackerMustache extends Mustache {
- protected $_throwsExceptions = array(
- MustacheException::UNKNOWN_VARIABLE => false,
- MustacheException::UNCLOSED_SECTION => false,
- MustacheException::UNEXPECTED_CLOSE_SECTION => false,
- MustacheException::UNKNOWN_PARTIAL => false,
- MustacheException::UNKNOWN_PRAGMA => false,
- );
- }
- class TestableMustache extends Mustache {
- public function testableGetPragmaOptions($pragma_name) {
- return $this->_getPragmaOptions($pragma_name);
- }
- }
|