PhpSpreadsheet/tests/PhpSpreadsheetTests/CellTest.php

304 lines
9.0 KiB
PHP
Raw Normal View History

<?php
namespace PhpSpreadsheetTests;
use PhpSpreadsheet\Cell;
use PhpSpreadsheet\Exception;
class CellTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerColumnString
*/
2015-05-17 13:00:02 +00:00
public function testColumnIndexFromString()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'columnIndexFromString'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerColumnString()
{
return require 'data/ColumnString.php';
2015-05-17 13:00:02 +00:00
}
public function testColumnIndexFromStringTooLong()
2015-05-17 13:00:02 +00:00
{
$cellAddress = 'ABCD';
try {
2016-08-26 06:05:40 +00:00
call_user_func([Cell::class, 'columnIndexFromString'], $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
2015-05-17 13:00:02 +00:00
$this->assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
2015-05-17 13:00:02 +00:00
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testColumnIndexFromStringTooShort()
2015-05-17 13:00:02 +00:00
{
$cellAddress = '';
try {
2016-08-26 06:05:40 +00:00
call_user_func([Cell::class, 'columnIndexFromString'], $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
2015-05-17 13:00:02 +00:00
$this->assertEquals($e->getMessage(), 'Column string index can not be empty');
2015-05-17 13:00:02 +00:00
return;
}
$this->fail('An expected exception has not been raised.');
}
/**
* @dataProvider providerColumnIndex
*/
2015-05-17 13:00:02 +00:00
public function testStringFromColumnIndex()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'stringFromColumnIndex'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerColumnIndex()
{
return require 'data/ColumnIndex.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerCoordinates
*/
2015-05-17 13:00:02 +00:00
public function testCoordinateFromString()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'coordinateFromString'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerCoordinates()
{
return require 'data/CellCoordinates.php';
2015-05-17 13:00:02 +00:00
}
public function testCoordinateFromStringWithRangeAddress()
2015-05-17 13:00:02 +00:00
{
$cellAddress = 'A1:AI2012';
try {
2016-08-26 06:05:40 +00:00
call_user_func([Cell::class, 'coordinateFromString'], $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
2015-05-17 13:00:02 +00:00
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
2015-05-17 13:00:02 +00:00
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testCoordinateFromStringWithEmptyAddress()
2015-05-17 13:00:02 +00:00
{
$cellAddress = '';
try {
2016-08-26 06:05:40 +00:00
call_user_func([Cell::class, 'coordinateFromString'], $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
2015-05-17 13:00:02 +00:00
$this->assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
2015-05-17 13:00:02 +00:00
return;
}
$this->fail('An expected exception has not been raised.');
}
public function testCoordinateFromStringWithInvalidAddress()
2015-05-17 13:00:02 +00:00
{
$cellAddress = 'AI';
try {
2016-08-26 06:05:40 +00:00
call_user_func([Cell::class, 'coordinateFromString'], $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Invalid cell coordinate ' . $cellAddress);
2015-05-17 13:00:02 +00:00
return;
}
$this->fail('An expected exception has not been raised.');
}
/**
* @dataProvider providerAbsoluteCoordinates
*/
2015-05-17 13:00:02 +00:00
public function testAbsoluteCoordinateFromString()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'absoluteCoordinate'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerAbsoluteCoordinates()
{
return require 'data/CellAbsoluteCoordinate.php';
2015-05-17 13:00:02 +00:00
}
public function testAbsoluteCoordinateFromStringWithRangeAddress()
2015-05-17 13:00:02 +00:00
{
$cellAddress = 'A1:AI2012';
try {
2016-08-26 06:05:40 +00:00
call_user_func([Cell::class, 'absoluteCoordinate'], $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
2015-05-17 13:00:02 +00:00
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
2015-05-17 13:00:02 +00:00
return;
}
$this->fail('An expected exception has not been raised.');
}
/**
* @dataProvider providerAbsoluteReferences
*/
2015-05-17 13:00:02 +00:00
public function testAbsoluteReferenceFromString()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'absoluteReference'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerAbsoluteReferences()
{
return require 'data/CellAbsoluteReference.php';
2015-05-17 13:00:02 +00:00
}
public function testAbsoluteReferenceFromStringWithRangeAddress()
2015-05-17 13:00:02 +00:00
{
$cellAddress = 'A1:AI2012';
try {
2016-08-26 06:05:40 +00:00
call_user_func([Cell::class, 'absoluteReference'], $cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
2015-05-17 13:00:02 +00:00
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
2015-05-17 13:00:02 +00:00
return;
}
$this->fail('An expected exception has not been raised.');
}
/**
* @dataProvider providerSplitRange
*/
2015-05-17 13:00:02 +00:00
public function testSplitRange()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'splitRange'], $args);
2015-05-17 13:00:02 +00:00
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 require 'data/CellSplitRange.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerBuildRange
*/
2015-05-17 13:00:02 +00:00
public function testBuildRange()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'buildRange'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerBuildRange()
{
return require 'data/CellBuildRange.php';
2015-05-17 13:00:02 +00:00
}
public function testBuildRangeInvalid()
2015-05-17 13:00:02 +00:00
{
$cellRange = '';
try {
2016-08-26 06:05:40 +00:00
call_user_func([Cell::class, 'buildRange'], $cellRange);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
2015-05-17 13:00:02 +00:00
$this->assertEquals($e->getMessage(), 'Range does not contain any information');
2015-05-17 13:00:02 +00:00
return;
}
$this->fail('An expected exception has not been raised.');
}
/**
* @dataProvider providerRangeBoundaries
*/
2015-05-17 13:00:02 +00:00
public function testRangeBoundaries()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'rangeBoundaries'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerRangeBoundaries()
{
return require 'data/CellRangeBoundaries.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerRangeDimension
*/
2015-05-17 13:00:02 +00:00
public function testRangeDimension()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'rangeDimension'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerRangeDimension()
{
return require 'data/CellRangeDimension.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerGetRangeBoundaries
*/
2015-05-17 13:00:02 +00:00
public function testGetRangeBoundaries()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'getRangeBoundaries'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerGetRangeBoundaries()
{
return require 'data/CellGetRangeBoundaries.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerExtractAllCellReferencesInRange
*/
2015-05-17 13:00:02 +00:00
public function testExtractAllCellReferencesInRange()
{
$args = func_get_args();
$expectedResult = array_pop($args);
$result = call_user_func_array([Cell::class, 'extractAllCellReferencesInRange'], $args);
2015-05-17 13:00:02 +00:00
$this->assertEquals($expectedResult, $result);
}
public function providerExtractAllCellReferencesInRange()
{
return require 'data/CellExtractAllCellReferencesInRange.php';
2015-05-17 13:00:02 +00:00
}
}