isEqual() public static method

Two rows are equal if: - they have exactly the same columns / metadata - they have a subDataTable associated, then we check that both of them are the same. Column order is not important.
public static isEqual ( Row $row1, Row $row2 ) : boolean
$row1 Row first to compare
$row2 Row second to compare
return boolean
コード例 #1
0
ファイル: TruncateTest.php プロジェクト: mgou-net/piwik
 public function testWhenRowsInRandomOrderButSortSpecifiedShouldComputeSummaryRowAfterSort()
 {
     $table = new DataTable();
     $table->addRow($this->getRow3());
     $table->addRow($this->getRow2());
     $table->addRow($this->getRow4());
     $table->addRow($this->getRow1());
     $table->addRow($this->getRow0());
     $filter = new Truncate($table, 2, DataTable::LABEL_SUMMARY_ROW, $columnToSortBy = 'nb');
     $filter->filter($table);
     $this->assertEquals(3, $table->getRowsCount());
     $expectedRow = new Row(array(Row::COLUMNS => array('label' => DataTable::LABEL_SUMMARY_ROW, 'nb' => 111)));
     $this->assertTrue(Row::isEqual($table->getLastRow(), $expectedRow));
 }
コード例 #2
0
ファイル: DataTable.php プロジェクト: piwik/piwik
 /**
  * Returns true if both DataTable instances are exactly the same.
  *
  * DataTables are equal if they have the same number of rows, if
  * each row has a label that exists in the other table, and if each row
  * is equal to the row in the other table with the same label. The order
  * of rows is not important.
  *
  * @param \Piwik\DataTable $table1
  * @param \Piwik\DataTable $table2
  * @return bool
  */
 public static function isEqual(DataTable $table1, DataTable $table2)
 {
     $table1->rebuildIndex();
     $table2->rebuildIndex();
     if ($table1->getRowsCount() != $table2->getRowsCount()) {
         return false;
     }
     $rows1 = $table1->getRows();
     foreach ($rows1 as $row1) {
         $row2 = $table2->getRowFromLabel($row1->getColumn('label'));
         if ($row2 === false || !Row::isEqual($row1, $row2)) {
             return false;
         }
     }
     return true;
 }
コード例 #3
0
 /**
  * Simple test of the DataTable_Row
  */
 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(Row::COLUMNS => $columns, Row::METADATA => $metadata, 'fake useless key' => 38959, '43905724897' => 'value');
     $row1 = new Row($arrayRow);
     $columns2 = array('test_int' => 5, 'test_float' => 4.5, 'test_float2' => 14.5, 'test_stringint' => "5", 925824 => 'toto', 'integerArrayToSum' => array(1 => 5, 2 => 5.5, 3 => array(2 => 4)));
     $finalRow = new Row(array(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)), 925824 => 'toto');
     // Also testing that metadata is copied over
     $rowWanted = new Row(array(Row::COLUMNS => $columnsWanted, Row::METADATA => $metadata));
     $this->assertTrue(Row::isEqual($rowWanted, $finalRow));
     // testing that, 'sumRow' does not result in extra unwanted attributes being serialized
     $expectedRow = '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:925824;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($expectedRow, serialize($finalRow->export()));
     // Testing sumRow with disabled metadata sum
     $rowWanted = new Row(array(Row::COLUMNS => $columnsWanted));
     // no metadata
     $finalRow = new Row(array(Row::COLUMNS => $columns2));
     $finalRow->sumRow($row1, $enableCopyMetadata = false);
     $this->assertTrue(Row::isEqual($rowWanted, $finalRow));
 }