mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-25 14:56:04 +03:00
Unit tests for shared classes
This commit is contained in:
parent
6285555c52
commit
e6ebb0facf
@ -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');
|
||||
|
95
unitTests/PHPExcel/Shared/DateTest.php
Normal file
95
unitTests/PHPExcel/Shared/DateTest.php
Normal 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');
|
||||
}
|
||||
|
||||
}
|
@ -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');
|
||||
|
15
unitTests/rawTestData/Shared/DateTimeExcelToPHP1900.data
Normal file
15
unitTests/rawTestData/Shared/DateTimeExcelToPHP1900.data
Normal 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
|
7
unitTests/rawTestData/Shared/DateTimeExcelToPHP1904.data
Normal file
7
unitTests/rawTestData/Shared/DateTimeExcelToPHP1904.data
Normal file
@ -0,0 +1,7 @@
|
||||
#Excel DateTimeStamp Result
|
||||
1462, -1956528000
|
||||
1463, -1956441600
|
||||
22269, -158803200
|
||||
25569, 126316800
|
||||
30292, 534384000
|
||||
39611, 1339545600
|
37
unitTests/rawTestData/Shared/DateTimeFormatCodes.data
Normal file
37
unitTests/rawTestData/Shared/DateTimeFormatCodes.data
Normal 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
|
Loading…
Reference in New Issue
Block a user