Skip to content

Commit

Permalink
test: add more tests for last-of-type and nth-of-type
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jan 12, 2024
1 parent 821d630 commit ea925a1
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion test/phpunit/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,40 @@ public function testFirstOfTypeNthOfTypeLastOfType() {
self::assertEquals('table', $matches->item(1)->nodeValue);
}

public function testLastOfType() {
$document = new DOMDocument("1.0", "UTF-8");
$document->loadHTML(Helper::HTML_CHECKBOX);

$xpath = new DOMXPath($document);
$selector = new Translator("form label:last-of-type input");

$matches = $xpath->query($selector);
self::assertEquals(1, $this->count($matches));
/** @var \DOMElement $matchingInputElement */
$matchingInputElement = $matches->item(0);
self::assertEquals(
"3",
$matchingInputElement->getAttribute("value")
);
}

public function testNthOfType() {
$document = new DOMDocument("1.0", "UTF-8");
$document->loadHTML(Helper::HTML_CHECKBOX);

$xpath = new DOMXPath($document);
$selector = new Translator("form label:nth-of-type(2) input");

$matches = $xpath->query($selector);
self::assertEquals(1, $this->count($matches));
/** @var \DOMElement $matchingInputElement */
$matchingInputElement = $matches->item(0);
self::assertEquals(
"2",
$matchingInputElement->getAttribute("value")
);
}

public function testFirstNthLastChild() {
$document = new DOMDocument("1.0", "UTF-8");
$document->loadHTML('<div><p>Track & field champions:</p>
Expand Down Expand Up @@ -296,7 +330,7 @@ public function testCaseSensitivityHtmlMode() {
0,
$xpath->query($attributeValueCaseSensitive)->length
);

$tagNameCaseInsensitive = new Translator(
"dIv"
);
Expand Down

0 comments on commit ea925a1

Please sign in to comment.