Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed strict check when found variables inside a translation
- Loading branch information
Showing
2 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Twig\Tests\Node; | ||
|
||
use Symfony\Bridge\Twig\Node\TransNode; | ||
|
||
/** | ||
* | ||
* @author Asmir Mustafic <goetas@gmail.com> | ||
* | ||
*/ | ||
class TransNodeTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public function testCompileStrict() | ||
{ | ||
$body = new \Twig_Node_Text('trans %var%', 0); | ||
$vars = new \Twig_Node_Expression_Name('foo', 0); | ||
$node = new TransNode($body, null, null, $vars); | ||
|
||
$env = new \Twig_Environment(null, array( | ||
'strict_variables' => true, | ||
)); | ||
$compiler = new \Twig_Compiler($env); | ||
|
||
$this->assertEquals( | ||
sprintf( | ||
'echo $this->env->getExtension(\'translator\')->getTranslator()->trans("trans %%var%%", array_merge(array("%%var%%" => %s), %s), "messages");', | ||
$this->getVariableGetterWithoutStrictCheck('var'), | ||
$this->getVariableGetterWithStrictCheck('foo') | ||
), | ||
trim($compiler->compile($node)->getSource()) | ||
); | ||
} | ||
protected function getVariableGetterWithoutStrictCheck($name) | ||
{ | ||
if (version_compare(phpversion(), '5.4.0RC1', '>=')) { | ||
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name); | ||
} | ||
|
||
return sprintf('$this->getContext($context, "%s", true)', $name); | ||
} | ||
protected function getVariableGetterWithStrictCheck($name) | ||
{ | ||
if (version_compare(phpversion(), '5.4.0RC1', '>=')) { | ||
return sprintf('(isset($context["%s"]) ? $context["%s"] : $this->getContext($context, "%s"))', $name, $name, $name); | ||
} | ||
|
||
return sprintf('$this->getContext($context, "%s")', $name); | ||
} | ||
} |