-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement GH-18550: Implement getElementsByClassName() #19108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+364
−4
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fca2bbb
Implement GH-18550: Implement getElementsByClassName()
nielsdos 00e2303
fixes
nielsdos 85af612
Tests
nielsdos 8e7f320
Can use HASH_MAP
nielsdos fd749fb
Make test a bit more logical
nielsdos 210397f
NEWS and UPGRADING
nielsdos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
ext/dom/tests/modern/common/Element_getElementsByClassName.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--TEST-- | ||
Dom\Element::getElementsByClassName() | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
$dom = Dom\HTMLDocument::createFromString(<<<HTML | ||
<div class=" foo bar "> | ||
<p class="bar"> | ||
<p class="bar" name="here">1</p> | ||
<p name="here">2</p> | ||
<p name="here">3</p> | ||
<p class="bar" name="here">4</p> | ||
</p> | ||
<b class="foo bars"></b> | ||
</div> | ||
HTML, LIBXML_NOERROR); | ||
Girgias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$collection = $dom->documentElement->getElementsByClassName("bar"); | ||
|
||
echo "There are {$dom->getElementsByClassName("foo \n bar")->count()} items in the document in total that have both \"foo\" and \"bar\"\n"; | ||
|
||
echo "There are {$collection->count()} \"bar\" items\n"; | ||
|
||
foreach ($collection as $key => $node) { | ||
var_dump($key, $node->tagName); | ||
var_dump($node === $collection->item($key)); | ||
} | ||
|
||
var_dump($collection->namedItem("here")->textContent); | ||
|
||
?> | ||
--EXPECT-- | ||
There are 1 items in the document in total that have both "foo" and "bar" | ||
There are 4 "bar" items | ||
int(0) | ||
string(3) "DIV" | ||
bool(false) | ||
int(1) | ||
string(1) "P" | ||
bool(false) | ||
string(1) "1" |
32 changes: 32 additions & 0 deletions
32
ext/dom/tests/modern/common/Element_getElementsByClassName_empty.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
Dom\Element::getElementsByClassName() empty class names | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
$dom = Dom\HTMLDocument::createFromString(<<<HTML | ||
<div class=" foo bar "> | ||
<p id="child"></p> | ||
</div> | ||
HTML, LIBXML_NOERROR); | ||
|
||
$collection = $dom->documentElement->getElementsByClassName(""); | ||
var_dump($collection->count()); | ||
|
||
foreach ($collection as $node) { | ||
throw new Error("unreachable"); | ||
} | ||
|
||
var_dump($dom->getElementsByClassName(" ")->count()); | ||
var_dump($dom->getElementsByClassName("\t")->count()); | ||
var_dump($dom->getElementsByClassName("\t\n\f\v")->count()); | ||
var_dump($dom->getElementsByClassName("\t\n\f\v")->namedItem("cjild")); | ||
Girgias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
?> | ||
--EXPECT-- | ||
int(0) | ||
int(0) | ||
int(0) | ||
int(0) | ||
NULL |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.