Skip to content

Commit 85af612

Browse files
committed
Tests
1 parent 00e2303 commit 85af612

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
Dom\Element::getElementsByClassName() non quirks mode
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = Dom\HTMLDocument::createFromString(<<<HTML
9+
<!DOCTYPE html>
10+
<div id="container">
11+
<p class="Bar">1</p>
12+
<p class="bar">2</p>
13+
<p class="Bar Foo">3</p>
14+
<p class="Bar foo">4</p>
15+
<p class="foo bar">5</p>
16+
<p class="foo bar" name="here">6</p>
17+
</div>
18+
<div>
19+
<p class="Bar">7</p>
20+
<p class="bar">8</p>
21+
<p class="Bar Foo">9</p>
22+
<p class="Bar foo">10</p>
23+
<p class="foo bar">11</p>
24+
</div>
25+
HTML);
26+
27+
$collection = $dom->getElementsByClassName("foo \n bar");
28+
29+
echo "There are {$collection->length} items in the document in total that have both \"foo\" and \"bar\"\n";
30+
31+
$collection = $dom->getElementById('container')->getElementsByClassName("foo \n bar");
32+
33+
echo "There are {$collection->length} items in #container in total that have both \"foo\" and \"bar\"\n";
34+
35+
foreach ($collection as $key => $node) {
36+
echo "--- Key $key ---\n";
37+
var_dump($node->tagName, $node->textContent);
38+
var_dump($node === $collection->item($key));
39+
}
40+
41+
var_dump($collection->namedItem("here")->textContent);
42+
43+
?>
44+
--EXPECT--
45+
There are 3 items in the document in total that have both "foo" and "bar"
46+
There are 2 items in #container in total that have both "foo" and "bar"
47+
--- Key 0 ---
48+
string(1) "P"
49+
string(1) "5"
50+
bool(true)
51+
--- Key 1 ---
52+
string(1) "P"
53+
string(1) "6"
54+
bool(true)
55+
string(1) "6"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--TEST--
2+
Dom\Element::getElementsByClassName() quirks mode
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$dom = Dom\HTMLDocument::createFromString(<<<HTML
9+
<div class=" foo bar ">
10+
<p class="bar">
11+
<p class="bar" name="here">1</p>
12+
<p name="here">2</p>
13+
<p name="here">3</p>
14+
<p class="bAR" name="here">4</p>
15+
</p>
16+
<b class="foo bars"></b>
17+
</div>
18+
HTML, LIBXML_NOERROR);
19+
$collection = $dom->documentElement->getElementsByClassName("Bar");
20+
21+
echo "There are {$dom->getElementsByClassName("foo \n bar")->count()} items in the document in total that have both \"foo\" and \"bar\"\n";
22+
23+
echo "There are {$collection->count()} \"Bar\" items\n";
24+
25+
foreach ($collection as $key => $node) {
26+
echo "--- Key $key ---\n";
27+
var_dump($node->tagName, $node->textContent);
28+
var_dump($node === $collection->item($key));
29+
}
30+
31+
var_dump($collection->namedItem("here")->textContent);
32+
33+
?>
34+
--EXPECT--
35+
There are 1 items in the document in total that have both "foo" and "bar"
36+
There are 4 "Bar" items
37+
--- Key 0 ---
38+
string(3) "DIV"
39+
string(56) "
40+
41+
1
42+
2
43+
3
44+
4
45+
46+
47+
"
48+
bool(true)
49+
--- Key 1 ---
50+
string(1) "P"
51+
string(9) "
52+
"
53+
bool(true)
54+
--- Key 2 ---
55+
string(1) "P"
56+
string(1) "1"
57+
bool(true)
58+
--- Key 3 ---
59+
string(1) "P"
60+
string(1) "4"
61+
bool(true)
62+
string(1) "1"

0 commit comments

Comments
 (0)