From 62ae1c590c3e2fd27e9a05ea1fc0d19c6fb6208f Mon Sep 17 00:00:00 2001 From: Simon Bouland Date: Tue, 26 Jan 2016 10:26:29 +0100 Subject: [PATCH 1/3] ChoiceFormField of type "select" could be "disabled" Hi, A select could be "globaly" disabled not only one of its options. http://www.w3schools.com/tags/att_select_disabled.asp --- src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php b/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php index fcf510c370a06..a8012408c9ec2 100644 --- a/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php +++ b/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php @@ -59,6 +59,10 @@ public function hasValue() */ public function isDisabled() { + if (parent::isDisabled() && 'radio' !== $this->type) { + return true; + } + foreach ($this->options as $option) { if ($option['value'] == $this->value && $option['disabled']) { return true; From 653ecb2dfef5128cb277df9994d04bbbf9ec47d4 Mon Sep 17 00:00:00 2001 From: Simon Bouland Date: Tue, 26 Jan 2016 10:28:55 +0100 Subject: [PATCH 2/3] Add testSelectIsDisabled Check if field attribute disabled is working --- .../DomCrawler/Tests/Field/ChoiceFormFieldTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php b/src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php index 9b31945b237f8..8b35cc9ac5ba0 100644 --- a/src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php @@ -120,6 +120,14 @@ public function testSelectWithEmptyBooleanAttribute() $this->assertEquals('bar', $field->getValue()); } + public function testSelectIsDisabled() + { + $node = $this->createSelectNode(array('foo' => false, 'bar' => true), array('disabled' => 'disabled')); + $field = new ChoiceFormField($node); + + $this->assertTrue($field->isDisabled(), '->isDisabled() returns true for selects with a disabled attribute'); + } + public function testMultipleSelects() { $node = $this->createSelectNode(array('foo' => false, 'bar' => false), array('multiple' => 'multiple')); From 7506dfc47450246664886d3aa7663f26dc50a28d Mon Sep 17 00:00:00 2001 From: Simon Bouland Date: Mon, 15 Feb 2016 22:14:16 +0100 Subject: [PATCH 3/3] Update ChoiceFormField.php Review --- src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php b/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php index a8012408c9ec2..3e05015873588 100644 --- a/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php +++ b/src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php @@ -59,7 +59,7 @@ public function hasValue() */ public function isDisabled() { - if (parent::isDisabled() && 'radio' !== $this->type) { + if (parent::isDisabled() && 'select' === $this->type) { return true; }