Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Form] Fixed variable passing from outer to inner blocks of the same …
…FormView instance
- Loading branch information
Showing
10 changed files
with
299 additions
and
53 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
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
187 changes: 187 additions & 0 deletions
187
src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php
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,187 @@ | ||
<?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\Tests\TestCase; | ||
use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode; | ||
|
||
class SearchAndRenderBlockNodeTest extends TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
if (version_compare(\Twig_Environment::VERSION, '1.5.0', '<')) { | ||
$this->markTestSkipped('Requires Twig version to be at least 1.5.0.'); | ||
} | ||
} | ||
|
||
public function testCompileWidget() | ||
{ | ||
$arguments = new \Twig_Node(array( | ||
new \Twig_Node_Expression_Name('form', 0), | ||
)); | ||
|
||
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 0); | ||
|
||
$compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
|
||
$this->assertEquals( | ||
sprintf( | ||
'$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'widget\')', | ||
$this->getVariableGetter('form') | ||
), | ||
trim($compiler->compile($node)->getSource()) | ||
); | ||
} | ||
|
||
public function testCompileWidgetWithVariables() | ||
{ | ||
$arguments = new \Twig_Node(array( | ||
new \Twig_Node_Expression_Name('form', 0), | ||
new \Twig_Node_Expression_Array(array( | ||
new \Twig_Node_Expression_Constant('foo', 0), | ||
new \Twig_Node_Expression_Constant('bar', 0), | ||
), 0), | ||
)); | ||
|
||
$node = new SearchAndRenderBlockNode('form_widget', $arguments, 0); | ||
|
||
$compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
|
||
$this->assertEquals( | ||
sprintf( | ||
'$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'widget\', array("foo" => "bar"))', | ||
$this->getVariableGetter('form') | ||
), | ||
trim($compiler->compile($node)->getSource()) | ||
); | ||
} | ||
|
||
public function testCompileLabelWithLabel() | ||
{ | ||
$arguments = new \Twig_Node(array( | ||
new \Twig_Node_Expression_Name('form', 0), | ||
new \Twig_Node_Expression_Constant('my label', 0), | ||
)); | ||
|
||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
|
||
$compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
|
||
$this->assertEquals( | ||
sprintf( | ||
'$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("label" => "my label"))', | ||
$this->getVariableGetter('form') | ||
), | ||
trim($compiler->compile($node)->getSource()) | ||
); | ||
} | ||
|
||
public function testCompileLabelWithNullLabel() | ||
{ | ||
$arguments = new \Twig_Node(array( | ||
new \Twig_Node_Expression_Name('form', 0), | ||
new \Twig_Node_Expression_Constant(null, 0), | ||
)); | ||
|
||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
|
||
$compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
|
||
$this->assertEquals( | ||
sprintf( | ||
'$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("label" => null))', | ||
$this->getVariableGetter('form') | ||
), | ||
trim($compiler->compile($node)->getSource()) | ||
); | ||
} | ||
|
||
public function testCompileLabelWithDefaultLabel() | ||
{ | ||
$arguments = new \Twig_Node(array( | ||
new \Twig_Node_Expression_Name('form', 0), | ||
)); | ||
|
||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
|
||
$compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
|
||
$this->assertEquals( | ||
sprintf( | ||
'$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')', | ||
$this->getVariableGetter('form') | ||
), | ||
trim($compiler->compile($node)->getSource()) | ||
); | ||
} | ||
|
||
public function testCompileLabelWithAttributes() | ||
{ | ||
$arguments = new \Twig_Node(array( | ||
new \Twig_Node_Expression_Name('form', 0), | ||
new \Twig_Node_Expression_Constant(null, 0), | ||
new \Twig_Node_Expression_Array(array( | ||
new \Twig_Node_Expression_Constant('foo', 0), | ||
new \Twig_Node_Expression_Constant('bar', 0), | ||
), 0), | ||
)); | ||
|
||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
|
||
$compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
|
||
$this->assertEquals( | ||
sprintf( | ||
'$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => null))', | ||
$this->getVariableGetter('form') | ||
), | ||
trim($compiler->compile($node)->getSource()) | ||
); | ||
} | ||
|
||
public function testCompileLabelWithLabelAndAttributes() | ||
{ | ||
$arguments = new \Twig_Node(array( | ||
new \Twig_Node_Expression_Name('form', 0), | ||
new \Twig_Node_Expression_Constant('value in argument', 0), | ||
new \Twig_Node_Expression_Array(array( | ||
new \Twig_Node_Expression_Constant('foo', 0), | ||
new \Twig_Node_Expression_Constant('bar', 0), | ||
new \Twig_Node_Expression_Constant('label', 0), | ||
new \Twig_Node_Expression_Constant('value in attributes', 0), | ||
), 0), | ||
)); | ||
|
||
$node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
|
||
$compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
|
||
$this->assertEquals( | ||
sprintf( | ||
'$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => _twig_default_filter("value in argument", "value in attributes")))', | ||
$this->getVariableGetter('form') | ||
), | ||
trim($compiler->compile($node)->getSource()) | ||
); | ||
} | ||
|
||
protected function getVariableGetter($name) | ||
{ | ||
if (version_compare(phpversion(), '5.4.0RC1', '>=')) { | ||
return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name); | ||
} | ||
|
||
return sprintf('$this->getContext($context, "%s")', $name); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_row.html.php
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<div> | ||
<?php echo $view['form']->label($form, isset($label) ? $label : null) ?> | ||
<?php echo $view['form']->label($form) ?> | ||
<?php echo $view['form']->errors($form) ?> | ||
<?php echo $view['form']->widget($form) ?> | ||
</div> |
2 changes: 1 addition & 1 deletion
2
src/Symfony/Bundle/FrameworkBundle/Resources/views/FormTable/form_row.html.php
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
Oops, something went wrong.