Skip to content

Commit 5772255

Browse files
committed
[Form] Added test for 'email' type and fixed a few bugs
1 parent 23e9ad7 commit 5772255

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/email_widget.html.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<?php echo $view['form']->attributes() ?>
33
name="<?php echo $view->escape($name) ?>"
44
value="<?php echo $view->escape($value) ?>"
5+
<?php if ($max_length): ?>maxlength="<?php echo $view->escape($max_length) ?>"<?php endif ?>
56
<?php if ($read_only): ?>disabled="disabled"<?php endif ?>
67
<?php if ($required): ?>required="required"<?php endif ?>
78
/>

src/Symfony/Component/Form/Type/Loader/DefaultTypeLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function __construct(
3232
new Type\CountryType(),
3333
new Type\DateType(),
3434
new Type\DateTimeType(),
35+
new Type\EmailType(),
3536
new Type\HiddenType(),
3637
new Type\IntegerType(),
3738
new Type\LanguageType(),

tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,41 @@ public function testDateText()
603603
);
604604
}
605605

606+
public function testEmail()
607+
{
608+
$form = $this->factory->create('email', 'na&me', array(
609+
'property_path' => 'name',
610+
'data' => 'foo&bar',
611+
));
612+
613+
$this->assertWidgetMatchesXpath($form->createView(), array(),
614+
'/input
615+
[@type="email"]
616+
[@name="na&me"]
617+
[@value="foo&bar"]
618+
[not(@maxlength)]
619+
'
620+
);
621+
}
622+
623+
public function testEmailWithMaxLength()
624+
{
625+
$form = $this->factory->create('email', 'na&me', array(
626+
'property_path' => 'name',
627+
'data' => 'foo&bar',
628+
'max_length' => 123,
629+
));
630+
631+
$this->assertWidgetMatchesXpath($form->createView(), array(),
632+
'/input
633+
[@type="email"]
634+
[@name="na&me"]
635+
[@value="foo&bar"]
636+
[@maxlength="123"]
637+
'
638+
);
639+
}
640+
606641
public function testFile()
607642
{
608643
$form = $this->factory->create('file', 'na&me', array('property_path' => 'name'));

0 commit comments

Comments
 (0)