예제 #1
0
 /**
  * Returns true if both DataTable are exactly the same.
  * Used in unit tests.
  * 
  * @param Piwik_DataTable $table1
  * @param Piwik_DataTable $table2
  * @return bool
  */
 public static function isEqual(Piwik_DataTable $table1, Piwik_DataTable $table2)
 {
     $rows1 = $table1->getRows();
     $rows2 = $table2->getRows();
     $table1->rebuildIndex();
     $table2->rebuildIndex();
     if ($table1->getRowsCount() != $table2->getRowsCount()) {
         return false;
     }
     foreach ($rows1 as $row1) {
         $row2 = $table2->getRowFromLabel($row1->getColumn('label'));
         if ($row2 === false || !Piwik_DataTable_Row::isEqual($row1, $row2)) {
             return false;
         }
     }
     return true;
 }
예제 #2
0
 public function test_whenRowsInRandomOrderButSortSpecified_shouldComputeSummaryRowAfterSort()
 {
     $table = new Piwik_DataTable();
     $table->addRow($this->getRow3());
     $table->addRow($this->getRow2());
     $table->addRow($this->getRow4());
     $table->addRow($this->getRow1());
     $table->addRow($this->getRow0());
     $filter = new Piwik_DataTable_Filter_AddSummaryRow($table, 2, Piwik_DataTable::LABEL_SUMMARY_ROW, $columnToSortBy = 'nb');
     $this->assertEqual($table->getRowsCount(), 3);
     $expectedRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array('label' => Piwik_DataTable::LABEL_SUMMARY_ROW, 'nb' => 111)));
     $this->assertTrue(Piwik_DataTable_Row::isEqual($table->getLastRow(), $expectedRow));
 }
예제 #3
0
 /**
  * Simple test of the DataTable_Row
  * 
  * @group Core
  * @group DataTable
  */
 public function testSumRow()
 {
     $columns = array('test_int' => 145, 'test_float' => 145.5, 'test_float3' => 1.5, 'test_stringint' => "145", "test" => 'string fake', 'integerArrayToSum' => array(1 => 1, 2 => 10.0, 3 => array(1 => 2, 2 => 3)));
     $metadata = array('logo' => 'piwik.png', 'super' => array('this column has an array value, amazing'));
     $arrayRow = array(Piwik_DataTable_Row::COLUMNS => $columns, Piwik_DataTable_Row::METADATA => $metadata, 'fake useless key' => 38959, 43905724897.0 => 'value');
     $row1 = new Piwik_DataTable_Row($arrayRow);
     $columns2 = array('test_int' => 5, 'test_float' => 4.5, 'test_float2' => 14.5, 'test_stringint' => "5", 00 => 'toto', 'integerArrayToSum' => array(1 => 5, 2 => 5.5, 3 => array(2 => 4)));
     $finalRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
     $finalRow->sumRow($row1);
     $columnsWanted = array('test_int' => 150, 'test_float' => 150.0, 'test_float2' => 14.5, 'test_float3' => 1.5, 'test_stringint' => 150, 'test' => 'string fake', 'integerArrayToSum' => array(1 => 6, 2 => 15.5, 3 => array(1 => 2, 2 => 7)), 00 => 'toto');
     $rowWanted = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columnsWanted));
     $this->assertTrue(Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
 }
예제 #4
0
 /**
  * Simple test of the DataTable_Row
  * 
  * @group Core
  * @group DataTable
  */
 public function testSumRow()
 {
     $columns = array('test_int' => 145, 'test_float' => 145.5, 'test_float3' => 1.5, 'test_stringint' => "145", "test" => 'string fake', 'integerArrayToSum' => array(1 => 1, 2 => 10.0, 3 => array(1 => 2, 2 => 3)));
     $metadata = array('logo' => 'piwik.png', 'super' => array('this column has an array value, amazing'));
     $arrayRow = array(Piwik_DataTable_Row::COLUMNS => $columns, Piwik_DataTable_Row::METADATA => $metadata, 'fake useless key' => 38959, 43905724897.0 => 'value');
     $row1 = new Piwik_DataTable_Row($arrayRow);
     $columns2 = array('test_int' => 5, 'test_float' => 4.5, 'test_float2' => 14.5, 'test_stringint' => "5", 00 => 'toto', 'integerArrayToSum' => array(1 => 5, 2 => 5.5, 3 => array(2 => 4)));
     $finalRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
     $finalRow->sumRow($row1);
     $columnsWanted = array('test_int' => 150, 'test_float' => 150.0, 'test_float2' => 14.5, 'test_float3' => 1.5, 'test_stringint' => 150, 'test' => 'string fake', 'integerArrayToSum' => array(1 => 6, 2 => 15.5, 3 => array(1 => 2, 2 => 7)), 00 => 'toto');
     // Also testing that metadata is copied over
     $rowWanted = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columnsWanted, Piwik_DataTable_Row::METADATA => $metadata));
     $this->assertTrue(Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
     // testing that, 'sumRow' does not result in extra unwanted attributes being serialized
     $expectedRow = 'O:19:"Piwik_DataTable_Row":1:{s:1:"c";a:3:{i:0;a:8:{s:8:"test_int";i:150;s:10:"test_float";d:150;s:11:"test_float2";d:14.5;s:14:"test_stringint";i:150;i:0;s:4:"toto";s:17:"integerArrayToSum";a:3:{i:1;i:6;i:2;d:15.5;i:3;a:2:{i:2;i:7;i:1;i:2;}}s:11:"test_float3";d:1.5;s:4:"test";s:11:"string fake";}i:1;a:2:{s:4:"logo";s:9:"piwik.png";s:5:"super";a:1:{i:0;s:39:"this column has an array value, amazing";}}i:3;N;}}';
     $this->assertEquals(serialize($finalRow), $expectedRow);
     // Testing sumRow with disabled metadata sum
     $rowWanted = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columnsWanted));
     // no metadata
     $finalRow = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $columns2));
     $finalRow->sumRow($row1, $enableCopyMetadata = false);
     $this->assertTrue(Piwik_DataTable_Row::isEqual($rowWanted, $finalRow));
 }