From c718a043aee30db8ce11833aaeec71d06aee096d Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Fri, 1 Jan 2021 20:54:23 +0200 Subject: [PATCH 1/2] Reproduced issue 6022 Can't fill field outside form when the field has form attribute --- tests/data/app/view/form/input-not-in-form.php | 16 ++++++++++++++++ tests/unit/Codeception/Module/TestsForWeb.php | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/data/app/view/form/input-not-in-form.php diff --git a/tests/data/app/view/form/input-not-in-form.php b/tests/data/app/view/form/input-not-in-form.php new file mode 100644 index 0000000..006dd76 --- /dev/null +++ b/tests/data/app/view/form/input-not-in-form.php @@ -0,0 +1,16 @@ + + +
+
+
+ +
+
+ +
+
+ +
+
+ + \ No newline at end of file diff --git a/tests/unit/Codeception/Module/TestsForWeb.php b/tests/unit/Codeception/Module/TestsForWeb.php index 44e76db..9dd4265 100644 --- a/tests/unit/Codeception/Module/TestsForWeb.php +++ b/tests/unit/Codeception/Module/TestsForWeb.php @@ -1684,6 +1684,17 @@ public function testClickButtonWithFormInvalidIdOutside() $this->module->click('Invalid form'); } + /** + * https://github.com/Codeception/Codeception/issues/6022 + */ + public function testFillFieldNotInForm() + { + $this->module->amOnPage('/form/input-not-in-form'); + $this->module->seeElement("form",["id" => "form1"]); + $this->module->seeElement("input",["name" => "username"]); + $this->module->fillField("username","usr-code"); + } + public function testSubmitHashForm() { $this->module->amOnPage('/form/anchor'); From a9ee9eabd9dd8bd8402f978cd1d57d07cb26dcc1 Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Fri, 1 Jan 2021 21:50:11 +0200 Subject: [PATCH 2/2] Add form elements with form attribute to cloned Form Fixes https://github.com/Codeception/Codeception/issues/6022 --- src/Codeception/Lib/InnerBrowser.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Codeception/Lib/InnerBrowser.php b/src/Codeception/Lib/InnerBrowser.php index f0c52e5..a49cfb5 100644 --- a/src/Codeception/Lib/InnerBrowser.php +++ b/src/Codeception/Lib/InnerBrowser.php @@ -1003,6 +1003,18 @@ private function getFormFromCrawler(Crawler $form) { $fakeDom = new \DOMDocument(); $fakeDom->appendChild($fakeDom->importNode($form->getNode(0), true)); + + //add fields having form attribute with id of this form + $formId = $form->attr('id'); + if ($formId !== null) { + $fakeForm = $fakeDom->firstChild; + $topParent = $form->parents()->last(); + $fieldsByFormAttribute = $topParent->filter("input[form=$formId],select[form=$formId],textarea[form=$formId]"); + foreach ($fieldsByFormAttribute as $field) { + $fakeForm->appendChild($fakeDom->importNode($field, true)); + } + } + $node = $fakeDom->documentElement; $action = (string)$this->getFormUrl($form); $cloned = new Crawler($node, $action, $this->getBaseUrl());