From 97ea12ef6d6fd80a33acca285ba8488b2a616375 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Thu, 26 Jan 2012 20:07:17 +0000 Subject: [PATCH] Allow array definitions in test data files git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@85784 2327b42d-5241-43d6-9e2a-de5ac946f064 --- unitTests/testDataFileIterator.php | 68 +++++++++++++++++++----------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/unitTests/testDataFileIterator.php b/unitTests/testDataFileIterator.php index e5bd1ea..38f8500 100644 --- a/unitTests/testDataFileIterator.php +++ b/unitTests/testDataFileIterator.php @@ -59,34 +59,54 @@ class testDataFileIterator implements Iterator // Split data into an array of individual values and a result $dataSet = explode(',',$testData); foreach($dataSet as &$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); - } 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; - } - } + $dataValue = $this->_parseDataValue($dataValue); } unset($dataValue); return $dataSet; } + 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; + } + }