2013-04-25 16:53:29 +00:00
|
|
|
<?php
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
namespace PhpOffice\PhpSpreadsheetTests;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\ReferenceHelper;
|
2017-11-08 15:48:01 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2015-05-29 20:35:35 +00:00
|
|
|
|
2017-11-08 15:48:01 +00:00
|
|
|
class ReferenceHelperTest extends TestCase
|
2013-04-25 16:53:29 +00:00
|
|
|
{
|
2020-04-27 10:28:36 +00:00
|
|
|
protected function setUp(): void
|
2013-04-25 16:53:29 +00:00
|
|
|
{
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2013-04-25 16:53:29 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testColumnSort(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2015-05-29 20:35:35 +00:00
|
|
|
$columnBase = $columnExpectedResult = [
|
2016-08-16 15:33:57 +00:00
|
|
|
'A', 'B', 'Z',
|
|
|
|
'AA', 'AB', 'AZ',
|
|
|
|
'BA', 'BB', 'BZ',
|
|
|
|
'ZA', 'ZB', 'ZZ',
|
|
|
|
'AAA', 'AAB', 'AAZ',
|
|
|
|
'ABA', 'ABB', 'ABZ',
|
|
|
|
'AZA', 'AZB', 'AZZ',
|
|
|
|
'BAA', 'BAB', 'BAZ',
|
|
|
|
'BBA', 'BBB', 'BBZ',
|
|
|
|
'BZA', 'BZB', 'BZZ',
|
2015-05-29 20:35:35 +00:00
|
|
|
];
|
2015-05-17 13:00:02 +00:00
|
|
|
shuffle($columnBase);
|
2016-08-16 15:33:57 +00:00
|
|
|
usort($columnBase, [ReferenceHelper::class, 'columnSort']);
|
2015-05-17 13:00:02 +00:00
|
|
|
foreach ($columnBase as $key => $value) {
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($columnExpectedResult[$key], $value);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-25 16:53:29 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testColumnReverseSort(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2015-05-29 20:35:35 +00:00
|
|
|
$columnBase = $columnExpectedResult = [
|
2016-08-16 15:33:57 +00:00
|
|
|
'A', 'B', 'Z',
|
|
|
|
'AA', 'AB', 'AZ',
|
|
|
|
'BA', 'BB', 'BZ',
|
|
|
|
'ZA', 'ZB', 'ZZ',
|
|
|
|
'AAA', 'AAB', 'AAZ',
|
|
|
|
'ABA', 'ABB', 'ABZ',
|
|
|
|
'AZA', 'AZB', 'AZZ',
|
|
|
|
'BAA', 'BAB', 'BAZ',
|
|
|
|
'BBA', 'BBB', 'BBZ',
|
|
|
|
'BZA', 'BZB', 'BZZ',
|
2015-05-29 20:35:35 +00:00
|
|
|
];
|
2015-05-17 13:00:02 +00:00
|
|
|
shuffle($columnBase);
|
|
|
|
$columnExpectedResult = array_reverse($columnExpectedResult);
|
2016-08-16 15:33:57 +00:00
|
|
|
usort($columnBase, [ReferenceHelper::class, 'columnReverseSort']);
|
2015-05-17 13:00:02 +00:00
|
|
|
foreach ($columnBase as $key => $value) {
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($columnExpectedResult[$key], $value);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-02 18:08:36 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testCellSort(): void
|
2019-10-02 18:08:36 +00:00
|
|
|
{
|
|
|
|
$cellBase = $columnExpectedResult = [
|
|
|
|
'A1', 'B1', 'AZB1',
|
|
|
|
'BBB1', 'BB2', 'BAB2',
|
|
|
|
'BZA2', 'Z3', 'AZA3',
|
|
|
|
'BZB3', 'AB5', 'AZ6',
|
|
|
|
'ABZ7', 'BA9', 'BZ9',
|
|
|
|
'AAA9', 'AAZ9', 'BA10',
|
|
|
|
'BZZ10', 'ZA11', 'AAB11',
|
|
|
|
'BBZ29', 'BAA32', 'ZZ43',
|
|
|
|
'AZZ43', 'BAZ67', 'ZB78',
|
|
|
|
'ABA121', 'ABB289', 'BBA544',
|
|
|
|
];
|
|
|
|
shuffle($cellBase);
|
|
|
|
usort($cellBase, [ReferenceHelper::class, 'cellSort']);
|
|
|
|
foreach ($cellBase as $key => $value) {
|
|
|
|
self::assertEquals($columnExpectedResult[$key], $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testCellReverseSort(): void
|
2019-10-02 18:08:36 +00:00
|
|
|
{
|
|
|
|
$cellBase = $columnExpectedResult = [
|
|
|
|
'BBA544', 'ABB289', 'ABA121',
|
|
|
|
'ZB78', 'BAZ67', 'AZZ43',
|
|
|
|
'ZZ43', 'BAA32', 'BBZ29',
|
|
|
|
'AAB11', 'ZA11', 'BZZ10',
|
|
|
|
'BA10', 'AAZ9', 'AAA9',
|
|
|
|
'BZ9', 'BA9', 'ABZ7',
|
|
|
|
'AZ6', 'AB5', 'BZB3',
|
|
|
|
'AZA3', 'Z3', 'BZA2',
|
|
|
|
'BAB2', 'BB2', 'BBB1',
|
|
|
|
'AZB1', 'B1', 'A1',
|
|
|
|
];
|
|
|
|
shuffle($cellBase);
|
|
|
|
usort($cellBase, [ReferenceHelper::class, 'cellReverseSort']);
|
|
|
|
foreach ($cellBase as $key => $value) {
|
|
|
|
self::assertEquals($columnExpectedResult[$key], $value);
|
|
|
|
}
|
|
|
|
}
|
2020-07-14 08:58:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerFormulaUpdates
|
|
|
|
*/
|
|
|
|
public function testUpdateFormula(string $formula, int $insertRows, int $insertColumns, string $worksheet, string $expectedResult): void
|
|
|
|
{
|
|
|
|
$referenceHelper = ReferenceHelper::getInstance();
|
|
|
|
|
|
|
|
$result = $referenceHelper->updateFormulaReferences($formula, 'A1', $insertRows, $insertColumns, $worksheet);
|
|
|
|
|
|
|
|
self::assertSame($expectedResult, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerFormulaUpdates(): array
|
|
|
|
{
|
|
|
|
return require 'tests/data/ReferenceHelperFormulaUpdates.php';
|
|
|
|
}
|
2013-04-25 16:53:29 +00:00
|
|
|
}
|