123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- <?php
- require_once 'testDataFileIterator.php';
- class CellTest extends PHPUnit_Framework_TestCase
- {
- public function setUp()
- {
- if (!defined('PHPEXCEL_ROOT')) {
- define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
- }
- require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
- }
- /**
- * @dataProvider providerColumnString
- */
- public function testColumnIndexFromString()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','columnIndexFromString'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerColumnString()
- {
- return new testDataFileIterator('rawTestData/ColumnString.data');
- }
- public function testColumnIndexFromStringTooLong()
- {
- $cellAddress = 'ABCD';
- try {
- $result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'),$cellAddress);
- } catch (PHPExcel_Exception $e) {
- $this->assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
- return;
- }
- $this->fail('An expected exception has not been raised.');
- }
- public function testColumnIndexFromStringTooShort()
- {
- $cellAddress = '';
- try {
- $result = call_user_func(array('PHPExcel_Cell','columnIndexFromString'),$cellAddress);
- } catch (PHPExcel_Exception $e) {
- $this->assertEquals($e->getMessage(), 'Column string index can not be empty');
- return;
- }
- $this->fail('An expected exception has not been raised.');
- }
- /**
- * @dataProvider providerColumnIndex
- */
- public function testStringFromColumnIndex()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','stringFromColumnIndex'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerColumnIndex()
- {
- return new testDataFileIterator('rawTestData/ColumnIndex.data');
- }
- /**
- * @dataProvider providerCoordinates
- */
- public function testCoordinateFromString()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','coordinateFromString'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerCoordinates()
- {
- return new testDataFileIterator('rawTestData/CellCoordinates.data');
- }
- public function testCoordinateFromStringWithRangeAddress()
- {
- $cellAddress = 'A1:AI2012';
- try {
- $result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
- } catch (PHPExcel_Exception $e) {
- $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
- return;
- }
- $this->fail('An expected exception has not been raised.');
- }
- public function testCoordinateFromStringWithEmptyAddress()
- {
- $cellAddress = '';
- try {
- $result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
- } catch (PHPExcel_Exception $e) {
- $this->assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
- return;
- }
- $this->fail('An expected exception has not been raised.');
- }
- public function testCoordinateFromStringWithInvalidAddress()
- {
- $cellAddress = 'AI';
- try {
- $result = call_user_func(array('PHPExcel_Cell','coordinateFromString'),$cellAddress);
- } catch (PHPExcel_Exception $e) {
- $this->assertEquals($e->getMessage(), 'Invalid cell coordinate '.$cellAddress);
- return;
- }
- $this->fail('An expected exception has not been raised.');
- }
- /**
- * @dataProvider providerAbsoluteCoordinates
- */
- public function testAbsoluteCoordinateFromString()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','absoluteCoordinate'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerAbsoluteCoordinates()
- {
- return new testDataFileIterator('rawTestData/CellAbsoluteCoordinate.data');
- }
- public function testAbsoluteCoordinateFromStringWithRangeAddress()
- {
- $cellAddress = 'A1:AI2012';
- try {
- $result = call_user_func(array('PHPExcel_Cell','absoluteCoordinate'),$cellAddress);
- } catch (PHPExcel_Exception $e) {
- $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
- return;
- }
- $this->fail('An expected exception has not been raised.');
- }
- /**
- * @dataProvider providerAbsoluteReferences
- */
- public function testAbsoluteReferenceFromString()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','absoluteReference'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerAbsoluteReferences()
- {
- return new testDataFileIterator('rawTestData/CellAbsoluteReference.data');
- }
- public function testAbsoluteReferenceFromStringWithRangeAddress()
- {
- $cellAddress = 'A1:AI2012';
- try {
- $result = call_user_func(array('PHPExcel_Cell','absoluteReference'),$cellAddress);
- } catch (PHPExcel_Exception $e) {
- $this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
- return;
- }
- $this->fail('An expected exception has not been raised.');
- }
- /**
- * @dataProvider providerSplitRange
- */
- public function testSplitRange()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','splitRange'),$args);
- foreach($result as $key => $split) {
- if (!is_array($expectedResult[$key])) {
- $this->assertEquals($expectedResult[$key], $split[0]);
- } else {
- $this->assertEquals($expectedResult[$key], $split);
- }
- }
- }
- public function providerSplitRange()
- {
- return new testDataFileIterator('rawTestData/CellSplitRange.data');
- }
- /**
- * @dataProvider providerBuildRange
- */
- public function testBuildRange()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','buildRange'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerBuildRange()
- {
- return new testDataFileIterator('rawTestData/CellBuildRange.data');
- }
- public function testBuildRangeInvalid()
- {
- $cellRange = '';
- try {
- $result = call_user_func(array('PHPExcel_Cell','buildRange'),$cellRange);
- } catch (PHPExcel_Exception $e) {
- $this->assertEquals($e->getMessage(), 'Range does not contain any information');
- return;
- }
- $this->fail('An expected exception has not been raised.');
- }
- /**
- * @dataProvider providerRangeBoundaries
- */
- public function testRangeBoundaries()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','rangeBoundaries'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerRangeBoundaries()
- {
- return new testDataFileIterator('rawTestData/CellRangeBoundaries.data');
- }
- /**
- * @dataProvider providerRangeDimension
- */
- public function testRangeDimension()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','rangeDimension'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerRangeDimension()
- {
- return new testDataFileIterator('rawTestData/CellRangeDimension.data');
- }
- /**
- * @dataProvider providerGetRangeBoundaries
- */
- public function testGetRangeBoundaries()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','getRangeBoundaries'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerGetRangeBoundaries()
- {
- return new testDataFileIterator('rawTestData/CellGetRangeBoundaries.data');
- }
- /**
- * @dataProvider providerExtractAllCellReferencesInRange
- */
- public function testExtractAllCellReferencesInRange()
- {
- $args = func_get_args();
- $expectedResult = array_pop($args);
- $result = call_user_func_array(array('PHPExcel_Cell','extractAllCellReferencesInRange'),$args);
- $this->assertEquals($expectedResult, $result);
- }
- public function providerExtractAllCellReferencesInRange()
- {
- return new testDataFileIterator('rawTestData/CellExtractAllCellReferencesInRange.data');
- }
- }
|