From 1702d953330b40d4ab6a49aa837ea5dee4c4d151 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 5 Jun 2016 17:03:42 +0100 Subject: [PATCH] Fix for XML settings, together with unit tests --- src/PhpSpreadsheet/Settings.php | 15 +++++++------ unitTests/classes/src/SettingsTest.php | 29 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 unitTests/classes/src/SettingsTest.php diff --git a/src/PhpSpreadsheet/Settings.php b/src/PhpSpreadsheet/Settings.php index 027d4402..c64c28e4 100644 --- a/src/PhpSpreadsheet/Settings.php +++ b/src/PhpSpreadsheet/Settings.php @@ -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; } } diff --git a/unitTests/classes/src/SettingsTest.php b/unitTests/classes/src/SettingsTest.php new file mode 100644 index 00000000..b2953f18 --- /dev/null +++ b/unitTests/classes/src/SettingsTest.php @@ -0,0 +1,29 @@ +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)); + } + +}