loadXML($string); $found = $doc->getElementsByTagName($tagname)->item(0); return array($found, $doc->documentElement); } /** * @expectedException \QueryPath\CSS\ParseException */ public function testUnknownPseudoClass() { $xml = 'test'; list($ele, $root) = $this->doc($xml, 'foo'); $ps = new PseudoClass(); $ps->elementMatches('TotallyFake', $ele, $root); } public function testLang() { $xml = 'test'; 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 testLangNS() { $xml = 'test'; 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() { $xml = 'test'; list($ele, $root) = $this->doc($xml, 'foo'); $ps = new PseudoClass(); $ret = $ps->elementMatches('submit', $ele, $root); $this->assertTrue($ret); $ret = $ps->elementMatches('reset', $ele, $root); $this->assertFalse($ret); } public function testHasAttribute() { $xml = 'test'; list($ele, $root) = $this->doc($xml, 'foo'); $ps = new PseudoClass(); $ret = $ps->elementMatches('enabled', $ele, $root); $this->assertTrue($ret); $ret = $ps->elementMatches('disabled', $ele, $root); $this->assertFalse($ret); } public function testHeader() { $xml = '

TEST

'; list($ele, $root) = $this->doc($xml, 'h1'); $ps = new PseudoClass(); $ret = $ps->elementMatches('header', $ele, $root); $this->assertTrue($ret); list($ele, $root) = $this->doc($xml, 'H6'); $ret = $ps->elementMatches('header', $ele, $root); $this->assertTrue($ret); list($ele, $root) = $this->doc($xml, 'hi'); $ret = $ps->elementMatches('header', $ele, $root); $this->assertFalse($ret); list($ele, $root) = $this->doc($xml, 'h1i'); $ret = $ps->elementMatches('header', $ele, $root); $this->assertFalse($ret); list($ele, $root) = $this->doc($xml, 'h12'); $ret = $ps->elementMatches('header', $ele, $root); $this->assertFalse($ret); } public function testContains(){ $xml = 'This is a test of :contains.'; list($ele, $root) = $this->doc($xml, 'h'); $ps = new PseudoClass(); $ret = $ps->elementMatches('contains', $ele, $root, 'test'); $this->assertTrue($ret); $ret = $ps->elementMatches('contains', $ele, $root, 'is a test'); $this->assertTrue($ret); $ret = $ps->elementMatches('contains', $ele, $root, 'This is a test of :contains.'); $this->assertTrue($ret); $ret = $ps->elementMatches('contains', $ele, $root, 'Agent P, here is your mission.'); $this->assertFalse($ret); $ret = $ps->elementMatches('contains', $ele, $root, "'Agent P, here is your mission.'"); $this->assertFalse($ret); } public function testContainsExactly() { $xml = 'This is a test of :contains-exactly.'; list($ele, $root) = $this->doc($xml, 'h'); $ps = new PseudoClass(); $ret = $ps->elementMatches('contains-exactly', $ele, $root, 'test'); $this->assertFalse($ret); $ret = $ps->elementMatches('contains-exactly', $ele, $root, 'This is a test of :contains-exactly.'); $this->assertTrue($ret); $ret = $ps->elementMatches('contains-exactly', $ele, $root, 'Agent P, here is your mission.'); $this->assertFalse($ret); $ret = $ps->elementMatches('contains-exactly', $ele, $root, '"Agent P, here is your mission."'); $this->assertFalse($ret); } public function testHas() { $xml = '