diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2021-05-17 05:27:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-17 05:27:21 +0300 |
commit | 68e031922f09c075cfcd98ae8157c2b56726bf24 (patch) | |
tree | 80b43ee9a069cde6747ba256f7b317b0b128eac5 | |
parent | b77e5ff594cdae59862dd4d863220baffc200bec (diff) |
Make sure summary row subtables are included in the serialized representaion of a datatable tree. (#17569)
-rw-r--r-- | core/DataTable.php | 4 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/DataTableTest.php | 20 |
2 files changed, 22 insertions, 2 deletions
diff --git a/core/DataTable.php b/core/DataTable.php index e992c9aa3a..26d85a49e5 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -1317,10 +1317,10 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess $consecutiveSubtableIds = array(); $forcedId = $subtableId; - // For each row, get the serialized row + // For each row (including the summary row), get the serialized row // If it is associated to a sub table, get the serialized table recursively ; // but returns all serialized tables and subtable in an array of 1 dimension - foreach ($this->rows as $id => $row) { + foreach ($this->getRows() as $id => $row) { $subTable = $row->getSubtable(); if ($subTable) { $consecutiveSubtableIds[$id] = ++$subtableId; diff --git a/tests/PHPUnit/Unit/DataTableTest.php b/tests/PHPUnit/Unit/DataTableTest.php index 8e8d18c823..75a4f67e3c 100644 --- a/tests/PHPUnit/Unit/DataTableTest.php +++ b/tests/PHPUnit/Unit/DataTableTest.php @@ -453,6 +453,26 @@ class DataTableTest extends \PHPUnit\Framework\TestCase $table->getSerialized(); } + public function test_getSerialized_SerializesSubtablesOfSummaryRows() + { + $table = new DataTable; + $table->addRowFromArray(array(Row::COLUMNS => array('label' => 'dimval1', 'visits' => 245))); + + $summaryRow = new Row([Row::COLUMNS => ['label' => 'others', 'visits' => 500]]); + + $summaryRowSubtable = new DataTable; + $summaryRowSubtable->addRow(new Row([Row::COLUMNS => ['label' => 'subtabledimension', 'visits' => 100]])); + $summaryRow->setSubtable($summaryRowSubtable); + + $table->addSummaryRow($summaryRow); + + $results = $table->getSerialized(); + + $this->assertCount(2, $results); + $this->assertStringContainsString('dimval1', $results[0]); + $this->assertStringContainsString('subtabledimension', $results[1]); + } + /** * Test queing filters */ |