Browse Source

[Form] Added tests for previous commit

stloyd 14 years ago
parent
commit
7b6d921cde

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

@@ -51,9 +51,9 @@ class FormHelperTest extends AbstractDivLayoutTest
         return (string)$this->helper->enctype($view);
     }
 
-    protected function renderLabel(FormView $view, $label = null)
+    protected function renderLabel(FormView $view, $label = null, array $vars = array())
     {
-        return (string)$this->helper->label($view, $label);
+        return (string)$this->helper->label($view, $label, $vars);
     }
 
     protected function renderErrors(FormView $view)
@@ -75,5 +75,4 @@ class FormHelperTest extends AbstractDivLayoutTest
     {
         return (string)$this->helper->rest($view, $vars);
     }
-
-}
+}

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

@@ -53,9 +53,9 @@ class FormExtensionDivLayoutTest extends AbstractDivLayoutTest
         return (string)$this->extension->renderEnctype($view);
     }
 
-    protected function renderLabel(FormView $view, $label = null)
+    protected function renderLabel(FormView $view, $label = null, array $vars = array())
     {
-        return (string)$this->extension->renderLabel($view, $label);
+        return (string)$this->extension->renderLabel($view, $label, $vars);
     }
 
     protected function renderErrors(FormView $view)

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

@@ -53,9 +53,9 @@ class FormExtensionTableLayoutTest extends AbstractTableLayoutTest
         return (string)$this->extension->renderEnctype($view);
     }
 
-    protected function renderLabel(FormView $view, $label = null)
+    protected function renderLabel(FormView $view, $label = null, array $vars = array())
     {
-        return (string)$this->extension->renderLabel($view, $label);
+        return (string)$this->extension->renderLabel($view, $label, $vars);
     }
 
     protected function renderErrors(FormView $view)

+ 56 - 1
tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

@@ -93,7 +93,7 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
 
     abstract protected function renderEnctype(FormView $view);
 
-    abstract protected function renderLabel(FormView $view, $label = null);
+    abstract protected function renderLabel(FormView $view, $label = null, array $vars = array());
 
     abstract protected function renderErrors(FormView $view);
 
@@ -171,6 +171,61 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         );
     }
 
+    public function testLabelWithCustomTextPassedAsOptionAndDirectly()
+    {
+        $form = $this->factory->createNamed('text', 'na&me', null, array(
+            'property_path' => 'name',
+            'label' => 'Custom label',
+        ));
+        $html = $this->renderLabel($form->createView(), 'Overridden label');
+
+        $this->assertMatchesXpath($html,
+'/label
+    [@for="na&me"]
+    [.="[trans]Overridden label[/trans]"]
+'
+        );
+    }
+
+    public function testLabelWithCustomOptionsPassedDirectly()
+    {
+        $form = $this->factory->createNamed('text', 'na&me', null, array(
+            'property_path' => 'name',
+        ));
+        $html = $this->renderLabel($form->createView(), null, array(
+            'attr' => array(
+                'class' => 'my&class'
+            ),
+        ));
+
+        $this->assertMatchesXpath($html,
+'/label
+    [@for="na&me"]
+    [@class="my&class"]
+'
+        );
+    }
+
+    public function testLabelWithCustomTextAndCustomOptionsPassedDirectly()
+    {
+        $form = $this->factory->createNamed('text', 'na&me', null, array(
+            'property_path' => 'name',
+        ));
+        $html = $this->renderLabel($form->createView(), 'Custom label', array(
+            'attr' => array(
+                'class' => 'my&class'
+            ),
+        ));
+
+        $this->assertMatchesXpath($html,
+'/label
+    [@for="na&me"]
+    [@class="my&class"]
+    [.="[trans]Custom label[/trans]"]
+'
+        );
+    }
+
     public function testErrors()
     {
         $form = $this->factory->createNamed('text', 'na&me', null, array(