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(''));
}
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());
}
}