瀏覽代碼

[Form] Removed TemplateContext::create()

Bernhard Schussek 14 年之前
父節點
當前提交
ca6ae09779

+ 2 - 6
src/Symfony/Bridge/Twig/Extension/FormExtension.php

@@ -100,8 +100,6 @@ class FormExtension extends \Twig_Extension
      */
     public function renderRow(TemplateContext $context, array $variables = array())
     {
-        $context->setRendered();
-
         return $this->render($context, 'row', $variables);
     }
 
@@ -132,8 +130,6 @@ class FormExtension extends \Twig_Extension
      */
     public function renderWidget(TemplateContext $context, array $variables = array(), $resources = null)
     {
-        $context->setRendered();
-
         if (null !== $resources && !is_array($resources)) {
             $resources = array($resources);
         }
@@ -180,8 +176,8 @@ class FormExtension extends \Twig_Extension
             $block = $block.'__'.$section;
 
             if (isset($templates[$block])) {
-                if ('widget' === $section) {
-                    $context->setVar('is_rendered', true);
+                if ('widget' === $section || 'row' === $section) {
+                    $context->setRendered(true);
                 }
 
                 return $templates[$block]->renderBlock($block, array_merge($context->getVars(), $variables));

+ 13 - 13
src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperTest.php

@@ -18,7 +18,7 @@ use Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper;
 use Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper;
 use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTemplateNameParser;
 use Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator;
-use Symfony\Component\Form\FormInterface;
+use Symfony\Component\Form\TemplateContext;
 use Symfony\Component\Templating\PhpEngine;
 use Symfony\Component\Templating\TemplateNameParser;
 use Symfony\Component\Templating\Loader\FilesystemLoader;
@@ -45,34 +45,34 @@ class FormHelperTest extends AbstractDivLayoutTest
         ));
     }
 
-    protected function renderEnctype(FormInterface $form)
+    protected function renderEnctype(TemplateContext $context)
     {
-        return (string)$this->helper->enctype($form->getContext());
+        return (string)$this->helper->enctype($context);
     }
 
-    protected function renderLabel(FormInterface $form, $label = null)
+    protected function renderLabel(TemplateContext $context, $label = null)
     {
-        return (string)$this->helper->label($form->getContext(), $label);
+        return (string)$this->helper->label($context, $label);
     }
 
-    protected function renderErrors(FormInterface $form)
+    protected function renderErrors(TemplateContext $context)
     {
-        return (string)$this->helper->errors($form->getContext());
+        return (string)$this->helper->errors($context);
     }
 
-    protected function renderWidget(FormInterface $form, array $vars = array())
+    protected function renderWidget(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->helper->widget($form->getContext(), $vars);
+        return (string)$this->helper->widget($context, $vars);
     }
 
-    protected function renderRow(FormInterface $form, array $vars = array())
+    protected function renderRow(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->helper->row($form->getContext(), $vars);
+        return (string)$this->helper->row($context, $vars);
     }
 
-    protected function renderRest(FormInterface $form, array $vars = array())
+    protected function renderRest(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->helper->rest($form->getContext(), $vars);
+        return (string)$this->helper->rest($context, $vars);
     }
 
 }

+ 1 - 1
src/Symfony/Component/Form/Form.php

@@ -834,7 +834,7 @@ class Form implements \IteratorAggregate, FormInterface
 
     public function getContext()
     {
-        return TemplateContext::create($this);
+        return new TemplateContext($this);
     }
 
     /**

+ 2 - 37
src/Symfony/Component/Form/TemplateContext.php

@@ -16,12 +16,8 @@ use Symfony\Component\Form\Util\ChoiceUtil;
 
 class TemplateContext implements \ArrayAccess, \IteratorAggregate
 {
-    static $cache;
-
     private $vars = array(
         'value' => null,
-        'choices' => array(),
-        'preferred_choices' => array(),
         'attr' => array(),
     );
 
@@ -40,28 +36,7 @@ class TemplateContext implements \ArrayAccess, \IteratorAggregate
      */
     private $rendered = false;
 
-    static public function create(FormInterface $form)
-    {
-        if (null === self::$cache) {
-            self::$cache = new \SplObjectStorage();
-        }
-
-        if (isset(self::$cache[$form])) {
-            return self::$cache[$form];
-        }
-
-        // populate the cache for the root form
-        $root = $form;
-        while ($root->getParent()) {
-            $root = $root->getParent();
-        }
-
-        self::$cache[$root] = new self($root);
-
-        return self::$cache[$form];
-    }
-
-    private function __construct(FormInterface $form, self $parent = null)
+    public function __construct(FormInterface $form, self $parent = null)
     {
         $this->parent = $parent;
 
@@ -75,7 +50,7 @@ class TemplateContext implements \ArrayAccess, \IteratorAggregate
         }
 
         foreach ($form as $key => $child) {
-            $children[$key] = self::$cache[$child] = new self($child, $this);
+            $children[$key] = new self($child, $this);
         }
 
         $this->setChildren($children);
@@ -185,16 +160,6 @@ class TemplateContext implements \ArrayAccess, \IteratorAggregate
         return new \ArrayIterator(array());
     }
 
-    public function getChoiceLabel($choice)
-    {
-        return isset($this->vars['choices'][$choice])
-            ? $this->vars['choices'][$choice]
-            : (isset($this->vars['preferred_choices'][$choice])
-                ? $this->vars['preferred_choices'][$choice]
-                : null
-            );
-    }
-
     public function isChoiceGroup($choice)
     {
         return is_array($choice) || $choice instanceof \Traversable;

+ 13 - 13
tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionDivLayoutTest.php

@@ -14,7 +14,7 @@ namespace Symfony\Tests\Bridge\Twig\Extension;
 require_once __DIR__.'/Fixtures/StubTranslator.php';
 require_once __DIR__.'/Fixtures/StubFilesystemLoader.php';
 
-use Symfony\Component\Form\FormInterface;
+use Symfony\Component\Form\TemplateContext;
 use Symfony\Bridge\Twig\Extension\FormExtension;
 use Symfony\Bridge\Twig\Extension\TranslationExtension;
 use Symfony\Tests\Component\Form\AbstractDivLayoutTest;
@@ -40,33 +40,33 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
         $this->extension->initRuntime($environment);
     }
 
-    protected function renderEnctype(FormInterface $form)
+    protected function renderEnctype(TemplateContext $context)
     {
-        return (string)$this->extension->renderEnctype($form->getContext());
+        return (string)$this->extension->renderEnctype($context);
     }
 
-    protected function renderLabel(FormInterface $form, $label = null)
+    protected function renderLabel(TemplateContext $context, $label = null)
     {
-        return (string)$this->extension->renderLabel($form->getContext(), $label);
+        return (string)$this->extension->renderLabel($context, $label);
     }
 
-    protected function renderErrors(FormInterface $form)
+    protected function renderErrors(TemplateContext $context)
     {
-        return (string)$this->extension->renderErrors($form->getContext());
+        return (string)$this->extension->renderErrors($context);
     }
 
-    protected function renderWidget(FormInterface $form, array $vars = array())
+    protected function renderWidget(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->extension->renderWidget($form->getContext(), $vars);
+        return (string)$this->extension->renderWidget($context, $vars);
     }
 
-    protected function renderRow(FormInterface $form, array $vars = array())
+    protected function renderRow(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->extension->renderRow($form->getContext(), $vars);
+        return (string)$this->extension->renderRow($context, $vars);
     }
 
-    protected function renderRest(FormInterface $form, array $vars = array())
+    protected function renderRest(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->extension->renderRest($form->getContext(), $vars);
+        return (string)$this->extension->renderRest($context, $vars);
     }
 }

+ 13 - 13
tests/Symfony/Tests/Bridge/Twig/Extension/FormExtensionTableLayoutTest.php

@@ -14,7 +14,7 @@ namespace Symfony\Tests\Bridge\Twig\Extension;
 require_once __DIR__.'/Fixtures/StubTranslator.php';
 require_once __DIR__.'/Fixtures/StubFilesystemLoader.php';
 
-use Symfony\Component\Form\FormInterface;
+use Symfony\Component\Form\TemplateContext;
 use Symfony\Bridge\Twig\Extension\FormExtension;
 use Symfony\Bridge\Twig\Extension\TranslationExtension;
 use Symfony\Tests\Component\Form\AbstractTableLayoutTest;
@@ -40,33 +40,33 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
         $this->extension->initRuntime($environment);
     }
 
-    protected function renderEnctype(FormInterface $form)
+    protected function renderEnctype(TemplateContext $context)
     {
-        return (string)$this->extension->renderEnctype($form->getContext());
+        return (string)$this->extension->renderEnctype($context);
     }
 
-    protected function renderLabel(FormInterface $form, $label = null)
+    protected function renderLabel(TemplateContext $context, $label = null)
     {
-        return (string)$this->extension->renderLabel($form->getContext(), $label);
+        return (string)$this->extension->renderLabel($context, $label);
     }
 
-    protected function renderErrors(FormInterface $form)
+    protected function renderErrors(TemplateContext $context)
     {
-        return (string)$this->extension->renderErrors($form->getContext());
+        return (string)$this->extension->renderErrors($context);
     }
 
-    protected function renderWidget(FormInterface $form, array $vars = array())
+    protected function renderWidget(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->extension->renderWidget($form->getContext(), $vars);
+        return (string)$this->extension->renderWidget($context, $vars);
     }
 
-    protected function renderRow(FormInterface $form, array $vars = array())
+    protected function renderRow(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->extension->renderRow($form->getContext(), $vars);
+        return (string)$this->extension->renderRow($context, $vars);
     }
 
-    protected function renderRest(FormInterface $form, array $vars = array())
+    protected function renderRest(TemplateContext $context, array $vars = array())
     {
-        return (string)$this->extension->renderRest($form->getContext(), $vars);
+        return (string)$this->extension->renderRest($context, $vars);
     }
 }

+ 13 - 10
tests/Symfony/Tests/Component/Form/AbstractDivLayoutTest.php

@@ -19,7 +19,8 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
     {
         $form = $this->factory->create('text', 'name');
         $form->addError(new FormError('Error!'));
-        $html = $this->renderRow($form);
+        $context = $form->getContext();
+        $html = $this->renderRow($context);
 
         $this->assertMatchesXpath($html,
 '/div
@@ -38,7 +39,8 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
     {
         $form = $this->factory->create('repeated', 'name');
         $form->addError(new FormError('Error!'));
-        $html = $this->renderRow($form);
+        $context = $form->getContext();
+        $html = $this->renderRow($context);
 
         $this->assertMatchesXpath($html,
 '/ul
@@ -60,22 +62,23 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
 
     public function testRest()
     {
-        $form = $this->factory->createBuilder('form', 'name')
+        $context = $this->factory->createBuilder('form', 'name')
             ->add('field1', 'text')
             ->add('field2', 'repeated')
             ->add('field3', 'text')
             ->add('field4', 'text')
-            ->getForm();
+            ->getForm()
+            ->getContext();
 
         // Render field2 row -> does not implicitely call renderWidget because
         // it is a repeated field!
-        $this->renderRow($form['field2']);
+        $this->renderRow($context['field2']);
 
         // Render field3 widget
-        $this->renderWidget($form['field3']);
+        $this->renderWidget($context['field3']);
 
         // Rest should only contain field1 and field4
-        $html = $this->renderRest($form);
+        $html = $this->renderRest($context);
 
         $this->assertMatchesXpath($html,
 '/input
@@ -105,7 +108,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
             'data' => array('a', 'b'),
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./div[./input[@type="text"][@value="a"]]
@@ -123,7 +126,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
             ->add('lastName', 'text')
             ->getForm();
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./input[@type="hidden"][@id="name__token"]
@@ -150,7 +153,7 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
             'data' => 'foobar',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./div

+ 51 - 51
tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

@@ -11,7 +11,6 @@
 
 namespace Symfony\Tests\Component\Form;
 
-use Symfony\Component\Form\FormInterface;
 use Symfony\Component\Form\FormError;
 use Symfony\Component\Form\TemplateContext;
 use Symfony\Component\Form\FormFactory;
@@ -74,9 +73,9 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         }
     }
 
-    protected function assertWidgetMatchesXpath(FormInterface $form, array $vars, $xpath)
+    protected function assertWidgetMatchesXpath(TemplateContext $context, array $vars, $xpath)
     {
-        $html = $this->renderWidget($form, array_merge(array(
+        $html = $this->renderWidget($context, array_merge(array(
             'id' => 'my_id',
             'attr' => array('class' => 'my_class'),
         ), $vars));
@@ -88,17 +87,17 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         $this->assertMatchesXpath($html, $xpath);
     }
 
-    abstract protected function renderEnctype(FormInterface $form);
+    abstract protected function renderEnctype(TemplateContext $context);
 
-    abstract protected function renderLabel(FormInterface $form, $label = null);
+    abstract protected function renderLabel(TemplateContext $context, $label = null);
 
-    abstract protected function renderErrors(FormInterface $form);
+    abstract protected function renderErrors(TemplateContext $context);
 
-    abstract protected function renderWidget(FormInterface $form, array $vars = array());
+    abstract protected function renderWidget(TemplateContext $context, array $vars = array());
 
-    abstract protected function renderRow(FormInterface $form, array $vars = array());
+    abstract protected function renderRow(TemplateContext $context, array $vars = array());
 
-    abstract protected function renderRest(FormInterface $form, array $vars = array());
+    abstract protected function renderRest(TemplateContext $context, array $vars = array());
 
     public function testEnctype()
     {
@@ -106,7 +105,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             ->add('file', 'file')
             ->getForm();
 
-        $this->assertEquals('enctype="multipart/form-data"', $this->renderEnctype($form));
+        $this->assertEquals('enctype="multipart/form-data"', $this->renderEnctype($form->getContext()));
     }
 
     public function testNoEnctype()
@@ -115,13 +114,13 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             ->add('text', 'text')
             ->getForm();
 
-        $this->assertEquals('', $this->renderEnctype($form));
+        $this->assertEquals('', $this->renderEnctype($form->getContext()));
     }
 
     public function testLabel()
     {
         $form = $this->factory->create('text', 'name');
-        $html = $this->renderLabel($form);
+        $html = $this->renderLabel($form->getContext());
 
         $this->assertMatchesXpath($html,
 '/label
@@ -134,7 +133,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
     public function testLabelWithCustomText()
     {
         $form = $this->factory->create('text', 'name');
-        $html = $this->renderLabel($form, 'Custom label');
+        $html = $this->renderLabel($form->getContext(), 'Custom label');
 
         $this->assertMatchesXpath($html,
 '/label
@@ -149,7 +148,8 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         $form = $this->factory->create('text', 'name');
         $form->addError(new FormError('Error 1'));
         $form->addError(new FormError('Error 2'));
-        $html = $this->renderErrors($form);
+        $context = $form->getContext();
+        $html = $this->renderErrors($context);
 
         $this->assertMatchesXpath($html,
 '/ul
@@ -168,7 +168,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => true,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="checkbox"]
     [@name="name"]
@@ -185,7 +185,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => true,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="checkbox"]
     [@name="name"]
@@ -201,7 +201,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="checkbox"]
     [@name="name"]
@@ -219,7 +219,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'expanded' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name"]
     [
@@ -241,7 +241,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'expanded' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array('separator' => '-- sep --'),
+        $this->assertWidgetMatchesXpath($form->getContext(), array('separator' => '-- sep --'),
 '/select
     [@name="name"]
     [
@@ -264,7 +264,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'expanded' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name"]
     [
@@ -289,7 +289,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'expanded' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name"]
     [./optgroup[@label="Group1"]
@@ -317,7 +317,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'expanded' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name[]"]
     [@multiple="multiple"]
@@ -340,7 +340,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'expanded' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name[]"]
     [@multiple="multiple"]
@@ -362,7 +362,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'expanded' => true,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./input[@type="radio"][@name="name"][@id="name_a"][@checked]
@@ -384,7 +384,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'expanded' => true,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./input[@type="checkbox"][@name="name[a]"][@id="name_a"][@checked]
@@ -405,7 +405,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'AT',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name"]
     [./option[@value="AT"][@selected="selected"][.="Austria"]]
@@ -418,7 +418,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
     {
         $form = $this->factory->create('csrf', 'name');
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="hidden"]
     [string-length(@value)>=40]
@@ -434,7 +434,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'with_seconds' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./div
@@ -474,7 +474,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'with_seconds' => true,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./div
@@ -517,7 +517,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'widget' => 'choice',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./select
@@ -543,7 +543,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'widget' => 'text',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="text"]
     [@name="name"]
@@ -556,7 +556,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
     {
         $form = $this->factory->create('file', 'name');
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./input[@type="file"][@id="name_file"]
@@ -574,7 +574,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'foobar',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="hidden"]
     [@name="name"]
@@ -589,7 +589,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => '123',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="number"]
     [@name="name"]
@@ -604,7 +604,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'de',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name"]
     [./option[@value="de"][@selected="selected"][.="German"]]
@@ -619,7 +619,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'de_AT',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name"]
     [./option[@value="de_AT"][@selected="selected"][.="German (Austria)"]]
@@ -635,7 +635,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'currency' => 'EUR',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="text"]
     [@name="name"]
@@ -651,7 +651,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 1234.56,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="text"]
     [@name="name"]
@@ -666,7 +666,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'Pa$sW0rD',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="password"]
     [@name="name"]
@@ -682,7 +682,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'max_length' => 123,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="password"]
     [@name="name"]
@@ -698,7 +698,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 0.1,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="text"]
     [@name="name"]
@@ -714,7 +714,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => true,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="radio"]
     [@name="name"]
@@ -731,7 +731,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'value' => 'foobar',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="radio"]
     [@name="name"]
@@ -747,7 +747,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="radio"]
     [@name="name"]
@@ -762,7 +762,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'foobar',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/textarea
     [@name="name"]
     [.="foobar"]
@@ -776,7 +776,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'foobar',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="text"]
     [@name="name"]
@@ -793,7 +793,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'max_length' => 123,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="text"]
     [@name="name"]
@@ -811,7 +811,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'with_seconds' => false,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./select
@@ -834,7 +834,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'with_seconds' => true,
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/div
     [
         ./select
@@ -858,7 +858,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'Europe/Vienna',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/select
     [@name="name"]
     [./optgroup
@@ -877,7 +877,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
             'data' => 'http://www.google.com',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/input
     [@type="url"]
     [@name="name"]

+ 17 - 13
tests/Symfony/Tests/Component/Form/AbstractTableLayoutTest.php

@@ -19,7 +19,8 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
     {
         $form = $this->factory->create('text', 'name');
         $form->addError(new FormError('Error!'));
-        $html = $this->renderRow($form);
+        $context = $form->getContext();
+        $html = $this->renderRow($context);
 
         $this->assertMatchesXpath($html,
 '/tr
@@ -41,7 +42,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
     public function testRepeatedRow()
     {
         $form = $this->factory->create('repeated', 'name');
-        $html = $this->renderRow($form);
+        $html = $this->renderRow($form->getContext());
 
         $this->assertMatchesXpath($html,
 '/tr
@@ -67,7 +68,8 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
     {
         $form = $this->factory->create('repeated', 'name');
         $form->addError(new FormError('Error!'));
-        $html = $this->renderRow($form);
+        $context = $form->getContext();
+        $html = $this->renderRow($context);
 
         $this->assertMatchesXpath($html,
 '/tr
@@ -95,22 +97,23 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
 
     public function testRest()
     {
-        $form = $this->factory->createBuilder('form', 'name')
+        $context = $this->factory->createBuilder('form', 'name')
             ->add('field1', 'text')
             ->add('field2', 'repeated')
             ->add('field3', 'text')
             ->add('field4', 'text')
-            ->getForm();
+            ->getForm()
+            ->getContext();
 
         // Render field2 row -> does not implicitely call renderWidget because
         // it is a repeated field!
-        $this->renderRow($form['field2']);
+        $this->renderRow($context['field2']);
 
         // Render field3 widget
-        $this->renderWidget($form['field3']);
+        $this->renderWidget($context['field3']);
 
         // Rest should only contain field1 and field4
-        $html = $this->renderRest($form);
+        $html = $this->renderRest($context);
 
         $this->assertMatchesXpath($html,
 '/tr[@style="display: none"]
@@ -146,7 +149,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
             'data' => array('a', 'b'),
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/table
     [
         ./tr[./td/input[@type="text"][@value="a"]]
@@ -159,12 +162,13 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
 
     public function testForm()
     {
-        $form = $this->factory->createBuilder('form', 'name')
+        $context = $this->factory->createBuilder('form', 'name')
             ->add('firstName', 'text')
             ->add('lastName', 'text')
-            ->getForm();
+            ->getForm()
+            ->getContext();
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($context, array(),
 '/table
     [
         ./tr[@style="display: none"]
@@ -199,7 +203,7 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest
             'data' => 'foobar',
         ));
 
-        $this->assertWidgetMatchesXpath($form, array(),
+        $this->assertWidgetMatchesXpath($form->getContext(), array(),
 '/table
     [
         ./tr