From 9a9c04512e5dcb77c7fe5d850e3f2a0250cc160e Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 18 Jan 2017 20:07:16 +0100 Subject: * Motor Sport Magazine feed provider --- .../test/Tests/QueryPath/CSS/PseudoClassTest.php | 828 +++++++++++++++++++++ 1 file changed, 828 insertions(+) create mode 100644 lib/querypath/test/Tests/QueryPath/CSS/PseudoClassTest.php (limited to 'lib/querypath/test/Tests/QueryPath/CSS/PseudoClassTest.php') diff --git a/lib/querypath/test/Tests/QueryPath/CSS/PseudoClassTest.php b/lib/querypath/test/Tests/QueryPath/CSS/PseudoClassTest.php new file mode 100644 index 0000000..6798b1c --- /dev/null +++ b/lib/querypath/test/Tests/QueryPath/CSS/PseudoClassTest.php @@ -0,0 +1,828 @@ +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 = '