From 042979bababb3795272eedbd6e3f3116a06b9dde 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/BrowserKitDriver.php b/src/BrowserKitDriver.php index 00627c3..7a7982f 100644 --- a/src/BrowserKitDriver.php +++ b/src/BrowserKitDriver.php @@ -423,8 +423,8 @@ public function setValue(string $xpath, $value) return; } - if (\is_array($value) || \is_bool($value)) { - throw new DriverException('Textual and file form fields don\'t support array or boolean values'); + if (\is_array($value) || \is_bool($value) || $value === null) { + throw new DriverException('Textual and file form fields don\'t support array, boolean or null 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);