PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/iGroup/PHPExcel
PHP | 188 lines | 139 code | 28 blank | 21 comment | 4 complexity | 2a9b93cfd74bc64fe8f2ab1375ecb653 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1
  1. <?php
  2. require_once 'testDataFileIterator.php';
  3. class DateTest extends PHPUnit_Framework_TestCase
  4. {
  5. public function setUp()
  6. {
  7. if (!defined('PHPEXCEL_ROOT')) {
  8. define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
  9. }
  10. require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  11. }
  12. public function testSetExcelCalendar()
  13. {
  14. $calendarValues = array(
  15. PHPExcel_Shared_Date::CALENDAR_MAC_1904,
  16. PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900,
  17. );
  18. foreach($calendarValues as $calendarValue) {
  19. $result = call_user_func(array('PHPExcel_Shared_Date','setExcelCalendar'),$calendarValue);
  20. $this->assertTrue($result);
  21. }
  22. }
  23. public function testSetExcelCalendarWithInvalidValue()
  24. {
  25. $unsupportedCalendar = '2012';
  26. $result = call_user_func(array('PHPExcel_Shared_Date','setExcelCalendar'),$unsupportedCalendar);
  27. $this->assertFalse($result);
  28. }
  29. /**
  30. * @dataProvider providerDateTimeExcelToPHP1900
  31. */
  32. public function testDateTimeExcelToPHP1900()
  33. {
  34. $result = call_user_func(
  35. array('PHPExcel_Shared_Date','setExcelCalendar'),
  36. PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
  37. );
  38. $args = func_get_args();
  39. $expectedResult = array_pop($args);
  40. if ($args[0] < 1) {
  41. $expectedResult += gmmktime(0,0,0);
  42. }
  43. $result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args);
  44. $this->assertEquals($expectedResult, $result);
  45. }
  46. public function providerDateTimeExcelToPHP1900()
  47. {
  48. return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900.data');
  49. }
  50. /**
  51. * @dataProvider providerDateTimePHPToExcel1900
  52. */
  53. public function testDateTimePHPToExcel1900()
  54. {
  55. $result = call_user_func(
  56. array('PHPExcel_Shared_Date','setExcelCalendar'),
  57. PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
  58. );
  59. $args = func_get_args();
  60. $expectedResult = array_pop($args);
  61. $result = call_user_func_array(array('PHPExcel_Shared_Date','PHPToExcel'),$args);
  62. $this->assertEquals($expectedResult, $result, NULL, 1E-5);
  63. }
  64. public function providerDateTimePHPToExcel1900()
  65. {
  66. return new testDataFileIterator('rawTestData/Shared/DateTimePHPToExcel1900.data');
  67. }
  68. /**
  69. * @dataProvider providerDateTimeFormattedPHPToExcel1900
  70. */
  71. public function testDateTimeFormattedPHPToExcel1900()
  72. {
  73. $result = call_user_func(
  74. array('PHPExcel_Shared_Date','setExcelCalendar'),
  75. PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
  76. );
  77. $args = func_get_args();
  78. $expectedResult = array_pop($args);
  79. $result = call_user_func_array(array('PHPExcel_Shared_Date','FormattedPHPToExcel'),$args);
  80. $this->assertEquals($expectedResult, $result, NULL, 1E-5);
  81. }
  82. public function providerDateTimeFormattedPHPToExcel1900()
  83. {
  84. return new testDataFileIterator('rawTestData/Shared/DateTimeFormattedPHPToExcel1900.data');
  85. }
  86. /**
  87. * @dataProvider providerDateTimeExcelToPHP1904
  88. */
  89. public function testDateTimeExcelToPHP1904()
  90. {
  91. $result = call_user_func(
  92. array('PHPExcel_Shared_Date','setExcelCalendar'),
  93. PHPExcel_Shared_Date::CALENDAR_MAC_1904
  94. );
  95. $args = func_get_args();
  96. $expectedResult = array_pop($args);
  97. if ($args[0] < 1) {
  98. $expectedResult += gmmktime(0,0,0);
  99. }
  100. $result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args);
  101. $this->assertEquals($expectedResult, $result);
  102. }
  103. public function providerDateTimeExcelToPHP1904()
  104. {
  105. return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1904.data');
  106. }
  107. /**
  108. * @dataProvider providerDateTimePHPToExcel1904
  109. */
  110. public function testDateTimePHPToExcel1904()
  111. {
  112. $result = call_user_func(
  113. array('PHPExcel_Shared_Date','setExcelCalendar'),
  114. PHPExcel_Shared_Date::CALENDAR_MAC_1904
  115. );
  116. $args = func_get_args();
  117. $expectedResult = array_pop($args);
  118. $result = call_user_func_array(array('PHPExcel_Shared_Date','PHPToExcel'),$args);
  119. $this->assertEquals($expectedResult, $result, NULL, 1E-5);
  120. }
  121. public function providerDateTimePHPToExcel1904()
  122. {
  123. return new testDataFileIterator('rawTestData/Shared/DateTimePHPToExcel1904.data');
  124. }
  125. /**
  126. * @dataProvider providerIsDateTimeFormatCode
  127. */
  128. public function testIsDateTimeFormatCode()
  129. {
  130. $args = func_get_args();
  131. $expectedResult = array_pop($args);
  132. $result = call_user_func_array(array('PHPExcel_Shared_Date','isDateTimeFormatCode'),$args);
  133. $this->assertEquals($expectedResult, $result);
  134. }
  135. public function providerIsDateTimeFormatCode()
  136. {
  137. return new testDataFileIterator('rawTestData/Shared/DateTimeFormatCodes.data');
  138. }
  139. /**
  140. * @dataProvider providerDateTimeExcelToPHP1900Timezone
  141. */
  142. public function testDateTimeExcelToPHP1900Timezone()
  143. {
  144. $result = call_user_func(
  145. array('PHPExcel_Shared_Date','setExcelCalendar'),
  146. PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900
  147. );
  148. $args = func_get_args();
  149. $expectedResult = array_pop($args);
  150. if ($args[0] < 1) {
  151. $expectedResult += gmmktime(0,0,0);
  152. }
  153. $result = call_user_func_array(array('PHPExcel_Shared_Date','ExcelToPHP'),$args);
  154. $this->assertEquals($expectedResult, $result);
  155. }
  156. public function providerDateTimeExcelToPHP1900Timezone()
  157. {
  158. return new testDataFileIterator('rawTestData/Shared/DateTimeExcelToPHP1900Timezone.data');
  159. }
  160. }