bug #10131 added lines to exceptions for the trans and transchoice tags (fabpot)
This PR was merged into the 2.3 branch.
Discussion
----------
added lines to exceptions for the trans and transchoice tags
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #10120
| License | MIT
| Doc PR | n/a
Commits
-------
ee0470d
added lines to exceptions for the trans and transchoice tags
This commit is contained in:
commit
eb74cb6604
@ -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(
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user