From e4cb4463dac83a996202e6e1fa82d1895557acf8 Mon Sep 17 00:00:00 2001 From: Kate Butler Date: Tue, 2 Jul 2019 22:33:55 +1200 Subject: Gracefully handle case when row evolution has no data (#14562) --- plugins/API/RowEvolution.php | 4 ++++ plugins/API/tests/Integration/RowEvolutionTest.php | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'plugins/API') diff --git a/plugins/API/RowEvolution.php b/plugins/API/RowEvolution.php index 41c75bffde..9fd489f7e4 100644 --- a/plugins/API/RowEvolution.php +++ b/plugins/API/RowEvolution.php @@ -55,6 +55,10 @@ class RowEvolution $dataTable = $this->loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $labels, $segment, $apiParameters); + if (empty($dataTable->getDataTables())) { + return array(); + } + if (empty($labels)) { $labels = $this->getLabelsFromDataTable($dataTable, $labels); $dataTable = $this->enrichRowAddMetadataLabelIndex($labels, $dataTable); diff --git a/plugins/API/tests/Integration/RowEvolutionTest.php b/plugins/API/tests/Integration/RowEvolutionTest.php index b796562cac..d96bb0efac 100644 --- a/plugins/API/tests/Integration/RowEvolutionTest.php +++ b/plugins/API/tests/Integration/RowEvolutionTest.php @@ -43,4 +43,10 @@ class RowEvolutionTest extends IntegrationTestCase $this->assertNotEmpty($table); } + public function test_getRowEvolution_shouldReturnEmptyArray_IfNoData() + { + $rowEvolution = new RowEvolution(); + $table = $rowEvolution->getRowEvolution(1, 'day', 'last7', 'Actions', 'getSiteSearchCategories'); + $this->assertEquals(array(), $table); + } } -- cgit v1.2.3