File tree 2 files changed +47
-0
lines changed
Filter options
src/Symfony/Component/Form/Tests
2 files changed +47
-0
lines changed
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Component \Form \Tests \Fixtures ;
4
+
5
+ use Symfony \Component \Form \FormInterface ;
6
+
7
+ use Symfony \Component \Form \AbstractType ;
8
+ use Symfony \Component \Form \FormBuilder ;
9
+
10
+ class AuthorType extends AbstractType
11
+ {
12
+ public function buildForm (FormBuilder $ builder , array $ options )
13
+ {
14
+ $ builder
15
+ ->add ('firstName ' )
16
+ ->add ('lastName ' )
17
+ ;
18
+ }
19
+
20
+ public function getName ()
21
+ {
22
+ return 'author ' ;
23
+ }
24
+
25
+ public function getDefaultOptions ()
26
+ {
27
+ return array (
28
+ 'data_class ' => 'Symfony\Component\Form\Tests\Fixtures\Author ' ,
29
+ );
30
+ }
31
+ }
Original file line number Diff line number Diff line change 16
16
use Symfony \Component \Form \Guess \Guess ;
17
17
use Symfony \Component \Form \Guess \ValueGuess ;
18
18
use Symfony \Component \Form \Guess \TypeGuess ;
19
+ use Symfony \Component \Form \Tests \Fixtures \Author ;
20
+ use Symfony \Component \Form \Tests \Fixtures \AuthorType ;
19
21
use Symfony \Component \Form \Tests \Fixtures \TestExtension ;
20
22
use Symfony \Component \Form \Tests \Fixtures \FooType ;
21
23
use Symfony \Component \Form \Tests \Fixtures \FooTypeBarExtension ;
@@ -539,6 +541,20 @@ public function testUnknownOption()
539
541
$ factory ->createNamedBuilder ($ type , "text " , "value " , array ("unknown " => "opt " ));
540
542
}
541
543
544
+ public function testFieldTypeCreatesDefaultValueForEmptyDataOption ()
545
+ {
546
+ $ factory = new FormFactory (array (new \Symfony \Component \Form \Extension \Core \CoreExtension ()));
547
+
548
+ $ form = $ factory ->createNamedBuilder (new AuthorType (), 'author ' )->getForm ();
549
+ $ form ->bind (array ('firstName ' => 'John ' , 'lastName ' => 'Smith ' ));
550
+
551
+ $ author = new Author ();
552
+ $ author ->firstName = 'John ' ;
553
+ $ author ->setLastName ('Smith ' );
554
+
555
+ $ this ->assertEquals ($ author , $ form ->getData ());
556
+ }
557
+
542
558
private function createMockFactory (array $ methods = array ())
543
559
{
544
560
return $ this ->getMockBuilder ('Symfony\Component\Form\FormFactory ' )
You can’t perform that action at this time.
0 commit comments