Skip to content
Browse files

Namespace support for :lang().

:lang() now correctly checks *:lang for language identifiers.
  • Loading branch information...
1 parent fbe47a0 commit db485091d191f507cadae00b7683c7895ff83be6 @technosophos committed May 3, 2012
Showing with 35 additions and 3 deletions.
  1. +17 −2 src/QueryPath/CSS/DOMTraverser/PseudoClass.php
  2. +18 −1 test/Tests/QueryPath/CSS/PseudoClassTest.php
View
19 src/QueryPath/CSS/DOMTraverser/PseudoClass.php
@@ -192,8 +192,23 @@ protected function lang($node, $value) {
// language from the parent... but this is unclear.
$operator = (strpos($value, '-') !== FALSE) ? EventHandler::isExactly : EventHandler::containsWithHyphen;
- return Util::matchesAttribute($node, 'lang', $value, $operator)
- || Util::matchesAttributeNS($node, 'lang', 'xml', $value, $operator);
+ $match = TRUE;
+ 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;
}
/**
View
19 test/Tests/QueryPath/CSS/PseudoClassTest.php
@@ -61,7 +61,24 @@ public function testLang() {
}
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() {

0 comments on commit db48509

Please sign in to comment.
Something went wrong with that request. Please try again.