From 5de845cb2e227810ab03f41a397c106d8c434960 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sun, 15 Aug 2010 06:32:36 -0400 Subject: [PATCH] Add test coverage for edge cases and exceptions. --- test/MustacheExceptionTest.php | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 test/MustacheExceptionTest.php diff --git a/test/MustacheExceptionTest.php b/test/MustacheExceptionTest.php new file mode 100644 index 0000000..39a0f5b --- /dev/null +++ b/test/MustacheExceptionTest.php @@ -0,0 +1,97 @@ +pickyMustache = new PickyMustache(); + $this->slackerMustache = new SlackerMustache(); + } + + /** + * @expectedException MustacheException + */ + public function testThrowsUnknownVariableException() { + $this->pickyMustache->render('{{not_a_variable}}'); + } + + /** + * @expectedException MustacheException + */ + public function testThrowsUnclosedSectionException() { + $this->pickyMustache->render('{{#unclosed}}'); + } + + /** + * @expectedException MustacheException + */ + public function testThrowsUnexpectedCloseSectionException() { + $this->pickyMustache->render('{{/unopened}}'); + } + + /** + * @expectedException MustacheException + */ + public function testThrowsUnknownPartialException() { + $this->pickyMustache->render('{{>impartial}}'); + } + + /** + * @expectedException MustacheException + */ + public function testThrowsUnknownPragmaException() { + $this->pickyMustache->render('{{%SWEET-MUSTACHE-BRO}}'); + } + + public function testDoesntThrowUnclosedSectionException() { + $this->assertEquals('', $this->slackerMustache->render('{{#unclosed}}')); + } + + public function testDoesntThrowUnexpectedCloseSectionException() { + $this->assertEquals('', $this->slackerMustache->render('{{/unopened}}')); + } + + public function testDoesntThrowUnknownPartialException() { + $this->assertEquals('', $this->slackerMustache->render('{{>impartial}}')); + } + + /** + * @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); + } +} \ No newline at end of file