File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -174,13 +174,13 @@ class Helper {
174
174
<description>light Belgian waffles covered with strawberrys and whipped cream</description>
175
175
<calories>900</calories>
176
176
</food>
177
- <food>
177
+ <food special-date="2020-08-30" >
178
178
<name>Berry-Berry Belgian Waffles</name>
179
179
<price>$8.95</price>
180
180
<description>light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
181
181
<calories>900</calories>
182
182
</food>
183
- <food>
183
+ <food offer="10%" >
184
184
<name>French Toast</name>
185
185
<price>$4.50</price>
186
186
<description>thick slices made from our homemade sourdough bread</description>
Original file line number Diff line number Diff line change @@ -20,6 +20,31 @@ public function testConstruction() {
20
20
// test construction from a XMLDocument object, just to be sure
21
21
$ fromXMLDocument = new XMLDocument ($ fromRawXML );
22
22
$ 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
+ }
23
44
45
+ self ::assertEquals (
46
+ 650 + 900 + 900 + 600 + 950 ,
47
+ $ totalCalories
48
+ );
24
49
}
25
50
}
You can’t perform that action at this time.
0 commit comments