8000 bug #59399 [DomCrawler] Make `ChoiceFormField::isDisabled` return `tr… · symfony/symfony@cb5fdaf · GitHub
[go: up one dir, main page]

Skip to content

Commit cb5fdaf

Browse files
bug #59399 [DomCrawler] Make ChoiceFormField::isDisabled return true for unchecked disabled checkboxes (MatTheCat)
This PR was merged into the 6.4 branch. Discussion ---------- [DomCrawler] Make `ChoiceFormField::isDisabled` return `true` for unchecked disabled checkboxes | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #8348 | License | MIT `ChoiceFormField::isDisabled`’s PHPDoc reads > Check if the current selected option is disabled. But a checkbox really embeds two options: either you check it, or not; which means it always has a selected option. Then, if a checkbox is disabled, these two options are too. So, `ChoiceFormField::isDisabled` should return `true` for disabled checkboxes, checked or not. This also matches what you intuitively would expect from this method. Commits ------- 9807ce6 [DomCrawler] Make `ChoiceFormField::isDisabled` return `true` for unchecked disabled checkboxes
2 parents 942aab8 + 9807ce6 commit cb5fdaf

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function hasValue(): bool
4545
*/
4646
public function isDisabled(): bool
4747
{
48+
if ('checkbox' === $this->type) {
49+
return parent::isDisabled();
50+
}
51+
4852
if (parent::isDisabled() && 'select' === $this->type) {
4953
return true;
5054
}

src/Symfony/Component/DomCrawler/Tests/Field/ChoiceFormFieldTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,17 @@ public function testCheckboxWithEmptyBooleanAttribute()
272272
$this->assertEquals('foo', $field->getValue());
273273
}
274274

275+
public function testCheckboxIsDisabled()
276+
{
277+
$node = $this->createNode('input', '', ['type' => 'checkbox', 'name' => 'name', 'disabled' => '']);
278+
$field = new ChoiceFormField($node);
279+
280+
$this->assertTrue($field->isDisabled(), '->isDisabled() returns true when the checkbox is disabled, even if it is not checked');
281+
282+
$field->tick();
283+
$this->assertTrue($field->isDisabled(), '->isDisabled() returns true when the checkbox is disabled, even if it is checked');
284+
}
285+
275286
public function testTick()
276287
{
277288
$node = $this->createSelectNode(['foo' => false, 'bar' => false]);

0 commit comments

Comments
 (0)
0