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