From b2029564e5fe1f7e8a154defe20604666c7192a3 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Sun, 5 Jun 2016 16:45:50 +0100 Subject: [PATCH] Fix for XML settings, together with unit tests --- Classes/PHPExcel/Settings.php | 16 ++++++----- Examples/01simple.php | 6 ++++ unitTests/Classes/PHPExcel/SettingsTest.php | 32 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 unitTests/Classes/PHPExcel/SettingsTest.php diff --git a/Classes/PHPExcel/Settings.php b/Classes/PHPExcel/Settings.php index eff33f0..dcbc89f 100644 --- a/Classes/PHPExcel/Settings.php +++ b/Classes/PHPExcel/Settings.php @@ -353,34 +353,36 @@ class PHPExcel_Settings } /** - * Set default options for libxml loader + * Set options for libxml loader * - * @param int $options Default options for libxml loader + * @param int $options Options for libxml loader */ 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; } /** - * Get default options for libxml loader. + * Get defined options for libxml loader. * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly. * * @return int Default options for libxml loader */ 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/Examples/01simple.php b/Examples/01simple.php index e9671be..4644a46 100644 --- a/Examples/01simple.php +++ b/Examples/01simple.php @@ -37,6 +37,12 @@ define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '
'); require_once dirname(__FILE__) . '/../Classes/PHPExcel.php'; + +$count = 39; +$columnLetter = PHPExcel_Cell::stringFromColumnIndex($count); + +var_dump($columnLetter); +die(); // Create new PHPExcel object echo date('H:i:s') , " Create new PHPExcel object" , EOL; $objPHPExcel = new PHPExcel(); diff --git a/unitTests/Classes/PHPExcel/SettingsTest.php b/unitTests/Classes/PHPExcel/SettingsTest.php new file mode 100644 index 0000000..0618c78 --- /dev/null +++ b/unitTests/Classes/PHPExcel/SettingsTest.php @@ -0,0 +1,32 @@ +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)); + } + +}