Fix for XML settings, together with unit tests
This commit is contained in:
parent
36a9068b38
commit
1702d95333
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue