diff options
Diffstat (limited to 'plugins/CoreVisualizations')
-rw-r--r-- | plugins/CoreVisualizations/Visualizations/Sparklines/Config.php | 7 | ||||
-rw-r--r-- | plugins/CoreVisualizations/tests/Integration/SparklinesConfigTest.php | 34 |
2 files changed, 37 insertions, 4 deletions
diff --git a/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php b/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php index 6557abb44b..a4dae712db 100644 --- a/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php +++ b/plugins/CoreVisualizations/Visualizations/Sparklines/Config.php @@ -205,9 +205,14 @@ class Config extends \Piwik\ViewDataTable\Config } if (!empty($requestParamsForSparkline['columns']) + && is_array($requestParamsForSparkline['columns']) && count($requestParamsForSparkline['columns']) === count($values)) { $columns = array_values($requestParamsForSparkline['columns']); - } else { + } elseif (!empty($requestParamsForSparkline['columns']) + && is_string($requestParamsForSparkline['columns']) + && count($values) === 1) { + $columns = array($requestParamsForSparkline['columns']); + } else{ $columns = array(); } diff --git a/plugins/CoreVisualizations/tests/Integration/SparklinesConfigTest.php b/plugins/CoreVisualizations/tests/Integration/SparklinesConfigTest.php index 45f4876ea4..49a116b5cc 100644 --- a/plugins/CoreVisualizations/tests/Integration/SparklinesConfigTest.php +++ b/plugins/CoreVisualizations/tests/Integration/SparklinesConfigTest.php @@ -54,7 +54,7 @@ class SparklinesConfigTest extends IntegrationTestCase $expectedSparkline = array( 'url' => '?period=day&date=2012-03-06,2012-04-04&idSite=1&module=CoreHome&action=renderMe&viewDataTable=sparkline', 'metrics' => array ( - array ('value' => 10, 'description' => 'Visits'), + array ('column' => '', 'value' => 10, 'description' => 'Visits'), ), 'order' => 999 ); @@ -62,6 +62,18 @@ class SparklinesConfigTest extends IntegrationTestCase $this->assertSame(array($expectedSparkline), $this->config->getSortedSparklines()); } + public function test_addSparkline_shouldAddAMinimalSparklineWithOneValueAndUseDefaultOrderWithColumn() + { + $params = $this->sparklineParams(); + $params['columns'] = 'nb_visits'; + $this->config->addSparkline($params, $value = 10, $description = 'Visits'); + + $expectedSparkline = array('column' => 'nb_visits', 'value' => 10, 'description' => 'Visits'); + + $sparklines = $this->config->getSortedSparklines(); + $this->assertSame(array($expectedSparkline), $sparklines[0]['metrics']); + } + public function test_addSparkline_shouldAddSparklineWithMultipleValues() { $this->config->addSparkline($this->sparklineParams(), $values = array(10, 20), $description = array('Visits', 'Actions')); @@ -69,11 +81,27 @@ class SparklinesConfigTest extends IntegrationTestCase $sparklines = $this->config->getSortedSparklines(); $this->assertSame(array ( - array ('value' => 10, 'description' => 'Visits'), - array ('value' => 20, 'description' => 'Actions'), + array ('column' => '', 'value' => 10, 'description' => 'Visits'), + array ('column' => '', 'value' => 20, 'description' => 'Actions'), ), $sparklines[0]['metrics']); } + public function test_addSparkline_shouldAddSparklinesMultipleValuesWithColumns() + { + $params = $this->sparklineParams(); + $params['columns'] = array('nb_visits', 'nb_actions'); + + $this->config->addSparkline($params, $values = array(10, 20), $description = array('Visits', 'Actions')); + + $expectedSparkline = array( + array ('column' => 'nb_visits', 'value' => 10, 'description' => 'Visits'), + array ('column' => 'nb_actions', 'value' => 20, 'description' => 'Actions') + ); + + $sparklines = $this->config->getSortedSparklines(); + $this->assertSame($expectedSparkline, $sparklines[0]['metrics']); + } + /** * @expectedException \Exception * @expectedExceptionMessage Values: 10, 20, 30 Descriptions: Visits, Actions |