From 4b8c0ae9ae92eb22030122d44ac10bc8a46df068 Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sun, 10 Mar 2024 15:45:39 +0000 Subject: [PATCH] Dateien nach "includes/PHPExcel/unitTests" hochladen --- includes/PHPExcel/unitTests/bootstrap.php | 49 +++++++ includes/PHPExcel/unitTests/phpunit-cc.xml | 40 ++++++ includes/PHPExcel/unitTests/phpunit.xml | 32 +++++ .../unitTests/testDataFileIterator.php | 131 ++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 includes/PHPExcel/unitTests/bootstrap.php create mode 100644 includes/PHPExcel/unitTests/phpunit-cc.xml create mode 100644 includes/PHPExcel/unitTests/phpunit.xml create mode 100644 includes/PHPExcel/unitTests/testDataFileIterator.php diff --git a/includes/PHPExcel/unitTests/bootstrap.php b/includes/PHPExcel/unitTests/bootstrap.php new file mode 100644 index 0000000..8e8cdb3 --- /dev/null +++ b/includes/PHPExcel/unitTests/bootstrap.php @@ -0,0 +1,49 @@ + /etc/php.d/xdebug.ini' . "\n"; +} diff --git a/includes/PHPExcel/unitTests/phpunit-cc.xml b/includes/PHPExcel/unitTests/phpunit-cc.xml new file mode 100644 index 0000000..8cb6cf5 --- /dev/null +++ b/includes/PHPExcel/unitTests/phpunit-cc.xml @@ -0,0 +1,40 @@ + + + + + + + ./Classes + + + + ../Classes + + ../Classes/PHPExcel/Shared/PCLZip + ../Classes/PHPExcel/Shared/JAMA + ../Classes/PHPExcel/Writer/PDF + + + + + + + + + + diff --git a/includes/PHPExcel/unitTests/phpunit.xml b/includes/PHPExcel/unitTests/phpunit.xml new file mode 100644 index 0000000..d024c28 --- /dev/null +++ b/includes/PHPExcel/unitTests/phpunit.xml @@ -0,0 +1,32 @@ + + + + + + + ./Classes + + + + ../Classes + + ../Classes/PHPExcel/Shared/PCLZip + ../Classes/PHPExcel/Shared/JAMA + ../Classes/PHPExcel/Writer/PDF + + + + diff --git a/includes/PHPExcel/unitTests/testDataFileIterator.php b/includes/PHPExcel/unitTests/testDataFileIterator.php new file mode 100644 index 0000000..9eabe09 --- /dev/null +++ b/includes/PHPExcel/unitTests/testDataFileIterator.php @@ -0,0 +1,131 @@ +file = fopen($file, 'r'); + } + + public function __destruct() + { + fclose($this->file); + } + + public function rewind() + { + rewind($this->file); + $this->current = $this->_parseNextDataset(); + $this->key = 0; + } + + public function valid() + { + return !feof($this->file); + } + + public function key() + { + return $this->key; + } + + public function current() + { + return $this->current; + } + + public function next() + { + $this->current = $this->_parseNextDataset(); + $this->key++; + } + + private function _parseNextDataset() + { + // Read a line of test data from the file + do { + // Only take lines that contain test data and that aren't commented out + $testDataRow = trim(fgets($this->file)); + } while (($testDataRow > '') && ($testDataRow{0} === '#')); + + // Discard any comments at the end of the line + list($testData) = explode('//',$testDataRow); + + // Split data into an array of individual values and a result + $dataSet = $this->_getcsv($testData, ',', "'"); + foreach($dataSet as &$dataValue) { + $dataValue = $this->_parseDataValue($dataValue); + } + unset($dataValue); + + return $dataSet; + } + + private function _getcsv($input, $delimiter, $enclosure) + { + if (function_exists('str_getcsv')) { + return str_getcsv($input, $delimiter, $enclosure); + } + + $temp = fopen('php://memory', 'rw'); + fwrite($temp, $input); + rewind($temp); + $data = fgetcsv($temp, strlen($input), $delimiter, $enclosure); + fclose($temp); + + if ($data === false) { + $data = array(null); + } + + return $data; + } + + private function _parseDataValue($dataValue) { + // discard any white space + $dataValue = trim($dataValue); + // test for the required datatype and convert accordingly + if (!is_numeric($dataValue)) { + if($dataValue == '') { + $dataValue = NULL; + } elseif($dataValue == '""') { + $dataValue = ''; + } elseif(($dataValue[0] == '"') && ($dataValue[strlen($dataValue)-1] == '"')) { + $dataValue = substr($dataValue,1,-1); + } elseif(($dataValue[0] == '{') && ($dataValue[strlen($dataValue)-1] == '}')) { + $dataValue = explode(';',substr($dataValue,1,-1)); + foreach($dataValue as &$dataRow) { + if (strpos($dataRow,'|') !== FALSE) { + $dataRow = explode('|',$dataRow); + foreach($dataRow as &$dataCell) { + $dataCell = $this->_parseDataValue($dataCell); + } + unset($dataCell); + } else { + $dataRow = $this->_parseDataValue($dataRow); + } + } + unset($dataRow); + } else { + switch (strtoupper($dataValue)) { + case 'NULL' : $dataValue = NULL; break; + case 'TRUE' : $dataValue = TRUE; break; + case 'FALSE' : $dataValue = FALSE; break; + } + } + } else { + if (strpos($dataValue,'.') !== FALSE) { + $dataValue = (float) $dataValue; + } else { + $dataValue = (int) $dataValue; + } + } + + return $dataValue; + } + +}