1212namespace Symfony \Component \DomCrawler \Tests ;
1313
1414use PHPUnit \Framework \TestCase ;
15+ use Symfony \Component \DomCrawler \Field \TextareaFormField ;
1516use Symfony \Component \DomCrawler \Form ;
1617use Symfony \Component \DomCrawler \FormFieldRegistry ;
1718
@@ -953,7 +954,7 @@ protected function createTestMultipleForm()
953954 return $ dom ;
954955 }
955956
956- public function testgetPhpValuesWithEmptyTextarea ()
957+ public function testGetPhpValuesWithEmptyTextarea ()
957958 {
958959 $ dom = new \DOMDocument ();
959960 $ dom ->loadHTML ('
@@ -968,4 +969,34 @@ public function testgetPhpValuesWithEmptyTextarea()
968969 $ form = new Form ($ nodes ->item (0 ), 'http://example.com ' );
969970 $ this ->assertEquals ($ form ->getPhpValues (), ['example ' => '' ]);
970971 }
972+
973+ public function testGetReturnTypes ()
974+ {
975+ $ dom = new \DOMDocument ();
976+ $ dom ->loadHTML ('
977+ <html>
978+ <form>
979+ <textarea name="foo[collection][0][bar]">item 0</textarea>
980+ </form>
981+ </html> '
982+ );
983+
984+ $ nodes = $ dom ->getElementsByTagName ('form ' );
985+ $ form = new Form ($ nodes ->item (0 ), 'http://example.com ' );
986+
987+ // FormField
988+ $ this ->assertInstanceOf (TextareaFormField::class, $ textareaFormField = $ form ->get ('foo[collection][0][bar] ' ));
989+
990+ // Array of FormField
991+ $ this ->assertSame ([
992+ 'bar ' => $ textareaFormField ,
993+ ], $ form ->get ('foo[collection][0] ' ));
994+
995+ // Array of array of FormField
996+ $ this ->assertSame ([
997+ [
998+ 'bar ' => $ textareaFormField ,
999+ ],
1000+ ], $ form ->get ('foo[collection] ' ));
1001+ }
9711002}
0 commit comments