From e6ebb0facf7e6d5caf2faa0eb2f85ed1904520b3 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Sun, 24 Jun 2012 22:33:33 +0100 Subject: [PATCH] Unit tests for shared classes --- unitTests/PHPExcel/Shared/CodePageTest.php | 3 +- unitTests/PHPExcel/Shared/DateTest.php | 95 +++++++++++++++++++ unitTests/PHPExcel/Shared/StringTest.php | 3 +- .../Shared/DateTimeExcelToPHP1900.data | 15 +++ .../Shared/DateTimeExcelToPHP1904.data | 7 ++ .../Shared/DateTimeFormatCodes.data | 37 ++++++++ 6 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 unitTests/PHPExcel/Shared/DateTest.php create mode 100644 unitTests/rawTestData/Shared/DateTimeExcelToPHP1900.data create mode 100644 unitTests/rawTestData/Shared/DateTimeExcelToPHP1904.data create mode 100644 unitTests/rawTestData/Shared/DateTimeFormatCodes.data diff --git a/unitTests/PHPExcel/Shared/CodePageTest.php b/unitTests/PHPExcel/Shared/CodePageTest.php index 27c00c6..ae4aeec 100644 --- a/unitTests/PHPExcel/Shared/CodePageTest.php +++ b/unitTests/PHPExcel/Shared/CodePageTest.php @@ -8,8 +8,7 @@ class CodePageTest extends PHPUnit_Framework_TestCase public function setUp() { - if (!defined('PHPEXCEL_ROOT')) - { + if (!defined('PHPEXCEL_ROOT')) { define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); } require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); diff --git a/unitTests/PHPExcel/Shared/DateTest.php b/unitTests/PHPExcel/Shared/DateTest.php new file mode 100644 index 0000000..6ee3b95 --- /dev/null +++ b/unitTests/PHPExcel/Shared/DateTest.php @@ -0,0 +1,95 @@ +assertTrue($result); + } + } + + public function testSetExcelCalendarWithInvalidValue() + { + $unsupportedCalendar = '2012'; + $result = call_user_func(array('PHPExcel_Shared_Date','setExcelCalendar'),$unsupportedCalendar); + $this->assertFalse($result); + } + + /** + * @dataProvider providerDateTimeExcelToPHP1900 + */ + public function testDateTimeExcelToPHP1900() + { + $result = call_user_func( + array('PHPExcel_Shared_Date','setExcelCalendar'), + PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900 + ); + + $args = func_get_args(); + $expectedResult = array_pop($args); + $result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args); + $this->assertEquals($expectedResult, $result); + } + + public function providerDateTimeExcelToPHP1900() + { + return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900.data'); + } + + /** + * @dataProvider providerDateTimeExcelToPHP1904 + */ + public function testDateTimeExcelToPHP1904() + { + $result = call_user_func( + array('PHPExcel_Shared_Date','setExcelCalendar'), + PHPExcel_Shared_Date::CALENDAR_MAC_1904 + ); + + $args = func_get_args(); + $expectedResult = array_pop($args); + $result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args); + $this->assertEquals($expectedResult, $result); + } + + public function providerDateTimeExcelToPHP1904() + { + return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1904.data'); + } + + /** + * @dataProvider providerIsDateTimeFormatCode + */ + public function testIsDateTimeFormatCode() + { + $args = func_get_args(); + $expectedResult = array_pop($args); + $result = call_user_func_array(array('PHPExcel_Shared_Date','isDateTimeFormatCode'),$args); + $this->assertEquals($expectedResult, $result); + } + + public function providerIsDateTimeFormatCode() + { + return new testDataFileIterator('rawTestData/Shared/DateTimeFormatCodes.data'); + } + +} diff --git a/unitTests/PHPExcel/Shared/StringTest.php b/unitTests/PHPExcel/Shared/StringTest.php index ad32b8b..8f1d698 100644 --- a/unitTests/PHPExcel/Shared/StringTest.php +++ b/unitTests/PHPExcel/Shared/StringTest.php @@ -8,8 +8,7 @@ class StringTest extends PHPUnit_Framework_TestCase public function setUp() { - if (!defined('PHPEXCEL_ROOT')) - { + if (!defined('PHPEXCEL_ROOT')) { define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); } require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); diff --git a/unitTests/rawTestData/Shared/DateTimeExcelToPHP1900.data b/unitTests/rawTestData/Shared/DateTimeExcelToPHP1900.data new file mode 100644 index 0000000..85497b8 --- /dev/null +++ b/unitTests/rawTestData/Shared/DateTimeExcelToPHP1900.data @@ -0,0 +1,15 @@ +#Excel DateTimeStamp Result Comments +714, -2147472000 // PHP 32-bit Earliest Date 14-Dec-1901 +1461, -2082931200 // 31-Dec-1903 +1462, -2082844800 // Excel 1904 Calendar Base Date 01-Jan-1904 +1463, -2082758400 // 02-Jan-1904 +22269, -285120000 // 19-Dec-1960 +25569, 0 // PHP Base Date 01-Jan-1970 +30292, 408067200 // 07-Dec-1982 +39611, 1213228800 // 12-Jun-2008 +50424, 2147472000 // PHP 32-bit Latest Date 19-Jan-2038 +1234.56789, -2102494934 // 18-May-1903 13:37:46 +12345.6789, -1142494943 // 18-Oct-1933 16:17:37 +0.5, 1340539200 // 12:00:00 +0.75, 1340560800 // 18:00.00 +0.12345, 1340506666 // 02:57:46 diff --git a/unitTests/rawTestData/Shared/DateTimeExcelToPHP1904.data b/unitTests/rawTestData/Shared/DateTimeExcelToPHP1904.data new file mode 100644 index 0000000..b30cff3 --- /dev/null +++ b/unitTests/rawTestData/Shared/DateTimeExcelToPHP1904.data @@ -0,0 +1,7 @@ +#Excel DateTimeStamp Result +1462, -1956528000 +1463, -1956441600 +22269, -158803200 +25569, 126316800 +30292, 534384000 +39611, 1339545600 diff --git a/unitTests/rawTestData/Shared/DateTimeFormatCodes.data b/unitTests/rawTestData/Shared/DateTimeFormatCodes.data new file mode 100644 index 0000000..7342047 --- /dev/null +++ b/unitTests/rawTestData/Shared/DateTimeFormatCodes.data @@ -0,0 +1,37 @@ +#Excel Format Code Result +"General", FALSE +"@", FALSE +"0", FALSE +"0.00", FALSE +"#,##0.00", FALSE +"#,##0.00_-", FALSE +"0%", FALSE +"0.00%", FALSE +"yyyy-mm-dd", TRUE +"yy-mm-dd", TRUE +"dd/mm/yy", TRUE +"d/m/y", TRUE +"d-m-y", TRUE +"d-m", TRUE +"m-y", TRUE +"mm-dd-yy", TRUE +"d-mmm-yy", TRUE +"d-mmm", TRUE +"mmm-yy", TRUE +"m/d/yy h:mm", TRUE +"d/m/y h:mm", TRUE +"h:mm AM/PM", TRUE +"h:mm:ss AM/PM", TRUE +"h:mm", TRUE +"h:mm:ss", TRUE +"mm:ss", TRUE +"h:mm:ss", TRUE +"i:s.S", TRUE +"h:mm:ss;@", TRUE +"yy/mm/dd;@", TRUE +"\"$\"#,##0.00_-", FALSE +"$#,##0_-", FALSE +"[$EUR ]#,##0.00_-", FALSE +"_[$EUR ]#,##0.00_-", FALSE +"[Green]#,##0.00;[Red]#,##0.00_-", FALSE +"#,##0.00 \"dollars\"", FALSE