From bee9b4d58a60b0f6e6cfda76dda4f84a9588daf9 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 29 Nov 2023 11:10:16 +0100 Subject: [PATCH] Fix the validation of invalid values in tests --- src/BrowserKitDriver.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BrowserKitDriver.php b/src/BrowserKitDriver.php index 00627c3..325a699 100644 --- a/src/BrowserKitDriver.php +++ b/src/BrowserKitDriver.php @@ -424,7 +424,7 @@ public function setValue(string $xpath, $value) } if (\is_array($value) || \is_bool($value)) { - throw new DriverException('Textual and file form fields don\'t support array or boolean values'); + throw new DriverException('Textual and file form fields don\'t support array or boolean values.'); } $field->setValue($value); @@ -592,6 +592,12 @@ protected function prepareUrl(string $url) protected function getFormField(string $xpath) { $fieldNode = $this->getCrawlerNode($this->getFilteredCrawler($xpath)); + $fieldType = $fieldNode->getAttribute('type'); + + if (\in_array($fieldType, ['button', 'submit', 'image'], true)) { + throw new DriverException(sprintf('Cannot access a form field of type "%s".', $fieldType)); + } + $fieldName = str_replace('[]', '', $fieldNode->getAttribute('name')); $formNode = $this->getFormNode($fieldNode);