Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/CoreVisualizations/tests/Unit/GraphTest.php')
-rw-r--r--plugins/CoreVisualizations/tests/Unit/GraphTest.php152
1 files changed, 152 insertions, 0 deletions
diff --git a/plugins/CoreVisualizations/tests/Unit/GraphTest.php b/plugins/CoreVisualizations/tests/Unit/GraphTest.php
new file mode 100644
index 0000000000..285960ae61
--- /dev/null
+++ b/plugins/CoreVisualizations/tests/Unit/GraphTest.php
@@ -0,0 +1,152 @@
+<?php
+/**
+ * Matomo - free/libre analytics platform
+ *
+ * @link http://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+namespace Piwik\Plugins\CoreVisualizations\tests\Unit;
+
+use Piwik\DataTable;
+
+/**
+ * @group CoreVisualizations
+ * @group SparklinesConfigTest
+ * @group Sparklines
+ * @group Plugins
+ */
+class GraphTest extends \PHPUnit_Framework_TestCase
+{
+ public function testSelectableColumnsAlreadySet()
+ {
+ $bar = $this->getMockGraph(array());
+ $bar->config->selectable_columns = array('nb_abc', 'nb_xyz');
+ $bar->afterAllFiltersAreApplied();
+
+ $columns = array_column($bar->config->selectable_columns, 'column');
+ $this->assertEquals(array('nb_abc', 'nb_xyz'), $columns);
+ }
+
+ public function testSelectableColumnsNbVisitsOnlyPresent()
+ {
+ $bar = $this->getMockGraph(array(
+ 'label' => 'abc',
+ 'nb_visits' => 0,
+ ));
+
+ $bar->afterAllFiltersAreApplied();
+
+ $columns = array_column($bar->config->selectable_columns, 'column');
+ $this->assertEquals(array('nb_visits'), $columns);
+ }
+
+ public function testSelectableColumnsUniqueVisitorsPresent()
+ {
+ $bar = $this->getMockGraph(array(
+ 'label' => 'abc',
+ 'nb_visits' => 5,
+ 'nb_uniq_visitors' => 2,
+ 'nb_something_else' => 1
+ ));
+
+ $bar->afterAllFiltersAreApplied();
+
+ $columns = array_column($bar->config->selectable_columns, 'column');
+ $this->assertEquals(array('nb_visits', 'nb_uniq_visitors'), $columns);
+ }
+
+ public function testSelectableColumnsNoDefaultColumnsPresent()
+ {
+ $bar = $this->getMockGraph(array(
+ 'label' => 'abc',
+ 'foo' => 5,
+ 'bar' => 2
+ ));
+
+ $bar->afterAllFiltersAreApplied();
+
+ $columns = array_column($bar->config->selectable_columns, 'column');
+ $this->assertEquals(array('foo', 'bar'), $columns);
+ }
+
+ public function testSelectableColumnsNoDefaultColumnsPresentLabelNotPresent()
+ {
+ $bar = $this->getMockGraph(array(
+ 'foo' => 5,
+ 'bar' => 2
+ ));
+
+ $bar->afterAllFiltersAreApplied();
+
+ $columns = array_column($bar->config->selectable_columns, 'column');
+ $this->assertEquals(array('foo', 'bar'), $columns);
+ }
+
+ public function testSelectableColumnsAlreadySetToEmptyArray()
+ {
+ $bar = $this->getMockGraph(array(
+ 'label' => 'abc',
+ 'foo' => 5,
+ 'bar' => 2
+ ));
+ $bar->config->selectable_columns = array();
+
+ $bar->afterAllFiltersAreApplied();
+
+ $this->assertEmpty($bar->config->selectable_columns);
+ }
+
+ public function testColumnsToDisplayNotInDataset()
+ {
+ $bar = $this->getMockGraph(array(
+ 'label' => 'abc',
+ 'nb_visits' => 25,
+ 'nb_actions' => 80
+ ));
+ // Not present in the dataset = should be thrown out and replaced with first value from dataset
+ $bar->config->columns_to_display = array('nb_uniq_visitors');
+
+ $bar->afterAllFiltersAreApplied();
+
+ $this->assertEquals(array('nb_visits'), $bar->config->columns_to_display);
+ }
+
+ public function testColumnsToDisplayNotInSelectableColumns()
+ {
+ $bar = $this->getMockGraph(array(
+ 'label' => 'abc',
+ 'nb_visits' => 25,
+ 'nb_actions' => 80
+ ));
+ // columns_to_display is not present in selectable_columbs, but as long as it's in the data set that's OK
+ $bar->config->selectable_columns = array('nb_visits');
+ $bar->config->columns_to_display = array('nb_actions');
+
+ $bar->afterAllFiltersAreApplied();
+
+ $this->assertEquals(array('nb_actions'), $bar->config->columns_to_display);
+ }
+
+ /**
+ * @return \Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Bar
+ */
+ private function getMockGraph(array $firstDataRow)
+ {
+ $row = new DataTable\Row(array(
+ DataTable\Row::COLUMNS => $firstDataRow
+ ));
+ $dataTable = new DataTable();
+ $dataTable->setRows(array($row));
+
+ $bar = $this->getMock('Piwik\Plugins\CoreVisualizations\Visualizations\JqplotGraph\Bar',
+ array('getDataTable'),
+ array('', '')
+ );
+ $bar->expects($this->any())
+ ->method('getDataTable')
+ ->will($this->returnValue($dataTable));
+
+ return $bar;
+ }
+}