Skip to content
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

More tests for last-of-type and nth-of-type #226

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Merge branch 'master' of github.com:PhpGt/CssXPath
� Conflicts:
�	src/Translator.php
�	test/phpunit/Helper/Helper.php
Greg Bowler committed Sep 14, 2022
commit c8b9da78fb9bf2ef440a393bfef834a270b86873
18 changes: 9 additions & 9 deletions src/Translator.php
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ protected function convertSingleSelector(string $css):string {
$thread = array_values($thread);

$xpath = [$this->prefix];
$hasElement = false;
$hasElement = false;
foreach($thread as $threadKey => $currentThreadItem) {
$next = isset($thread[$threadKey + 1])
? $thread[$threadKey + 1]
@@ -71,7 +71,7 @@ protected function convertSingleSelector(string $css):string {
case "star":
case "element":
$xpath []= $currentThreadItem['content'];
$hasElement = true;
$hasElement = true;
break;

case "pseudo":
@@ -161,7 +161,7 @@ protected function convertSingleSelector(string $css):string {

case "child":
array_push($xpath, "/");
$hasElement = false;
$hasElement = false;
break;

case "id":
@@ -170,31 +170,31 @@ protected function convertSingleSelector(string $css):string {
($hasElement ? '' : '*')
. "[@id='{$currentThreadItem['content']}']"
);
$hasElement = true;
$hasElement = true;
break;

case "class":
// https://devhints.io/xpath#class-check
array_push(
$xpath,
($hasElement ? '' : '*')
($hasElement ? '' : '*')
. "[contains(concat(' ',normalize-space(@class),' '),' {$currentThreadItem['content']} ')]"
);
$hasElement = true;
$hasElement = true;
break;

case "sibling":
array_push(
$xpath,
"/following-sibling::*[1]/self::"
);
$hasElement = false;
$hasElement = false;
break;

case "attribute":
if(!$hasElement) {
array_push($xpath, "*");
$hasElement = true;
$hasElement = true;
}

/** @var null|array<int, array<string, string>> $detail */
@@ -267,7 +267,7 @@ protected function convertSingleSelector(string $css):string {

case "descendant":
array_push($xpath, "//");
$hasElement = false;
$hasElement = false;
break;
}
}
2 changes: 1 addition & 1 deletion test/phpunit/Helper/Helper.php
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ class Helper {
</form>
HTML;

const HTML_SELECTORS = <<<HTML
const HTML_SELECTORS = <<<HTML
<!doctype html>
<html>
<head>
You are viewing a condensed version of this merge commit. You can view the full changes here.