added lines to exceptions for the trans and transchoice tags

This commit is contained in:
Fabien Potencier 2014-01-25 10:45:58 +01:00
parent f71193c055
commit ee0470d110
3 changed files with 30 additions and 3 deletions

View File

@ -57,6 +57,33 @@ class TranslationExtensionTest extends TestCase
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
}
/**
* @expectedException \Twig_Error_Syntax
* @expectedExceptionMessage Unexpected token. Twig was looking for the "with", "from", or "into" keyword in "index" at line 3.
*/
public function testTransUnknownKeyword()
{
$output = $this->getTemplate("{% trans \n\nfoo %}{% endtrans %}")->render();
}
/**
* @expectedException \Twig_Error_Syntax
* @expectedExceptionMessage A message inside a trans tag must be a simple text in "index" at line 2.
*/
public function testTransComplexBody()
{
$output = $this->getTemplate("{% trans %}\n{{ 1 + 2 }}{% endtrans %}")->render();
}
/**
* @expectedException \Twig_Error_Syntax
* @expectedExceptionMessage A message inside a transchoice tag must be a simple text in "index" at line 2.
*/
public function testTransChoiceComplexBody()
{
$output = $this->getTemplate("{% transchoice count %}\n{{ 1 + 2 }}{% endtranschoice %}")->render();
}
public function getTransTests()
{
return array(

View File

@ -64,7 +64,7 @@ class TransChoiceTokenParser extends TransTokenParser
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
throw new \Twig_Error_Syntax('A message must be a simple text.');
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getFilename());
}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);

View File

@ -55,7 +55,7 @@ class TransTokenParser extends \Twig_TokenParser
$stream->next();
$locale = $this->parser->getExpressionParser()->parseExpression();
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with" or "from" keyword.');
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getFilename());
}
}
@ -64,7 +64,7 @@ class TransTokenParser extends \Twig_TokenParser
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text');
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getFilename());
}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);