Prechádzať zdrojové kódy

[Form] Added test for 'email' type and fixed a few bugs

Bernhard Schussek 14 rokov pred
rodič
commit
57722550de

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/email_widget.html.php

@@ -2,6 +2,7 @@
     <?php echo $view['form']->attributes() ?>
     name="<?php echo $view->escape($name) ?>"
     value="<?php echo $view->escape($value) ?>"
+    <?php if ($max_length): ?>maxlength="<?php echo $view->escape($max_length) ?>"<?php endif ?>
     <?php if ($read_only): ?>disabled="disabled"<?php endif ?>
     <?php if ($required): ?>required="required"<?php endif ?>
 />

+ 1 - 0
src/Symfony/Component/Form/Type/Loader/DefaultTypeLoader.php

@@ -32,6 +32,7 @@ class DefaultTypeLoader extends ArrayTypeLoader
             new Type\CountryType(),
             new Type\DateType(),
             new Type\DateTimeType(),
+            new Type\EmailType(),
             new Type\HiddenType(),
             new Type\IntegerType(),
             new Type\LanguageType(),

+ 35 - 0
tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

@@ -603,6 +603,41 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
         );
     }
 
+    public function testEmail()
+    {
+        $form = $this->factory->create('email', 'na&me', array(
+            'property_path' => 'name',
+            'data' => 'foo&bar',
+        ));
+
+        $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/input
+    [@type="email"]
+    [@name="na&me"]
+    [@value="foo&bar"]
+    [not(@maxlength)]
+'
+        );
+    }
+
+    public function testEmailWithMaxLength()
+    {
+        $form = $this->factory->create('email', 'na&me', array(
+            'property_path' => 'name',
+            'data' => 'foo&bar',
+            'max_length' => 123,
+        ));
+
+        $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/input
+    [@type="email"]
+    [@name="na&me"]
+    [@value="foo&bar"]
+    [@maxlength="123"]
+'
+        );
+    }
+
     public function testFile()
     {
         $form = $this->factory->create('file', 'na&me', array('property_path' => 'name'));