added lines to exceptions for the trans and transchoice tags
This commit is contained in:
parent
f71193c055
commit
ee0470d110
@ -57,6 +57,33 @@ class TranslationExtensionTest extends TestCase
|
|||||||
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
|
$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()
|
public function getTransTests()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
@ -64,7 +64,7 @@ class TransChoiceTokenParser extends TransTokenParser
|
|||||||
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
|
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
|
||||||
|
|
||||||
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
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);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
@ -55,7 +55,7 @@ class TransTokenParser extends \Twig_TokenParser
|
|||||||
$stream->next();
|
$stream->next();
|
||||||
$locale = $this->parser->getExpressionParser()->parseExpression();
|
$locale = $this->parser->getExpressionParser()->parseExpression();
|
||||||
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
|
} 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);
|
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
|
||||||
|
|
||||||
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
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);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
Reference in New Issue
Block a user