assertFalse(XmlParser::getDomDocument('')); $this->assertFalse(XmlParser::getSimpleXml('')); $this->assertNotFalse(XmlParser::getHtmlDocument('')); } public function testGetEncodingFromMetaTag() { $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('windows-1251', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('utf-8', XmlParser::getEncodingFromMetaTag('')); $this->assertEquals('iso-8859-1', XmlParser::getEncodingFromMetaTag('')); } public function testGetEncodingFromXmlTag() { $this->assertEquals('utf-8', XmlParser::getEncodingFromXmlTag("assertEquals('utf-8', XmlParser::getEncodingFromXmlTag('assertEquals('windows-1251', XmlParser::getEncodingFromXmlTag('')); $this->assertEquals('', XmlParser::getEncodingFromXmlTag(" ]> This result is &harmless; XML; $this->assertFalse(XmlParser::getDomDocument($xml)); } public function testScanForXXE() { $file = tempnam(sys_get_temp_dir(), 'PicoFeed_XmlParser'); file_put_contents($file, 'Content Injection'); $xml = << ]> &foo; XML; $this->assertFalse(XmlParser::getDomDocument($xml)); unlink($file); } public function testScanSimpleXML() { return << test XML; $result = XmlParser::getSimpleXml($xml); $this->assertTrue($result instanceof SimpleXMLElement); $this->assertEquals($result->result, 'test'); } public function testScanDomDocument() { return << test XML; $result = XmlParser::getDomDocument($xml); $this->assertTrue($result instanceof DOMDocument); $node = $result->getElementsByTagName('result')->item(0); $this->assertEquals($node->nodeValue, 'test'); } public function testScanInvalidXml() { $xml = <<test XML; $this->assertFalse(XmlParser::getDomDocument($xml)); $this->assertFalse(XmlParser::getSimpleXml($xml)); } public function testScanXmlWithDTD() { $xml = << ]> test XML; $result = XmlParser::getDomDocument($xml); $this->assertTrue($result instanceof DOMDocument); $this->assertTrue($result->validate()); } public function testReplaceXPathPrefixWithNamespaceURI() { $ns = array('lorem' => 'https://en.wikipedia.org/wiki/Lorem'); $query = '//lorem:title'; $expected = '//*[namespace-uri()="https://en.wikipedia.org/wiki/Lorem" and local-name()="title"]'; $this->assertEquals($expected, XmlParser::replaceXPathPrefixWithNamespaceURI($query, $ns)); $ns = array('lorem' => 'https://en.wikipedia.org/wiki/Lorem', 'ipsum' => 'https://en.wikipedia.org/wiki/Ipsum'); $query = '//lorem:title/ipsum:name'; $expected = '//*[namespace-uri()="https://en.wikipedia.org/wiki/Lorem" and local-name()="title"]/*[namespace-uri()="https://en.wikipedia.org/wiki/Ipsum" and local-name()="name"]'; $this->assertEquals($expected, XmlParser::replaceXPathPrefixWithNamespaceURI($query, $ns)); $ns = array('lorem' => 'https://en.wikipedia.org/wiki/Lorem', 'ipsum' => 'https://en.wikipedia.org/wiki/Ipsum'); $query = '//lorem:title/ipsum:name/@xml:lang'; $expected = '//*[namespace-uri()="https://en.wikipedia.org/wiki/Lorem" and local-name()="title"]/*[namespace-uri()="https://en.wikipedia.org/wiki/Ipsum" and local-name()="name"]/@xml:lang'; $this->assertEquals($expected, XmlParser::replaceXPathPrefixWithNamespaceURI($query, $ns)); } }