diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2021-05-11 03:28:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 03:28:13 +0300 |
commit | 8366ad8ded026d8e6907a4738be44744c72a0312 (patch) | |
tree | 607f33569ed43e28505ae2260e0b52febc4eed08 /tests/PHPUnit/Unit | |
parent | 59301c3638c63a49a56f40965ecf50387c6c645f (diff) |
Do not confuse normal rows with the label "-1" w/ the summary row (#17517)
* add failing tests
* do not mistake normal rows w/ labels -1 for summary rows
* try to set a new flag to determine summary row inside Row instead of guessing from the label
* fix tests
* fix test hopefully
* fix another test
* fix another summary row issue
* Add test showing -1 label + Others row.
* apply review feedback
Diffstat (limited to 'tests/PHPUnit/Unit')
-rw-r--r-- | tests/PHPUnit/Unit/DataTableTest.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/PHPUnit/Unit/DataTableTest.php b/tests/PHPUnit/Unit/DataTableTest.php index 22adb1abe2..8e8d18c823 100644 --- a/tests/PHPUnit/Unit/DataTableTest.php +++ b/tests/PHPUnit/Unit/DataTableTest.php @@ -935,6 +935,85 @@ class DataTableTest extends \PHPUnit\Framework\TestCase $this->assertTrue(DataTable::isEqual($table, $tableExpected)); } + public function test_addDataTable_whenThereIsNoSummaryRowInOneTable_andASummaryRowInTheOtherTable() + { + $table1 = new DataTable(); + $table1->addRowsFromSimpleArray([ + ['label' => 'a', 'value' => 5], + ]); + $table1->addSummaryRow(new Row([ + Row::COLUMNS => [ + 'label' => DataTable::LABEL_SUMMARY_ROW, + 'value' => 15, + ], + ])); + + $table2 = new DataTable(); + $table2->addRowsFromSimpleArray([ + ['label' => 'a', 'value' => 10], + ['label' => -1, 'value' => 30], + ]); + $table2->addSummaryRow(new Row([ + Row::COLUMNS => [ + 'label' => DataTable::LABEL_SUMMARY_ROW, + 'value' => 5, + ], + ])); + + $table1->addDataTable($table2); + + $expectedRows = [ + 0 => ['label' => 'a', 'value' => 15], + 1 => ['label' => -1, 'value' => 30], + DataTable::ID_SUMMARY_ROW => ['label' => -1, 'value' => 20], + ]; + + $actualRows = $table1->getRows(); + $actualRows = array_map(function (Row $r) { return $r->getColumns(); }, $actualRows); + + $this->assertEquals($expectedRows, $actualRows); + } + + public function test_addDataTable_whenThereIsASummaryRow_andRowWithNegativeOneLabel() + { + $table1 = new DataTable(); + $table1->addRowsFromSimpleArray([ + ['label' => 'a', 'value' => 5], + ['label' => '-1', 'value' => 20], + ]); + $table1->addSummaryRow(new Row([ + Row::COLUMNS => [ + 'label' => DataTable::LABEL_SUMMARY_ROW, + 'value' => 15, + ], + ])); + + $table2 = new DataTable(); + $table2->addRowsFromSimpleArray([ + ['label' => 'a', 'value' => 10], + ['label' => -1, 'value' => 30], + ]); + $table2->addSummaryRow(new Row([ + Row::COLUMNS => [ + 'label' => DataTable::LABEL_SUMMARY_ROW, + 'value' => 5, + ], + ])); + + $table1->addDataTable($table2); + + $expectedRows = [ + 0 => ['label' => 'a', 'value' => 15], + 1 => ['label' => -1, 'value' => 50], + DataTable::ID_SUMMARY_ROW => ['label' => -1, 'value' => 20], + ]; + + $actualRows = $table1->getRows(); + $actualRows = array_map(function (Row $r) { return $r->getColumns(); }, $actualRows); + + $this->assertEquals($expectedRows, $actualRows); + } + public function testUnrelatedDataTableNotDestructed() { $mockedDataTable = $this->createPartialMock('\Piwik\DataTable', array('__destruct')); |