Skip to content

Commit

Permalink
Select value: check falsey values (#318)
Browse files Browse the repository at this point in the history
* safer use of nullable domNode property

* stan: improve types (level 6)

* build: cite Andrii in authors section

* build: bump dependencies

* tweak: allow selecting a select's option by setting select's value

* test: select value interacts with appropriate option value

* stan: improve types

* fix: Compare nulls with falsey values
  • Loading branch information
g105b authored Jan 30, 2022
1 parent 83dcb5a commit 762e108
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/HTMLElement/HTMLOptionElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ protected function __prop_set_text(string $value):void {

/** @link https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/value */
protected function __prop_get_value():string {
if($value = $this->getAttribute("value")) {
$value = $this->getAttribute("value");
if(!is_null($value)) {
return $value;
}

Expand Down
21 changes: 21 additions & 0 deletions test/phpunit/HTMLElement/HTMLSelectElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,25 @@ public function testValue_selectsAppropriateOptions_withValueAttribute():void {
}
}
}

public function testValue_setBinaryNumber():void {
/** @var HTMLSelectElement $sut */
$sut = NodeTestFactory::createHTMLElement("select");
/** @var HTMLOptionElement $optionEmpty */
$optionEmpty = $sut->ownerDocument->createElement("option");
/** @var HTMLOptionElement $optionYes */
$optionYes = $sut->ownerDocument->createElement("option");
$optionYes->textContent = "Yes";
$optionYes->value = "1";
/** @var HTMLOptionElement $optionNo */
$optionNo = $sut->ownerDocument->createElement("option");
$optionNo->textContent = "No";
$optionNo->value = "0";

$sut->append($optionEmpty, $optionYes, $optionNo);
$sut->value = "0";

self::assertTrue($optionNo->selected);
self::assertFalse($optionYes->selected);
}
}

0 comments on commit 762e108

Please sign in to comment.