Fix for XML settings, together with unit tests

This commit is contained in:
MarkBaker 2016-06-05 17:03:42 +01:00
parent 36a9068b38
commit 1702d95333
2 changed files with 36 additions and 8 deletions

View File

@ -352,12 +352,10 @@ class Settings
*/
public static function setLibXmlLoaderOptions($options = null)
{
if (is_null($options) && defined(LIBXML_DTDLOAD)) {
if (is_null($options) && defined('LIBXML_DTDLOAD')) {
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
}
if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
@libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
}
@libxml_disable_entity_loader((bool) $options);
self::$libXmlLoaderOptions = $options;
}
@ -369,12 +367,13 @@ class Settings
*/
public static function getLibXmlLoaderOptions()
{
if (is_null(self::$libXmlLoaderOptions) && defined(LIBXML_DTDLOAD)) {
if (is_null(self::$libXmlLoaderOptions) && defined('LIBXML_DTDLOAD')) {
self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
} elseif (is_null(self::$libXmlLoaderOptions)) {
self::$libXmlLoaderOptions = true;
}
if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
@libxml_disable_entity_loader(self::$libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
}
@libxml_disable_entity_loader((bool) self::$libXmlLoaderOptions);
return self::$libXmlLoaderOptions;
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace PHPExcel;
class SettingsTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
}
/**
*/
public function testGetXMLSettings()
{
$result = call_user_func(array('PHPExcel\\Settings','getLibXmlLoaderOptions'));
$this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR) & $result));
}
/**
*/
public function testSetXMLSettings()
{
call_user_func_array(array('PHPExcel\\Settings','setLibXmlLoaderOptions'), [LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID]);
$result = call_user_func(array('PHPExcel\\Settings','getLibXmlLoaderOptions'));
$this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID) & $result));
}
}