Basic unit testing for 100 series actions for SUBTOTAL() with hidden rows/columns
This commit is contained in:
parent
1ece540254
commit
04b4e74ec7
|
@ -1073,7 +1073,6 @@ class MathTrig
|
||||||
$args,
|
$args,
|
||||||
function ($index) use ($cellReference) {
|
function ($index) use ($cellReference) {
|
||||||
list(, $row, $column) = explode('.', $index);
|
list(, $row, $column) = explode('.', $index);
|
||||||
|
|
||||||
return $cellReference->getWorksheet()->getRowDimension($row)->getVisible() &&
|
return $cellReference->getWorksheet()->getRowDimension($row)->getVisible() &&
|
||||||
$cellReference->getWorksheet()->getColumnDimension($column)->getVisible();
|
$cellReference->getWorksheet()->getColumnDimension($column)->getVisible();
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,6 +5,10 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\RowDimension;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnDimension;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class MathTrigTest extends TestCase
|
class MathTrigTest extends TestCase
|
||||||
|
@ -507,8 +511,26 @@ class MathTrigTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testSUBTOTAL($expectedResult, ...$args)
|
public function testSUBTOTAL($expectedResult, ...$args)
|
||||||
{
|
{
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$cell = $this->getMockBuilder(Cell::class)
|
||||||
$cellReference = $spreadsheet->getActiveSheet()->getCell('A1');
|
->setMethods(['getValue'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$cell->method('getValue')
|
||||||
|
->willReturn(null);
|
||||||
|
$worksheet = $this->getMockBuilder(Worksheet::class)
|
||||||
|
->setMethods(['cellExists', 'getCell'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$worksheet->method('cellExists')
|
||||||
|
->willReturn(true);
|
||||||
|
$worksheet->method('getCell')
|
||||||
|
->willReturn($cell);
|
||||||
|
$cellReference = $this->getMockBuilder(Cell::class)
|
||||||
|
->setMethods(['getWorksheet'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$cellReference->method('getWorksheet')
|
||||||
|
->willReturn($worksheet);
|
||||||
|
|
||||||
array_push($args, $cellReference);
|
array_push($args, $cellReference);
|
||||||
$result = MathTrig::SUBTOTAL(...$args);
|
$result = MathTrig::SUBTOTAL(...$args);
|
||||||
|
@ -519,4 +541,63 @@ class MathTrigTest extends TestCase
|
||||||
{
|
{
|
||||||
return require 'data/Calculation/MathTrig/SUBTOTAL.php';
|
return require 'data/Calculation/MathTrig/SUBTOTAL.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function rowVisibility() {
|
||||||
|
yield from [1 => false, 2 => true, 3 => false, 4 => true, 5 => false, 6 => false, 7 => false, 8 => true, 9 => false, 10 => true, 11 =>true];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerSUBTOTALHIDDEN
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testSUBTOTALHIDDEN($expectedResult, ...$args)
|
||||||
|
{
|
||||||
|
$generator = \PhpOffice\PhpSpreadsheetTests\Calculation\MathTrigTest::rowVisibility();
|
||||||
|
$rowDimension = $this->getMockBuilder(RowDimension::class)
|
||||||
|
->setMethods(['getVisible'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$rowDimension->method('getVisible')
|
||||||
|
->will($this->returnCallback(function() use ($generator) { $result = $generator->current(); $generator->next(); return $result; }));
|
||||||
|
$columnDimension = $this->getMockBuilder(ColumnDimension::class)
|
||||||
|
->setMethods(['getVisible'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$columnDimension->method('getVisible')
|
||||||
|
->willReturn(true);
|
||||||
|
$cell = $this->getMockBuilder(Cell::class)
|
||||||
|
->setMethods(['getValue'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$cell->method('getValue')
|
||||||
|
->willReturn('');
|
||||||
|
$worksheet = $this->getMockBuilder(Worksheet::class)
|
||||||
|
->setMethods(['cellExists', 'getCell', 'getRowDimension', 'getColumnDimension'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$worksheet->method('cellExists')
|
||||||
|
->willReturn(true);
|
||||||
|
$worksheet->method('getCell')
|
||||||
|
->willReturn($cell);
|
||||||
|
$worksheet->method('getRowDimension')
|
||||||
|
->willReturn($rowDimension);
|
||||||
|
$worksheet->method('getColumnDimension')
|
||||||
|
->willReturn($columnDimension);
|
||||||
|
$cellReference = $this->getMockBuilder(Cell::class)
|
||||||
|
->setMethods(['getWorksheet'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$cellReference->method('getWorksheet')
|
||||||
|
->willReturn($worksheet);
|
||||||
|
|
||||||
|
array_push($args, $cellReference);
|
||||||
|
$result = MathTrig::SUBTOTAL(...$args);
|
||||||
|
self::assertEquals($expectedResult, $result, null, 1E-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerSUBTOTALHIDDEN()
|
||||||
|
{
|
||||||
|
return require 'data/Calculation/MathTrig/SUBTOTALHIDDEN.php';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,74 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$baseTestData = [
|
||||||
|
1 => ['A' => 0],
|
||||||
|
2 => ['A' => 1],
|
||||||
|
3 => ['A' => 1],
|
||||||
|
4 => ['A' => 2],
|
||||||
|
5 => ['A' => 3],
|
||||||
|
6 => ['A' => 5],
|
||||||
|
7 => ['A' => 8],
|
||||||
|
8 => ['A' => 13],
|
||||||
|
9 => ['A' => 21],
|
||||||
|
10 => ['A' => 34],
|
||||||
|
11 => ['A' => 55],
|
||||||
|
12 => ['A' => 89]
|
||||||
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
19.3333333333333,
|
19.3333333333333,
|
||||||
1, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
1,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
12,
|
12,
|
||||||
2, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
2,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
12,
|
12,
|
||||||
3, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
3,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
89,
|
89,
|
||||||
4, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
4,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
0,
|
0,
|
||||||
5, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
5,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
0,
|
0,
|
||||||
6, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
6,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
27.5196899207337,
|
27.5196899207337,
|
||||||
7, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
7,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
26.3480971271593,
|
26.3480971271593,
|
||||||
8, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
8,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
232,
|
232,
|
||||||
9, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
9,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
757.3333333333330,
|
757.3333333333330,
|
||||||
10, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
10,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
694.2222222222220,
|
694.2222222222220,
|
||||||
11, [1 => ['A' => 0], 2 => ['A' => 1], 3 => ['A' => 1], 4 => ['A' => 2], 5 => ['A' => 3], 6 => ['A' => 5], 7 => ['A' => 8], 8 => ['A' => 13], 9 => ['A' => 21], 10 => ['A' => 34], 11 => ['A' => 55], 12 => ['A' => 89] ]
|
11,
|
||||||
|
$baseTestData,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$baseTestData = [
|
||||||
|
1 => ['A' => 0],
|
||||||
|
2 => ['A' => 1],
|
||||||
|
3 => ['A' => 1],
|
||||||
|
4 => ['A' => 2],
|
||||||
|
5 => ['A' => 3],
|
||||||
|
6 => ['A' => 5],
|
||||||
|
7 => ['A' => 8],
|
||||||
|
8 => ['A' => 13],
|
||||||
|
9 => ['A' => 21],
|
||||||
|
10 => ['A' => 34],
|
||||||
|
11 => ['A' => 55],
|
||||||
|
12 => ['A' => 89]
|
||||||
|
];
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
21,
|
||||||
|
101,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
5,
|
||||||
|
102,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
5,
|
||||||
|
103,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
55,
|
||||||
|
104,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
105,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
48620,
|
||||||
|
106,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
23.1840462387393,
|
||||||
|
107,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
20.7364413533277,
|
||||||
|
108,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
105,
|
||||||
|
109,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
537.5,
|
||||||
|
110,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
430,
|
||||||
|
111,
|
||||||
|
$baseTestData,
|
||||||
|
],
|
||||||
|
];
|
Loading…
Reference in New Issue