Skip to content

Commit

Permalink
Additional Unit Tests (#1582)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Baker authored Jul 14, 2020
1 parent 8712fb0 commit b89968d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/PhpSpreadsheetTests/ReferenceHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,21 @@ public function testCellReverseSort(): void
self::assertEquals($columnExpectedResult[$key], $value);
}
}

/**
* @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';
}
}
74 changes: 74 additions & 0 deletions tests/data/ReferenceHelperFormulaUpdates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

return [
[
'=SUM(C3:E5)',
-2,
-2,
'2020',
'=SUM(A1:C3)',
],
[
'=SUM(2020!C3:E5,2019!C3:E5)',
-2,
-2,
'2020',
'=SUM(2020!A1:C3,2019!C3:E5)',
],
[
'=SUM(2020!3:5,2019!3:5)',
-2,
-2,
'2020',
'=SUM(2020!1:3,2019!3:5)',
],
[
'=SUM(2020!C:E,2019!C:E)',
-2,
-2,
'2020',
'=SUM(2020!A:C,2019!C:E)',
],
[
"=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B1)-1))",
2,
2,
'2019',
"=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B3)-1))",
],
[
"=IF('2020'!B$1=\"\",\"-\",(('2020'!B$1/'2019'!B$1)-1))",
2,
2,
'2019',
"=IF('2020'!B\$1=\"\",\"-\",(('2020'!B\$1/'2019'!D\$1)-1))",
],
[
"=IF('2020'!Z$1=\"\",\"-\",(('2020'!Z$1/'2019'!Z$1)-1))",
2,
2,
'2019',
"=IF('2020'!Z\$1=\"\",\"-\",(('2020'!Z\$1/'2019'!AB\$1)-1))",
],
[
"=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B1)-1))",
2,
2,
'2020',
"=IF('2020'!\$B3=\"\",\"-\",(('2020'!\$B3/'2019'!\$B1)-1))",
],
[
"=IF('2020'!B$1=\"\",\"-\",(('2020'!B$1/'2019'!B$1)-1))",
2,
2,
'2020',
"=IF('2020'!D\$1=\"\",\"-\",(('2020'!D\$1/'2019'!B\$1)-1))",
],
[
"=IF('2020'!Z$1=\"\",\"-\",(('2020'!Z$1/'2019'!Z$1)-1))",
2,
2,
'2020',
"=IF('2020'!AB\$1=\"\",\"-\",(('2020'!AB\$1/'2019'!Z\$1)-1))",
],
];

0 comments on commit b89968d

Please sign in to comment.