Clean up pragma exception fix, add test coverage.
This commit is contained in:
+5
-5
@@ -403,10 +403,11 @@ class Mustache {
|
|||||||
$options_string = $matches['options_string'];
|
$options_string = $matches['options_string'];
|
||||||
|
|
||||||
if (!in_array($pragma_name, $this->_pragmasImplemented)) {
|
if (!in_array($pragma_name, $this->_pragmasImplemented)) {
|
||||||
if($this->_throwsException(MustacheException::UNKNOWN_PRAGMA))
|
if ($this->_throwsException(MustacheException::UNKNOWN_PRAGMA)) {
|
||||||
throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA);
|
throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA);
|
||||||
else
|
} else {
|
||||||
return '';
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array();
|
$options = array();
|
||||||
@@ -451,10 +452,9 @@ class Mustache {
|
|||||||
*/
|
*/
|
||||||
protected function _getPragmaOptions($pragma_name) {
|
protected function _getPragmaOptions($pragma_name) {
|
||||||
if (!$this->_hasPragma($pragma_name)) {
|
if (!$this->_hasPragma($pragma_name)) {
|
||||||
if($this->_throwsException(MustacheException::UNKNOWN_PRAGMA))
|
if ($this->_throwsException(MustacheException::UNKNOWN_PRAGMA)) {
|
||||||
throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA);
|
throw new MustacheException('Unknown pragma: ' . $pragma_name, MustacheException::UNKNOWN_PRAGMA);
|
||||||
else
|
}
|
||||||
return array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (is_array($this->_localPragmas[$pragma_name])) ? $this->_localPragmas[$pragma_name] : array();
|
return (is_array($this->_localPragmas[$pragma_name])) ? $this->_localPragmas[$pragma_name] : array();
|
||||||
|
|||||||
@@ -20,6 +20,20 @@ class MustachePragmaTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->fail('Mustache should have thrown an unknown pragma exception');
|
$this->fail('Mustache should have thrown an unknown pragma exception');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSuppressUnknownPragmaException() {
|
||||||
|
$m = new LessWhinyMustache();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->assertEquals('', $m->render('{{%I-HAVE-THE-GREATEST-MUSTACHE}}'));
|
||||||
|
} catch (MustacheException $e) {
|
||||||
|
if ($e->getCode() == MustacheException::UNKNOWN_PRAGMA) {
|
||||||
|
$this->fail('Mustache should have thrown an unknown pragma exception');
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testPragmaReplace() {
|
public function testPragmaReplace() {
|
||||||
$m = new Mustache();
|
$m = new Mustache();
|
||||||
$this->assertEquals('', $m->render('{{%UNESCAPED}}'), 'Pragma tag not removed');
|
$this->assertEquals('', $m->render('{{%UNESCAPED}}'), 'Pragma tag not removed');
|
||||||
@@ -47,4 +61,14 @@ class MustachePragmaTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals('>>>', $m->render('{{%UNESCAPED}}{{symbol}}'));
|
$this->assertEquals('>>>', $m->render('{{%UNESCAPED}}{{symbol}}'));
|
||||||
$this->assertEquals('>>>', $m->render('{{{symbol}}}'));
|
$this->assertEquals('>>>', $m->render('{{{symbol}}}'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LessWhinyMustache extends Mustache {
|
||||||
|
protected $_throwsExceptions = array(
|
||||||
|
MustacheException::UNKNOWN_VARIABLE => false,
|
||||||
|
MustacheException::UNCLOSED_SECTION => true,
|
||||||
|
MustacheException::UNEXPECTED_CLOSE_SECTION => true,
|
||||||
|
MustacheException::UNKNOWN_PARTIAL => false,
|
||||||
|
MustacheException::UNKNOWN_PRAGMA => false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user