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
path: root/tests
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2015-11-03 00:55:32 +0300
committerThomas Steur <thomas.steur@gmail.com>2015-11-04 23:02:10 +0300
commit8c970d3ecd5ee10825882eee2dfaf60f92a3a6ea (patch)
tree264a701b99ef0b77ade9ef7bdbacfe85d12a2318 /tests
parent89eb98b2fdaf3fa72a4a038daa050764f904ecc6 (diff)
changed look of custom variables screen, merge metadata when specified
Diffstat (limited to 'tests')
-rw-r--r--tests/PHPUnit/Unit/DataTable/RowTest.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/PHPUnit/Unit/DataTable/RowTest.php b/tests/PHPUnit/Unit/DataTable/RowTest.php
index e18806d2d5..bc9c49bb84 100644
--- a/tests/PHPUnit/Unit/DataTable/RowTest.php
+++ b/tests/PHPUnit/Unit/DataTable/RowTest.php
@@ -362,6 +362,65 @@ class RowTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->row->hasColumn('test'));
}
+ public function test_sumRowMetadata_shouldSumMetadataAccordingToAggregationOperations()
+ {
+ $this->row->setColumn('nb_visits', 10);
+ $this->row->setMetadata('my_sum', 5);
+ $this->row->setMetadata('my_max', 4);
+ $this->row->setMetadata('my_array', array(array('test' => 1, 'value' => 1), array('test' => 2, 'value' => 2)));
+
+
+ $row = $this->getTestRowWithNoSubDataTable();
+ $row->setColumn('nb_visits', 15);
+ $row->setMetadata('my_sum', 7);
+ $row->setMetadata('my_max', 2);
+ $row->setMetadata('my_array', array(array('test' => 3, 'value' => 3), array('test' => 2, 'value' => 2)));
+
+
+ $aggregations = array(
+ 'nosuchcolumn' => 'max', // this metadata name does not exist and should be ignored
+ 'my_sum' => 'sum',
+ 'my_max' => 'max',
+ 'my_array' => 'uniquearraymerge'
+ );
+ $this->row->sumRowMetadata($row, $aggregations);
+
+ $metadata = $this->row->getMetadata();
+ $expected = array(
+ 'my_sum' => 12,
+ 'my_max' => 4,
+ 'my_array' => array(array('test' => 1, 'value' => 1), array('test' => 2, 'value' => 2), array('test' => 3, 'value' => 3))
+ );
+ $this->assertSame($expected, $metadata);
+ }
+
+ public function test_sumRowMetadata_uniquearraymergeShouldUseArrayFromOtherRow_IfNoMetadataForThisRowSpecified()
+ {
+ $row = $this->getTestRowWithNoSubDataTable();
+ $arrayValue = array(array('test' => 3, 'value' => 3), array('test' => 2, 'value' => 2));
+ $row->setMetadata('my_array', $arrayValue);
+
+ $aggregations = array('my_array' => 'uniquearraymerge');
+
+ $this->row->sumRowMetadata($row, $aggregations);
+
+ $this->assertSame(array('my_array' => $arrayValue), $this->row->getMetadata());
+ }
+
+ public function test_sumRowMetadata_uniquearraymergeShouldUseArrayFromThisRow_IfNoMetadataForOtherRowSpecified()
+ {
+ $row = $this->getTestRowWithNoSubDataTable();
+
+ $arrayValue = array(array('test' => 3, 'value' => 3), array('test' => 2, 'value' => 2));
+ $this->row->setMetadata('my_array', $arrayValue);
+
+ $aggregations = array('my_array' => 'uniquearraymerge');
+
+ $this->row->sumRowMetadata($row, $aggregations);
+
+ $this->assertSame(array('my_array' => $arrayValue), $this->row->getMetadata());
+ }
+
private function assertColumnSavesValue($expectedValue, $columnName, $valueToSet)
{
$this->row->setColumn($columnName, $valueToSet);