PhpSpreadsheet/unitTests/Classes/PHPExcel/Shared/DateTest.php

188 lines
5.8 KiB
PHP
Raw Normal View History

2012-06-24 21:33:33 +00:00
<?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');
2015-05-17 13:00:02 +00:00
}
2012-06-24 21:33:33 +00:00
2015-05-17 13:00:02 +00:00
public function testSetExcelCalendar()
{
$calendarValues = array(
PHPExcel_Shared_Date::CALENDAR_MAC_1904,
PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900,
);
foreach ($calendarValues as $calendarValue) {
2015-05-17 16:34:30 +00:00
$result = call_user_func(array('PHPExcel_Shared_Date','setExcelCalendar'), $calendarValue);
2015-05-17 13:00:02 +00:00
$this->assertTrue($result);
}
}
2012-06-24 21:33:33 +00:00
public function testSetExcelCalendarWithInvalidValue()
2015-05-17 13:00:02 +00:00
{
$unsupportedCalendar = '2012';
2015-05-17 16:34:30 +00:00
$result = call_user_func(array('PHPExcel_Shared_Date','setExcelCalendar'), $unsupportedCalendar);
2015-05-17 13:00:02 +00:00
$this->assertFalse($result);
}
2012-06-24 21:33:33 +00:00
/**
* @dataProvider providerDateTimeExcelToPHP1900
*/
2015-05-17 13:00:02 +00:00
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);
if ($args[0] < 1) {
2015-05-17 17:26:34 +00:00
$expectedResult += gmmktime(0, 0, 0);
2015-05-17 13:00:02 +00:00
}
2015-05-17 17:26:34 +00:00
$result = call_user_func_array(array('PHPExcel_Shared_Date', 'ExcelToPHP'), $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
2012-06-24 21:33:33 +00:00
public function providerDateTimeExcelToPHP1900()
{
2015-05-17 13:00:02 +00:00
return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900.data');
}
2012-06-24 21:33:33 +00:00
2012-07-24 12:21:31 +00:00
/**
* @dataProvider providerDateTimePHPToExcel1900
*/
2015-05-17 13:00:02 +00:00
public function testDateTimePHPToExcel1900()
{
$result = call_user_func(
array('PHPExcel_Shared_Date','setExcelCalendar'),
PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
);
$args = func_get_args();
$expectedResult = array_pop($args);
2015-05-17 16:34:30 +00:00
$result = call_user_func_array(array('PHPExcel_Shared_Date','PHPToExcel'), $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result, null, 1E-5);
}
2012-07-24 12:21:31 +00:00
public function providerDateTimePHPToExcel1900()
{
2015-05-17 13:00:02 +00:00
return new testDataFileIterator('rawTestData/Shared/DateTimePHPToExcel1900.data');
}
2012-07-24 12:21:31 +00:00
/**
* @dataProvider providerDateTimeFormattedPHPToExcel1900
*/
2015-05-17 13:00:02 +00:00
public function testDateTimeFormattedPHPToExcel1900()
{
$result = call_user_func(
array('PHPExcel_Shared_Date','setExcelCalendar'),
PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
);
$args = func_get_args();
$expectedResult = array_pop($args);
2015-05-17 16:34:30 +00:00
$result = call_user_func_array(array('PHPExcel_Shared_Date','FormattedPHPToExcel'), $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result, null, 1E-5);
}
2012-07-24 12:21:31 +00:00
public function providerDateTimeFormattedPHPToExcel1900()
{
2015-05-17 13:00:02 +00:00
return new testDataFileIterator('rawTestData/Shared/DateTimeFormattedPHPToExcel1900.data');
}
2012-07-24 12:21:31 +00:00
2012-06-24 21:33:33 +00:00
/**
* @dataProvider providerDateTimeExcelToPHP1904
*/
2015-05-17 13:00:02 +00:00
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);
if ($args[0] < 1) {
2015-05-17 17:26:34 +00:00
$expectedResult += gmmktime(0, 0, 0);
2015-05-17 13:00:02 +00:00
}
2015-05-17 16:34:30 +00:00
$result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'), $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
2012-06-24 21:33:33 +00:00
public function providerDateTimeExcelToPHP1904()
{
2015-05-17 13:00:02 +00:00
return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1904.data');
}
2012-06-24 21:33:33 +00:00
2012-07-24 12:21:31 +00:00
/**
* @dataProvider providerDateTimePHPToExcel1904
*/
2015-05-17 13:00:02 +00:00
public function testDateTimePHPToExcel1904()
{
$result = call_user_func(
array('PHPExcel_Shared_Date','setExcelCalendar'),
PHPExcel_Shared_Date::CALENDAR_MAC_1904
);
$args = func_get_args();
$expectedResult = array_pop($args);
2015-05-17 16:34:30 +00:00
$result = call_user_func_array(array('PHPExcel_Shared_Date','PHPToExcel'), $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result, null, 1E-5);
}
2012-07-24 12:21:31 +00:00
public function providerDateTimePHPToExcel1904()
{
2015-05-17 13:00:02 +00:00
return new testDataFileIterator('rawTestData/Shared/DateTimePHPToExcel1904.data');
}
2012-07-24 12:21:31 +00:00
2012-06-24 21:33:33 +00:00
/**
* @dataProvider providerIsDateTimeFormatCode
*/
2015-05-17 13:00:02 +00:00
public function testIsDateTimeFormatCode()
{
$args = func_get_args();
$expectedResult = array_pop($args);
2015-05-17 16:34:30 +00:00
$result = call_user_func_array(array('PHPExcel_Shared_Date','isDateTimeFormatCode'), $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
2012-06-24 21:33:33 +00:00
public function providerIsDateTimeFormatCode()
{
2015-05-17 13:00:02 +00:00
return new testDataFileIterator('rawTestData/Shared/DateTimeFormatCodes.data');
}
2012-06-24 21:33:33 +00:00
/**
* @dataProvider providerDateTimeExcelToPHP1900Timezone
*/
2015-05-17 13:00:02 +00:00
public function testDateTimeExcelToPHP1900Timezone()
{
$result = call_user_func(
array('PHPExcel_Shared_Date','setExcelCalendar'),
PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
);
$args = func_get_args();
$expectedResult = array_pop($args);
if ($args[0] < 1) {
2015-05-17 17:26:34 +00:00
$expectedResult += gmmktime(0, 0, 0);
2015-05-17 13:00:02 +00:00
}
2015-05-17 16:34:30 +00:00
$result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'), $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerDateTimeExcelToPHP1900Timezone()
{
2015-05-17 13:00:02 +00:00
return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900Timezone.data');
}
2012-06-24 21:33:33 +00:00
}