PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/unitTests/Classes/PHPExcel/CellTest.php

https://github.com/iGroup/PHPExcel
PHP | 295 lines | 227 code | 35 blank | 33 comment | 3 complexity | 3760c5950cc6c6a863ade9e34d547a6c MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1
  1. <?php
  2. require_once 'testDataFileIterator.php';
  3. class CellTest 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. /**
  13. * @dataProvider providerColumnString
  14. */
  15. public function testColumnIndexFromString()
  16. {
  17. $args = func_get_args();
  18. $expectedResult = array_pop($args);
  19. $result = call_user_func_array(array('PHPExcel_Cell','columnIndexFromString'),$args);
  20. $this->assertEquals($expectedResult, $result);
  21. }
  22. public function providerColumnString()
  23. {
  24. return new testDataFileIterator('rawTestData/ColumnString.data');
  25. }
  26. public function testColumnIndexFromStringTooLong()
  27. {
  28. $cellAddress = 'ABCD';
  29. try {
  30. $result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'),$cellAddress);
  31. } catch (PHPExcel_Exception $e) {
  32. $this->assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
  33. return;
  34. }
  35. $this->fail('An expected exception has not been raised.');
  36. }
  37. public function testColumnIndexFromStringTooShort()
  38. {
  39. $cellAddress = '';
  40. try {
  41. $result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'),$cellAddress);
  42. } catch (PHPExcel_Exception $e) {
  43. $this->assertEquals($e->getMessage(), 'Column string index can not be empty');
  44. return;
  45. }
  46. $this->fail('An expected exception has not been raised.');
  47. }
  48. /**
  49. * @dataProvider providerColumnIndex
  50. */
  51. public function testStringFromColumnIndex()
  52. {
  53. $args = func_get_args();
  54. $expectedResult = array_pop($args);
  55. $result = call_user_func_array(array('PHPExcel_Cell','stringFromColumnIndex'),$args);
  56. $this->assertEquals($expectedResult, $result);
  57. }
  58. public function providerColumnIndex()
  59. {
  60. return new testDataFileIterator('rawTestData/ColumnIndex.data');
  61. }
  62. /**
  63. * @dataProvider providerCoordinates
  64. */
  65. public function testCoordinateFromString()
  66. {
  67. $args = func_get_args();
  68. $expectedResult = array_pop($args);
  69. $result = call_user_func_array(array('PHPExcel_Cell','coordinateFromString'),$args);
  70. $this->assertEquals($expectedResult, $result);
  71. }
  72. public function providerCoordinates()
  73. {
  74. return new testDataFileIterator('rawTestData/CellCoordinates.data');
  75. }
  76. public function testCoordinateFromStringWithRangeAddress()
  77. {
  78. $cellAddress = 'A1:AI2012';
  79. try {
  80. $result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
  81. } catch (PHPExcel_Exception $e) {
  82. $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
  83. return;
  84. }
  85. $this->fail('An expected exception has not been raised.');
  86. }
  87. public function testCoordinateFromStringWithEmptyAddress()
  88. {
  89. $cellAddress = '';
  90. try {
  91. $result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
  92. } catch (PHPExcel_Exception $e) {
  93. $this->assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
  94. return;
  95. }
  96. $this->fail('An expected exception has not been raised.');
  97. }
  98. public function testCoordinateFromStringWithInvalidAddress()
  99. {
  100. $cellAddress = 'AI';
  101. try {
  102. $result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
  103. } catch (PHPExcel_Exception $e) {
  104. $this->assertEquals($e->getMessage(), 'Invalid cell coordinate '.$cellAddress);
  105. return;
  106. }
  107. $this->fail('An expected exception has not been raised.');
  108. }
  109. /**
  110. * @dataProvider providerAbsoluteCoordinates
  111. */
  112. public function testAbsoluteCoordinateFromString()
  113. {
  114. $args = func_get_args();
  115. $expectedResult = array_pop($args);
  116. $result = call_user_func_array(array('PHPExcel_Cell','absoluteCoordinate'),$args);
  117. $this->assertEquals($expectedResult, $result);
  118. }
  119. public function providerAbsoluteCoordinates()
  120. {
  121. return new testDataFileIterator('rawTestData/CellAbsoluteCoordinate.data');
  122. }
  123. public function testAbsoluteCoordinateFromStringWithRangeAddress()
  124. {
  125. $cellAddress = 'A1:AI2012';
  126. try {
  127. $result = call_user_func(array('PHPExcel_Cell','absoluteCoordinate'),$cellAddress);
  128. } catch (PHPExcel_Exception $e) {
  129. $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
  130. return;
  131. }
  132. $this->fail('An expected exception has not been raised.');
  133. }
  134. /**
  135. * @dataProvider providerAbsoluteReferences
  136. */
  137. public function testAbsoluteReferenceFromString()
  138. {
  139. $args = func_get_args();
  140. $expectedResult = array_pop($args);
  141. $result = call_user_func_array(array('PHPExcel_Cell','absoluteReference'),$args);
  142. $this->assertEquals($expectedResult, $result);
  143. }
  144. public function providerAbsoluteReferences()
  145. {
  146. return new testDataFileIterator('rawTestData/CellAbsoluteReference.data');
  147. }
  148. public function testAbsoluteReferenceFromStringWithRangeAddress()
  149. {
  150. $cellAddress = 'A1:AI2012';
  151. try {
  152. $result = call_user_func(array('PHPExcel_Cell','absoluteReference'),$cellAddress);
  153. } catch (PHPExcel_Exception $e) {
  154. $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
  155. return;
  156. }
  157. $this->fail('An expected exception has not been raised.');
  158. }
  159. /**
  160. * @dataProvider providerSplitRange
  161. */
  162. public function testSplitRange()
  163. {
  164. $args = func_get_args();
  165. $expectedResult = array_pop($args);
  166. $result = call_user_func_array(array('PHPExcel_Cell','splitRange'),$args);
  167. foreach($result as $key => $split) {
  168. if (!is_array($expectedResult[$key])) {
  169. $this->assertEquals($expectedResult[$key], $split[0]);
  170. } else {
  171. $this->assertEquals($expectedResult[$key], $split);
  172. }
  173. }
  174. }
  175. public function providerSplitRange()
  176. {
  177. return new testDataFileIterator('rawTestData/CellSplitRange.data');
  178. }
  179. /**
  180. * @dataProvider providerBuildRange
  181. */
  182. public function testBuildRange()
  183. {
  184. $args = func_get_args();
  185. $expectedResult = array_pop($args);
  186. $result = call_user_func_array(array('PHPExcel_Cell','buildRange'),$args);
  187. $this->assertEquals($expectedResult, $result);
  188. }
  189. public function providerBuildRange()
  190. {
  191. return new testDataFileIterator('rawTestData/CellBuildRange.data');
  192. }
  193. public function testBuildRangeInvalid()
  194. {
  195. $cellRange = '';
  196. try {
  197. $result = call_user_func(array('PHPExcel_Cell','buildRange'),$cellRange);
  198. } catch (PHPExcel_Exception $e) {
  199. $this->assertEquals($e->getMessage(), 'Range does not contain any information');
  200. return;
  201. }
  202. $this->fail('An expected exception has not been raised.');
  203. }
  204. /**
  205. * @dataProvider providerRangeBoundaries
  206. */
  207. public function testRangeBoundaries()
  208. {
  209. $args = func_get_args();
  210. $expectedResult = array_pop($args);
  211. $result = call_user_func_array(array('PHPExcel_Cell','rangeBoundaries'),$args);
  212. $this->assertEquals($expectedResult, $result);
  213. }
  214. public function providerRangeBoundaries()
  215. {
  216. return new testDataFileIterator('rawTestData/CellRangeBoundaries.data');
  217. }
  218. /**
  219. * @dataProvider providerRangeDimension
  220. */
  221. public function testRangeDimension()
  222. {
  223. $args = func_get_args();
  224. $expectedResult = array_pop($args);
  225. $result = call_user_func_array(array('PHPExcel_Cell','rangeDimension'),$args);
  226. $this->assertEquals($expectedResult, $result);
  227. }
  228. public function providerRangeDimension()
  229. {
  230. return new testDataFileIterator('rawTestData/CellRangeDimension.data');
  231. }
  232. /**
  233. * @dataProvider providerGetRangeBoundaries
  234. */
  235. public function testGetRangeBoundaries()
  236. {
  237. $args = func_get_args();
  238. $expectedResult = array_pop($args);
  239. $result = call_user_func_array(array('PHPExcel_Cell','getRangeBoundaries'),$args);
  240. $this->assertEquals($expectedResult, $result);
  241. }
  242. public function providerGetRangeBoundaries()
  243. {
  244. return new testDataFileIterator('rawTestData/CellGetRangeBoundaries.data');
  245. }
  246. /**
  247. * @dataProvider providerExtractAllCellReferencesInRange
  248. */
  249. public function testExtractAllCellReferencesInRange()
  250. {
  251. $args = func_get_args();
  252. $expectedResult = array_pop($args);
  253. $result = call_user_func_array(array('PHPExcel_Cell','extractAllCellReferencesInRange'),$args);
  254. $this->assertEquals($expectedResult, $result);
  255. }
  256. public function providerExtractAllCellReferencesInRange()
  257. {
  258. return new testDataFileIterator('rawTestData/CellExtractAllCellReferencesInRange.data');
  259. }
  260. }