Skip to content

Commit

Permalink
Namespace support for :lang().
Browse files Browse the repository at this point in the history
:lang() now correctly checks *:lang for language identifiers.
  • Loading branch information
technosophos committed May 4, 2012
1 parent fbe47a0 commit db48509
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/QueryPath/CSS/DOMTraverser/PseudoClass.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -192,8 +192,23 @@ protected function lang($node, $value) {
// language from the parent... but this is unclear. // language from the parent... but this is unclear.
$operator = (strpos($value, '-') !== FALSE) ? EventHandler::isExactly : EventHandler::containsWithHyphen; $operator = (strpos($value, '-') !== FALSE) ? EventHandler::isExactly : EventHandler::containsWithHyphen;


return Util::matchesAttribute($node, 'lang', $value, $operator) $match = TRUE;
|| Util::matchesAttributeNS($node, 'lang', 'xml', $value, $operator); foreach ($node->attributes as $attrNode) {
if ($attrNode->localName == 'lang') {

if ($attrNode->nodeName == $attrNode->localName) {
// fprintf(STDOUT, "%s in NS %s\n", $attrNode->name, $attrNode->nodeName);
return Util::matchesAttribute($node, 'lang', $value, $operator);
}
else {
$nsuri = $attrNode->namespaceURI;
// fprintf(STDOUT, "%s in NS %s\n", $attrNode->name, $nsuri);
return Util::matchesAttributeNS($node, 'lang', $nsuri, $value, $operator);
}

}
}
return FALSE;
} }


/** /**
Expand Down
19 changes: 18 additions & 1 deletion test/Tests/QueryPath/CSS/PseudoClassTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,7 +61,24 @@ public function testLang() {
} }


public function testLangNS() { public function testLangNS() {
$this->markTestIncomplete(); $xml = '<?xml version="1.0"?><root><foo xml:lang="en-US">test</foo></root>';

list($ele, $root) = $this->doc($xml, 'foo');
$ps = new PseudoClass();

$ret = $ps->elementMatches('lang', $ele, $root, 'en-US');
$this->assertTrue($ret);
$ret = $ps->elementMatches('lang', $ele, $root, 'en');
$this->assertTrue($ret);
$ret = $ps->elementMatches('lang', $ele, $root, 'fr-FR');
$this->assertFalse($ret);
$ret = $ps->elementMatches('lang', $ele, $root, 'fr');
$this->assertFalse($ret);


// Check on ele that doesn't have lang.
$ret = $ps->elementMatches('lang', $root, $root, 'fr');
$this->assertFalse($ret);
} }


public function testFormType() { public function testFormType() {
Expand Down

0 comments on commit db48509

Please sign in to comment.