File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1003,6 +1003,18 @@ private function getFormFromCrawler(Crawler $form)
10031003 {
10041004 $ fakeDom = new \DOMDocument ();
10051005 $ fakeDom ->appendChild ($ fakeDom ->importNode ($ form ->getNode (0 ), true ));
1006+
1007+ //add fields having form attribute with id of this form
1008+ $ formId = $ form ->attr ('id ' );
1009+ if ($ formId !== null ) {
1010+ $ fakeForm = $ fakeDom ->firstChild ;
1011+ $ topParent = $ form ->parents ()->last ();
1012+ $ fieldsByFormAttribute = $ topParent ->filter ("input[form= $ formId],select[form= $ formId],textarea[form= $ formId] " );
1013+ foreach ($ fieldsByFormAttribute as $ field ) {
1014+ $ fakeForm ->appendChild ($ fakeDom ->importNode ($ field , true ));
1015+ }
1016+ }
1017+
10061018 $ node = $ fakeDom ->documentElement ;
10071019 $ action = (string )$ this ->getFormUrl ($ form );
10081020 $ cloned = new Crawler ($ node , $ action , $ this ->getBaseUrl ());
Original file line number Diff line number Diff line change 1+ <html >
2+ <body >
3+ <div class = " login-container2" >
4+ <form action = " /form/button" id = " form1" accept-charset = " utf-8" method = " post" ></form >
5+ <div class = " form-element-row" >
6+ <button form = " form1" name = " btn[login]" class = " primary small" >Login</button >
7+ </div >
8+ <div class = " form-element-row" >
9+ <input type = " text" id = " form1-username" name = " username" placeholder = " User code" form = " form1" />
10+ </div >
11+ <div class = " form-element-row" >
12+ <input type = " password" id = " form1-password" name = " password" placeholder = " Password" form = " form1" />
13+ </div >
14+ </div >
15+ </body >
16+ </html >
Original file line number Diff line number Diff line change @@ -1684,6 +1684,17 @@ public function testClickButtonWithFormInvalidIdOutside()
16841684 $ this ->module ->click ('Invalid form ' );
16851685 }
16861686
1687+ /**
1688+ * https://github.com/Codeception/Codeception/issues/6022
1689+ */
1690+ public function testFillFieldNotInForm ()
1691+ {
1692+ $ this ->module ->amOnPage ('/form/input-not-in-form ' );
1693+ $ this ->module ->seeElement ("form " ,["id " => "form1 " ]);
1694+ $ this ->module ->seeElement ("input " ,["name " => "username " ]);
1695+ $ this ->module ->fillField ("username " ,"usr-code " );
1696+ }
1697+
16871698 public function testSubmitHashForm ()
16881699 {
16891700 $ this ->module ->amOnPage ('/form/anchor ' );
You can’t perform that action at this time.
0 commit comments