diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-07-21 12:01:35 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-07-21 12:01:36 +0400 |
commit | aca8ec33a85e0a70b818b6227145041717d7a69e (patch) | |
tree | 41377e3a9737d63222522ef93ecf8483f3faddfa /tests/PHPUnit/Core/DataTable/MapTest.php | |
parent | 0a63210e3eae7562af1a3dbee340eb1ee140db3d (diff) |
Refs #4059 Work in progress: Conversion to use Namespaces: Period*, Metrics, Segment, SegmentExpression, PluginsManager.
Removed some deprecated code.
Diffstat (limited to 'tests/PHPUnit/Core/DataTable/MapTest.php')
-rw-r--r-- | tests/PHPUnit/Core/DataTable/MapTest.php | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/tests/PHPUnit/Core/DataTable/MapTest.php b/tests/PHPUnit/Core/DataTable/MapTest.php new file mode 100644 index 0000000000..2ac19275a9 --- /dev/null +++ b/tests/PHPUnit/Core/DataTable/MapTest.php @@ -0,0 +1,127 @@ +<?php +use Piwik\Config; +use Piwik\DataTable; +use Piwik\DataTable\Manager; +use Piwik\DataTable\Row; + +class Test_DataTable_Map extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + parent::setUp(); + Config::getInstance()->setTestEnvironment(); + Manager::getInstance()->deleteAll(); + } + + private function createTestDataTable() + { + $result = new DataTable(); + + $result->addRowsFromArray(array( + array(Row::COLUMNS => array('label' => 'row1', 'col1' => 1)), + array(Row::COLUMNS => array('label' => 'row2', 'col1' => 2)) + )); + + return $result; + } + + private function createInstanceWithDataTables() + { + $dataTable = new DataTable\Map(); + + $subDataTable1 = $this->createTestDataTable(); + $dataTable->addTable($subDataTable1, 'subDataTable1'); + + $subDataTable2 = $this->createTestDataTable(); + $dataTable->addTable($subDataTable2, 'subDataTable2'); + + return $dataTable; + } + + private function createInstanceWithDataTableArrays() + { + $dataTable = new DataTable\Map(); + + $subDataTableArray1 = $this->createInstanceWithDataTables(); + $dataTable->addTable($subDataTableArray1, 'subArray1'); + + $subDataTableArray2 = $this->createInstanceWithDataTables(); + $dataTable->addTable($subDataTableArray2, 'subArray2'); + + return $dataTable; + } + + /** + * Tests that Set::mergeChildren works when the DataTable_Array contains DataTables. + * @group Core + * @group DataTable + * @group DataTable_Array + */ + public function test_MergeChildrenDataTable() + { + $dataTable = $this->createInstanceWithDataTables(); + + $result = $dataTable->mergeChildren(); + + // check that the result is a DataTable w/ 4 rows + $this->assertInstanceOf('DataTable', $result); + $this->assertEquals(4, $result->getRowsCount()); + + // check that the first two rows have 'subDataTable1' as the label + $this->mergeChildren_checkRow($result->getRowFromId(0), 'subDataTable1', 1); + $this->mergeChildren_checkRow($result->getRowFromId(1), 'subDataTable1', 2); + + // check that the last two rows have 'subDataTable2' as the label + $this->mergeChildren_checkRow($result->getRowFromId(2), 'subDataTable2', 1); + $this->mergeChildren_checkRow($result->getRowFromId(3), 'subDataTable2', 2); + } + + private function mergeChildren_checkRow($row, $expectedLabel, $expectedColumnValue) + { + $this->assertEquals($expectedLabel, $row->getColumn('label')); + $this->assertEquals($expectedColumnValue, $row->getColumn('col1')); + } + + /** + * Tests that Set::mergeChildren works when the DataTable_Array contains DataTable_Arrays. + * @group Core + * @group DataTable + * @group DataTable_Array + */ + public function testMergeChildrenDataTableArray() + { + $dataTable = $this->createInstanceWithDataTableArrays(); + + $result = $dataTable->mergeChildren(); + + // check that the result is a DataTable_Array w/ two DataTable children + $this->assertInstanceOf('Set', $result); + $this->assertEquals(2, $result->getRowsCount()); + + // check that the first sub-DataTable is a DataTable with 4 rows + $subDataTable1 = $result->getTable('subDataTable1'); + $this->assertTrue($subDataTable1 instanceof DataTable); + $this->assertEquals(4, $subDataTable1->getRowsCount()); + + // check that the first two rows of the first sub-table have 'subArray1' as the label + $this->mergeChildren_checkRow($subDataTable1->getRowFromId(0), 'subArray1', 1); + $this->mergeChildren_checkRow($subDataTable1->getRowFromId(1), 'subArray1', 2); + + // check that the last two rows of the first sub-table have 'subArray2' as the label + $this->mergeChildren_checkRow($subDataTable1->getRowFromId(2), 'subArray2', 1); + $this->mergeChildren_checkRow($subDataTable1->getRowFromId(3), 'subArray2', 2); + + // check that the second sub-DataTable is a DataTable with 4 rows + $subDataTable2 = $result->getTable('subDataTable2'); + $this->assertTrue($subDataTable2 instanceof DataTable); + $this->assertEquals(4, $subDataTable2->getRowsCount()); + + // check that the first two rows of the second sub-table have 'subArray1' as the label + $this->mergeChildren_checkRow($subDataTable2->getRowFromId(0), 'subArray1', 1); + $this->mergeChildren_checkRow($subDataTable2->getRowFromId(1), 'subArray1', 2); + + // check that the last two rows of the second sub-table have 'subArray2' as the label + $this->mergeChildren_checkRow($subDataTable2->getRowFromId(2), 'subArray2', 1); + $this->mergeChildren_checkRow($subDataTable2->getRowFromId(3), 'subArray2', 2); + } +} |