Full unit tests for SUBTOTAL function
This commit is contained in:
parent
3298667153
commit
bbe11eed37
|
@ -1088,8 +1088,9 @@ class MathTrig
|
|||
list(, $row, $column) = explode('.', $index);
|
||||
if ($cellReference->getWorksheet()->cellExists($column . $row)) {
|
||||
//take this cell out if it contains the SUBTOTAL formula
|
||||
return !$cellReference->getWorksheet()->getCell($column . $row)->isFormula() &&
|
||||
!preg_match('/^=.*\bSUBTOTAL\s*\(/', strtoupper($cellReference->getWorksheet()->getCell($column . $row)->getValue()));
|
||||
$isFormula = $cellReference->getWorksheet()->getCell($column . $row)->isFormula();
|
||||
$cellFormula = !preg_match('/^=.*\bSUBTOTAL\s*\(/', strtoupper($cellReference->getWorksheet()->getCell($column . $row)->getValue()));
|
||||
return !$isFormula || $cellFormula;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
|
|
@ -603,9 +603,13 @@ class MathTrigTest extends TestCase
|
|||
}
|
||||
|
||||
protected function cellValues($cellValues) {
|
||||
return function() use ($cellValues) {
|
||||
yield from $cellValues;
|
||||
};
|
||||
yield from $cellValues;
|
||||
}
|
||||
|
||||
protected function cellIsFormula($cellValues) {
|
||||
foreach($cellValues as $cellValue) {
|
||||
yield $cellValue[0] === '=';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -615,18 +619,17 @@ class MathTrigTest extends TestCase
|
|||
*/
|
||||
public function testNestedSUBTOTAL($expectedResult, ...$args)
|
||||
{
|
||||
$this->markTestSkipped('Revisite when cellValueGenarator() works for mocking getValue() calls');
|
||||
|
||||
$cellValueGenerator = $this->cellValues(Functions::flattenArray(array_slice($args, 1)));
|
||||
$cellIsFormulaGenerator = $this->cellIsFormula(Functions::flattenArray(array_slice($args, 1)));
|
||||
|
||||
$cell = $this->getMockBuilder(Cell::class)
|
||||
->setMethods(['getValue', 'isFormula'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$cell->method('getValue')
|
||||
->will($this->returnCallback(function() use ($cellValueGenerator) { $result = $cellValueGenerator->current(); $cellValueGenerator->next(); var_dump($result); return $result; }));
|
||||
->will($this->returnCallback(function() use ($cellValueGenerator) { $result = $cellValueGenerator->current(); $cellValueGenerator->next(); return $result; }));
|
||||
$cell->method('isFormula')
|
||||
->willReturn(true);
|
||||
->will($this->returnCallback(function() use ($cellIsFormulaGenerator) { $result = $cellIsFormulaGenerator->current(); $cellIsFormulaGenerator->next(); return $result; }));
|
||||
$worksheet = $this->getMockBuilder(Worksheet::class)
|
||||
->setMethods(['cellExists', 'getCell'])
|
||||
->disableOriginalConstructor()
|
||||
|
@ -643,6 +646,7 @@ class MathTrigTest extends TestCase
|
|||
->willReturn($worksheet);
|
||||
|
||||
array_push($args, $cellReference);
|
||||
|
||||
$result = MathTrig::SUBTOTAL(...$args);
|
||||
self::assertEquals($expectedResult, $result, null, 1E-12);
|
||||
}
|
||||
|
@ -651,5 +655,4 @@ class MathTrigTest extends TestCase
|
|||
{
|
||||
return require 'data/Calculation/MathTrig/SUBTOTALNESTED.php';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
$baseTestData = [
|
||||
1 => ['A' => 1],
|
||||
2 => ['A' => '=2*1'],
|
||||
1 => ['A' => 123],
|
||||
2 => ['A' => 234],
|
||||
3 => ['A' => '=SUBTOTAL(1, A1:A2)'],
|
||||
4 => ['A' => '=ROMAN(SUBTOTAL(1, A1:A2))'],
|
||||
5 => ['A' => 'This is text containing "=" and "SUBTOTAL("'],
|
||||
|
@ -10,8 +10,8 @@ $baseTestData = [
|
|||
|
||||
return [
|
||||
[
|
||||
2,
|
||||
2,
|
||||
357,
|
||||
9,
|
||||
$baseTestData,
|
||||
],
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue