Skip to content

Commit 1ffa6a1

Browse files
author
Greg Bowler
authored
Use get/set value attribute for value elements (#217)
* Update fixes for CssXPath * Use get/set attribute for value elements * Missing parameter to setAttribute
1 parent 4df60cd commit 1ffa6a1

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

composer.lock

Lines changed: 13 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Element.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function prop_get_value() {
124124
}
125125

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

130130
return null;
@@ -136,7 +136,7 @@ public function prop_set_value(string $newValue) {
136136
return $this->$methodName($newValue);
137137
}
138138

139-
$this->nodeValue = $newValue;
139+
$this->setAttribute("value", $newValue);
140140
}
141141

142142
public function prop_get_id():?string {

test/unit/ElementTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,15 @@ public function testAttributeValueSelection() {
499499
self::assertSame($input1, $input2);
500500
self::assertEquals("Scarlett", $input1->value);
501501
}
502+
503+
public function testOptionValueGetSet() {
504+
$document = new HTMLDocument(Helper::HTML_SELECTS);
505+
foreach($document->querySelectorAll("[name=from] option") as $fromOption) {
506+
self::assertIsNumeric($fromOption->value);
507+
}
508+
509+
foreach($document->querySelectorAll("[name=to] option") as $toOption) {
510+
self::assertIsNumeric($toOption->value);
511+
}
512+
}
502513
}

test/unit/Helper/Helper.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,35 @@ class Helper {
370370
<input name="dob" type="date" />
371371
</label>
372372
</form>
373+
HTML;
374+
375+
const HTML_SELECTS = <<<HTML
376+
<!doctype html>
377+
<form>
378+
<label>
379+
<span>From:</span>
380+
<select name="from">
381+
<option value="0">Zero</option>
382+
<option value="1">One</option>
383+
<option value="2">Two</option>
384+
<option value="3">Three</option>
385+
<option value="4">Four</option>
386+
<option value="5">Five</option>
387+
</select>
388+
</label>
389+
390+
<label>
391+
<span>To:</span>
392+
<select name="to">
393+
<option value="5">Five</option>
394+
<option value="6">Six</option>
395+
<option value="7">Seven</option>
396+
<option value="8">Eight</option>
397+
<option value="9">Nine</option>
398+
<option value="10">Ten</option>
399+
</select>
400+
</label>
401+
</form>
373402
HTML;
374403

375404
}

0 commit comments

Comments
 (0)