Code works, but the tests don't yet

This commit is contained in:
MarkBaker 2018-04-21 20:34:25 +01:00
parent 36afa01d33
commit f08eeaa2ed
3 changed files with 29 additions and 10 deletions

View File

@ -1088,7 +1088,8 @@ class MathTrig
list(, $row, $column) = explode('.', $index);
if ($cellReference->getWorksheet()->cellExists($column . $row)) {
//take this cell out if it contains the SUBTOTAL formula
return !preg_match('/=.*\b(SUBTOTAL)\s*\(/', strtoupper($cellReference->getWorksheet()->getCell($column . $row)->getValue()));
return !$cellReference->getWorksheet()->getCell($column . $row)->isFormula() &&
!preg_match('/^=.*\bSUBTOTAL\s*\(/', strtoupper($cellReference->getWorksheet()->getCell($column . $row)->getValue()));
}
return true;
},
@ -1102,7 +1103,11 @@ class MathTrig
* Returns a subtotal in a list or database.
*
* @param int the number 1 to 11 that specifies which function to
* use in calculating subtotals within a list
* use in calculating subtotals within a range
* list
* Numbers 101 to 111 shadow the functions of 1 to 11
* but ignore any values in the range that are
* in hidden rows or columns
* @param array of mixed Data Series
*
* @return float
@ -1117,7 +1122,7 @@ class MathTrig
if ((is_numeric($subtotal)) && (!is_string($subtotal))) {
if ($subtotal > 100) {
$aArgs = self::filterHiddenArgs($cellReference, $aArgs);
$subtotal = $subtotal - 100;
$subtotal -= 100;
}
$aArgs = self::filterFormulaArgs($cellReference, $aArgs);

View File

@ -542,7 +542,7 @@ class MathTrigTest extends TestCase
return require 'data/Calculation/MathTrig/SUBTOTAL.php';
}
protected static function rowVisibility() {
protected 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];
}
@ -553,13 +553,14 @@ class MathTrigTest extends TestCase
*/
public function testHiddenSUBTOTAL($expectedResult, ...$args)
{
$generator = \PhpOffice\PhpSpreadsheetTests\Calculation\MathTrigTest::rowVisibility();
$visibilityGenerator = $this->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; }));
->will($this->returnCallback(function() use ($visibilityGenerator) { $result = $visibilityGenerator->current(); $visibilityGenerator->next(); return $result; }));
$columnDimension = $this->getMockBuilder(ColumnDimension::class)
->setMethods(['getVisible'])
->disableOriginalConstructor()
@ -601,6 +602,13 @@ class MathTrigTest extends TestCase
return require 'data/Calculation/MathTrig/SUBTOTALHIDDEN.php';
}
public static $cellValues;
public function cellValues() {
echo 'CALLED cellValues()', PHP_EOL;
yield from [1,2,3,4,5,6,7,8,9,10];
}
/**
* @dataProvider providerNestedSUBTOTAL
*
@ -608,12 +616,17 @@ class MathTrigTest extends TestCase
*/
public function testNestedSUBTOTAL($expectedResult, ...$args)
{
self::$cellValues = Functions::flattenArray(array_slice($args, 1));
$cellValueGenerator = $this->cellValues();
$cell = $this->getMockBuilder(Cell::class)
->setMethods(['getValue'])
->setMethods(['getValue', 'isFormula'])
->disableOriginalConstructor()
->getMock();
$cell->method('getValue')
->willReturn(null);
->will($this->returnCallback(function() use ($cellValueGenerator) { $result = $cellValueGenerator->current(); $cellValueGenerator->next(); var_dump($result); return $result; }));
$cell->method('isFormula')
->willReturn(true);
$worksheet = $this->getMockBuilder(Worksheet::class)
->setMethods(['cellExists', 'getCell'])
->disableOriginalConstructor()

View File

@ -2,9 +2,10 @@
$baseTestData = [
1 => ['A' => 1],
2 => ['A' => 1],
2 => ['A' => '=2*1'],
3 => ['A' => '=SUBTOTAL(1, A1:A2)'],
4 => ['A' => '=ROMAN(SUBTOTAL(1, A1:A2))']
4 => ['A' => '=ROMAN(SUBTOTAL(1, A1:A2))'],
5 => ['A' => 'This is text containing "=" and "SUBTOTAL("'],
];
return [