Skip to content

Commit

Permalink
Use get/set value attribute for value elements (#217)
Browse files Browse the repository at this point in the history
* Update fixes for CssXPath

* Use get/set attribute for value elements

* Missing parameter to setAttribute
  • Loading branch information
g105b authored Aug 15, 2019
1 parent 4df60cd commit 1ffa6a1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
18 changes: 13 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function prop_get_value() {
}

if(in_array(strtoupper($this->tagName), self::VALUE_ELEMENTS)) {
return $this->nodeValue;
return $this->getAttribute("value");
}

return null;
Expand All @@ -136,7 +136,7 @@ public function prop_set_value(string $newValue) {
return $this->$methodName($newValue);
}

$this->nodeValue = $newValue;
$this->setAttribute("value", $newValue);
}

public function prop_get_id():?string {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,15 @@ public function testAttributeValueSelection() {
self::assertSame($input1, $input2);
self::assertEquals("Scarlett", $input1->value);
}

public function testOptionValueGetSet() {
$document = new HTMLDocument(Helper::HTML_SELECTS);
foreach($document->querySelectorAll("[name=from] option") as $fromOption) {
self::assertIsNumeric($fromOption->value);
}

foreach($document->querySelectorAll("[name=to] option") as $toOption) {
self::assertIsNumeric($toOption->value);
}
}
}
29 changes: 29 additions & 0 deletions test/unit/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,35 @@ class Helper {
<input name="dob" type="date" />
</label>
</form>
HTML;

const HTML_SELECTS = <<<HTML
<!doctype html>
<form>
<label>
<span>From:</span>
<select name="from">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
</label>
<label>
<span>To:</span>
<select name="to">
<option value="5">Five</option>
<option value="6">Six</option>
<option value="7">Seven</option>
<option value="8">Eight</option>
<option value="9">Nine</option>
<option value="10">Ten</option>
</select>
</label>
</form>
HTML;

}

0 comments on commit 1ffa6a1

Please sign in to comment.