diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php index 2b9c553366..524b86bc62 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php @@ -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( diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php index be8ac5cfaa..1c75d8bb85 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php @@ -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); diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php index a11681c249..86f9579cf6 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php @@ -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);