Skip to content

Commit b89968d

Browse files
author
Mark Baker
authored
Additional Unit Tests (#1582)
1 parent 8712fb0 commit b89968d

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

tests/PhpSpreadsheetTests/ReferenceHelperTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,21 @@ public function testCellReverseSort(): void
9595
self::assertEquals($columnExpectedResult[$key], $value);
9696
}
9797
}
98+
99+
/**
100+
* @dataProvider providerFormulaUpdates
101+
*/
102+
public function testUpdateFormula(string $formula, int $insertRows, int $insertColumns, string $worksheet, string $expectedResult): void
103+
{
104+
$referenceHelper = ReferenceHelper::getInstance();
105+
106+
$result = $referenceHelper->updateFormulaReferences($formula, 'A1', $insertRows, $insertColumns, $worksheet);
107+
108+
self::assertSame($expectedResult, $result);
109+
}
110+
111+
public function providerFormulaUpdates(): array
112+
{
113+
return require 'tests/data/ReferenceHelperFormulaUpdates.php';
114+
}
98115
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
return [
4+
[
5+
'=SUM(C3:E5)',
6+
-2,
7+
-2,
8+
'2020',
9+
'=SUM(A1:C3)',
10+
],
11+
[
12+
'=SUM(2020!C3:E5,2019!C3:E5)',
13+
-2,
14+
-2,
15+
'2020',
16+
'=SUM(2020!A1:C3,2019!C3:E5)',
17+
],
18+
[
19+
'=SUM(2020!3:5,2019!3:5)',
20+
-2,
21+
-2,
22+
'2020',
23+
'=SUM(2020!1:3,2019!3:5)',
24+
],
25+
[
26+
'=SUM(2020!C:E,2019!C:E)',
27+
-2,
28+
-2,
29+
'2020',
30+
'=SUM(2020!A:C,2019!C:E)',
31+
],
32+
[
33+
"=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B1)-1))",
34+
2,
35+
2,
36+
'2019',
37+
"=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B3)-1))",
38+
],
39+
[
40+
"=IF('2020'!B$1=\"\",\"-\",(('2020'!B$1/'2019'!B$1)-1))",
41+
2,
42+
2,
43+
'2019',
44+
"=IF('2020'!B\$1=\"\",\"-\",(('2020'!B\$1/'2019'!D\$1)-1))",
45+
],
46+
[
47+
"=IF('2020'!Z$1=\"\",\"-\",(('2020'!Z$1/'2019'!Z$1)-1))",
48+
2,
49+
2,
50+
'2019',
51+
"=IF('2020'!Z\$1=\"\",\"-\",(('2020'!Z\$1/'2019'!AB\$1)-1))",
52+
],
53+
[
54+
"=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B1)-1))",
55+
2,
56+
2,
57+
'2020',
58+
"=IF('2020'!\$B3=\"\",\"-\",(('2020'!\$B3/'2019'!\$B1)-1))",
59+
],
60+
[
61+
"=IF('2020'!B$1=\"\",\"-\",(('2020'!B$1/'2019'!B$1)-1))",
62+
2,
63+
2,
64+
'2020',
65+
"=IF('2020'!D\$1=\"\",\"-\",(('2020'!D\$1/'2019'!B\$1)-1))",
66+
],
67+
[
68+
"=IF('2020'!Z$1=\"\",\"-\",(('2020'!Z$1/'2019'!Z$1)-1))",
69+
2,
70+
2,
71+
'2020',
72+
"=IF('2020'!AB\$1=\"\",\"-\",(('2020'!AB\$1/'2019'!Z\$1)-1))",
73+
],
74+
];

0 commit comments

Comments
 (0)