From 1ffa6a1f747dbd1bcbb6d0e444481cedb29ec338 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 15 Aug 2019 12:01:38 +0100 Subject: [PATCH] Use get/set value attribute for value elements (#217) * Update fixes for CssXPath * Use get/set attribute for value elements * Missing parameter to setAttribute --- composer.lock | 18 +++++++++++++----- src/Element.php | 4 ++-- test/unit/ElementTest.php | 11 +++++++++++ test/unit/Helper/Helper.php | 29 +++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 20403284..00549dc6 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "phpgt/cssxpath", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/PhpGt/CssXPath.git", - "reference": "99184374bd3b9565373c09e3c7be179a5d2298bb" + "reference": "af4b9583ad4a950225f10a0b9c97d8dc4f14e22d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/CssXPath/zipball/99184374bd3b9565373c09e3c7be179a5d2298bb", - "reference": "99184374bd3b9565373c09e3c7be179a5d2298bb", + "url": "https://api.github.com/repos/PhpGt/CssXPath/zipball/af4b9583ad4a950225f10a0b9c97d8dc4f14e22d", + "reference": "af4b9583ad4a950225f10a0b9c97d8dc4f14e22d", "shasum": "" }, "require": { @@ -37,8 +37,16 @@ "license": [ "MIT" ], + "authors": [ + { + "name": "Greg Bowler", + "role": "Developer", + "email": "greg.bowler@g105b.com", + "homepage": "https://www.g105b.com" + } + ], "description": "Convert CSS selectors to XPath queries.", - "time": "2019-08-09T15:24:18+00:00" + "time": "2019-08-15T09:48:36+00:00" }, { "name": "psr/http-message", diff --git a/src/Element.php b/src/Element.php index ca3b1265..81f8f046 100644 --- a/src/Element.php +++ b/src/Element.php @@ -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; @@ -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 { diff --git a/test/unit/ElementTest.php b/test/unit/ElementTest.php index 99fd01c8..67a4e75b 100644 --- a/test/unit/ElementTest.php +++ b/test/unit/ElementTest.php @@ -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); + } + } } \ No newline at end of file diff --git a/test/unit/Helper/Helper.php b/test/unit/Helper/Helper.php index 299d3db6..712752f0 100644 --- a/test/unit/Helper/Helper.php +++ b/test/unit/Helper/Helper.php @@ -370,6 +370,35 @@ class Helper { +HTML; + + const HTML_SELECTS = << +
+ + + +
HTML; } \ No newline at end of file