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
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
Loading