Skip to content

Commit

Permalink
[CssSelector] Tests on Xpath translator will always pass
Browse files Browse the repository at this point in the history
  • Loading branch information
franckranaivo authored and nicolas-grekas committed Jul 7, 2023
1 parent 95f3c74 commit 0ad3f7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Tests/XPath/Fixtures/ids.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@
</div>
<div id="foobar-div" foobar="ab bc
cde"><span id="foobar-span"></span></div>
</body></html>
<section>
<span id="no-siblings-of-any-type"></span>
</section>
</body>
</html>
12 changes: 6 additions & 6 deletions Tests/XPath/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testHtmlIds($css, array $elementsId)
$document->loadHTMLFile(__DIR__.'/Fixtures/ids.html');
$document = simplexml_import_dom($document);
$elements = $document->xpath($translator->cssToXPath($css));
$this->assertCount(\count($elementsId), $elementsId);
$this->assertCount(\count($elementsId), $elements);
foreach ($elements as $element) {
if (null !== $element->attributes()->id) {
$this->assertContains((string) $element->attributes()->id, $elementsId);
Expand Down Expand Up @@ -302,14 +302,14 @@ public static function getHtmlIdsTestData()
['li:nth-last-child(-n+1)', ['seventh-li']],
['li:nth-last-child(-n+3)', ['fifth-li', 'sixth-li', 'seventh-li']],
['ol:first-of-type', ['first-ol']],
['ol:nth-child(1)', ['first-ol']],
['ol:nth-child(4)', ['first-ol']],
['ol:nth-of-type(2)', ['second-ol']],
['ol:nth-last-of-type(1)', ['second-ol']],
['span:only-child', ['foobar-span']],
['span:only-child', ['foobar-span', 'no-siblings-of-any-type']],
['li div:only-child', ['li-div']],
['div *:only-child', ['li-div', 'foobar-span']],
['p:only-of-type', ['paragraph']],
[':only-of-type', ['html', 'li-div', 'foobar-span', 'paragraph']],
[':only-of-type', ['html', 'li-div', 'foobar-span', 'no-siblings-of-any-type']],
['div#foobar-div :only-of-type', ['foobar-span']],
['a:empty', ['name-anchor']],
['a:EMpty', ['name-anchor']],
Expand All @@ -318,8 +318,8 @@ public static function getHtmlIdsTestData()
['html:root', ['html']],
['li:root', []],
['* :root', []],
['*:contains("link")', ['html', 'outer-div', 'tag-anchor', 'nofollow-anchor']],
[':CONtains("link")', ['html', 'outer-div', 'tag-anchor', 'nofollow-anchor']],
['*:contains("link")', ['html', 'nil', 'outer-div', 'tag-anchor', 'nofollow-anchor']],
[':CONtains("link")', ['html', 'nil', 'outer-div', 'tag-anchor', 'nofollow-anchor']],
['*:contains("LInk")', []], // case sensitive
['*:contains("e")', ['html', 'nil', 'outer-div', 'first-ol', 'first-li', 'paragraph', 'p-em']],
['*:contains("E")', []], // case-sensitive
Expand Down

0 comments on commit 0ad3f7e

Please sign in to comment.