test

"); $this->assertEquals("//div[@id='UserProfile']//label", $parser->selector2xpath("div#UserProfile label")); $this->assertEquals("//div", $parser->selector2xpath("div")); $this->assertEquals("//div[contains(@class,'test')]", $parser->selector2xpath("div.test")); $this->assertEquals( "//*[@id='UserProfile']//div[contains(@class,'test')]//*[contains(@class,'other')]//div[@id='Item']", $parser->selector2xpath("#UserProfile div.test .other div#Item") ); } public function testGetBySelector() { $parser = new CSSContentParser( << test

result

test

HTML ); $result = $parser->getBySelector('div.one'); $this->assertEquals("A", $result[0]['id'] . ''); $result = $parser->getBySelector('div.two'); $this->assertEquals("A", $result[0]['id'] . ''); $result = $parser->getBySelector('div.three'); $this->assertEquals("A", $result[0]['id'] . ''); $result = $parser->getBySelector('div#A p.other'); $this->assertEquals("result", $result[0] . ''); $result = $parser->getBySelector('#A .other'); $this->assertEquals("result", $result[0] . ''); } public function testXmlEntitiesDisabled() { // CSSContentParser uses simplexml to parse html // Ensure XML entities are not substituted in to prevent XXE attacks $xml = ']>
Hello &myentity;
'; $parser = new CSSContentParser($xml); $div = $parser->getBySelector('div')[0]->asXML(); $this->assertEquals('
Hello &myentity;
', $div); } }