Skip to content

Commit 41bad81

Browse files
author
Greg Bowler
authored
Test querySelector on XML documents (#256)
* Improve compatibility with traits' constant usage * Test query selector methods on XML documents Closes #174
1 parent 2ef9540 commit 41bad81

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

test/phpunit/Helper/Helper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ class Helper {
174174
<description>light Belgian waffles covered with strawberrys and whipped cream</description>
175175
<calories>900</calories>
176176
</food>
177-
<food>
177+
<food special-date="2020-08-30">
178178
<name>Berry-Berry Belgian Waffles</name>
179179
<price>$8.95</price>
180180
<description>light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
181181
<calories>900</calories>
182182
</food>
183-
<food>
183+
<food offer="10%">
184184
<name>French Toast</name>
185185
<price>$4.50</price>
186186
<description>thick slices made from our homemade sourdough bread</description>

test/phpunit/XMLDocumentTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ public function testConstruction() {
2020
// test construction from a XMLDocument object, just to be sure
2121
$fromXMLDocument = new XMLDocument($fromRawXML);
2222
$this->assertInstanceOf(XMLDocument::class, $fromXMLDocument);
23+
}
24+
25+
public function testQuerySelector() {
26+
$document = new XMLDocument(Helper::XML);
27+
$firstFoodName = $document->querySelector("food name");
28+
self::assertEquals("Belgian Waffles", $firstFoodName->nodeValue);
29+
}
30+
31+
public function testQuerySelectorAttribute() {
32+
$document = new XMLDocument(Helper::XML);
33+
$offerFood = $document->querySelector("food[offer]");
34+
self::assertEquals("10%", $offerFood->getAttribute("offer"));
35+
}
36+
37+
public function testQuerySelectorAll() {
38+
$document = new XMLDocument(Helper::XML);
39+
$totalCalories = 0;
40+
41+
foreach($document->querySelectorAll("breakfast-menu>food calories") as $caloriesElement) {
42+
$totalCalories += (int)$caloriesElement->nodeValue;
43+
}
2344

45+
self::assertEquals(
46+
650 + 900 + 900 + 600 + 950,
47+
$totalCalories
48+
);
2449
}
2550
}

0 commit comments

Comments
 (0)