Unit tests for shared classes

This commit is contained in:
Mark Baker 2012-06-24 22:33:33 +01:00
parent 6285555c52
commit e6ebb0facf
6 changed files with 156 additions and 4 deletions

View File

@ -8,8 +8,7 @@ class CodePageTest extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
if (!defined('PHPEXCEL_ROOT')) if (!defined('PHPEXCEL_ROOT')) {
{
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');

View File

@ -0,0 +1,95 @@
<?php
require_once 'testDataFileIterator.php';
class DateTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
public function testSetExcelCalendar()
{
$calendarValues = array(
PHPExcel_Shared_Date::CALENDAR_MAC_1904,
PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900,
);
foreach($calendarValues as $calendarValue) {
$result = call_user_func(array('PHPExcel_Shared_Date','setExcelCalendar'),$calendarValue);
$this->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');
}
}

View File

@ -8,8 +8,7 @@ class StringTest extends PHPUnit_Framework_TestCase
public function setUp() public function setUp()
{ {
if (!defined('PHPEXCEL_ROOT')) if (!defined('PHPEXCEL_ROOT')) {
{
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/'); define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
} }
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');

View File

@ -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

View File

@ -0,0 +1,7 @@
#Excel DateTimeStamp Result
1462, -1956528000
1463, -1956441600
22269, -158803200
25569, 126316800
30292, 534384000
39611, 1339545600

View File

@ -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