diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2021-05-11 03:28:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 03:28:13 +0300 |
commit | 8366ad8ded026d8e6907a4738be44744c72a0312 (patch) | |
tree | 607f33569ed43e28505ae2260e0b52febc4eed08 | |
parent | 59301c3638c63a49a56f40965ecf50387c6c645f (diff) |
Do not confuse normal rows with the label "-1" w/ the summary row (#17517)
* add failing tests
* do not mistake normal rows w/ labels -1 for summary rows
* try to set a new flag to determine summary row inside Row instead of guessing from the label
* fix tests
* fix test hopefully
* fix another test
* fix another summary row issue
* Add test showing -1 label + Others row.
* apply review feedback
19 files changed, 743 insertions, 48 deletions
diff --git a/core/DataTable.php b/core/DataTable.php index 4a1bc6eebf..e992c9aa3a 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -648,7 +648,7 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess // this takes a lot of time. $row = $tableToSum->getRowFromId(DataTable::ID_SUMMARY_ROW); if ($row) { - $this->aggregateRowWithLabel($row, $columnAggregationOps); + $this->aggregateRow($this->summaryRow, $row, $columnAggregationOps, true); } } } @@ -700,17 +700,20 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess $this->rebuildIndex(); } - if ($label === self::LABEL_SUMMARY_ROW - && !is_null($this->summaryRow) - ) { - return self::ID_SUMMARY_ROW; - } - $label = (string) $label; if (!isset($this->rowsIndexByLabel[$label])) { + // in case label is '-1' and there is no normal row w/ that label. Note: this is for BC since + // in the past, it was possible to get the summary row by searching for the label '-1' + if ($label == self::LABEL_SUMMARY_ROW + && !is_null($this->summaryRow) + ) { + return self::ID_SUMMARY_ROW; + } + return false; } + return $this->rowsIndexByLabel[$label]; } @@ -746,13 +749,6 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess } } - if ($this->summaryRow) { - $label = $this->summaryRow->getColumn('label'); - if ($label !== false) { - $this->rowsIndexByLabel[$label] = DataTable::ID_SUMMARY_ROW; - } - } - $this->indexNotUpToDate = false; } @@ -764,12 +760,13 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess */ public function getRowFromId($id) { + if ($id == self::ID_SUMMARY_ROW + && !is_null($this->summaryRow) + ) { + return $this->summaryRow; + } + if (!isset($this->rows[$id])) { - if ($id == self::ID_SUMMARY_ROW - && !is_null($this->summaryRow) - ) { - return $this->summaryRow; - } return false; } return $this->rows[$id]; @@ -844,16 +841,9 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess public function addSummaryRow(Row $row) { $this->summaryRow = $row; + $row->setIsSummaryRow(); - // add summary row to index - if (!$this->indexNotUpToDate - && $this->rebuildIndexContinuously - ) { - $label = $row->getColumn('label'); - if ($label !== false) { - $this->rowsIndexByLabel[$label] = self::ID_SUMMARY_ROW; - } - } + // NOTE: the summary row does not go in the index, since it will overwrite rows w/ label == -1 return $row; } @@ -1430,8 +1420,10 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess if (array_key_exists(self::ID_SUMMARY_ROW, $rows)) { if (is_array($rows[self::ID_SUMMARY_ROW])) { $this->summaryRow = new Row($rows[self::ID_SUMMARY_ROW]); + $this->summaryRow->setIsSummaryRow(); } elseif (isset($rows[self::ID_SUMMARY_ROW]->c)) { $this->summaryRow = new Row($rows[self::ID_SUMMARY_ROW]->c); // Pre Piwik 2.13 + $this->summaryRow->setIsSummaryRow(); } unset($rows[self::ID_SUMMARY_ROW]); } @@ -1478,6 +1470,7 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess if ($id == self::ID_SUMMARY_ROW) { $this->summaryRow = $row; + $this->summaryRow->setIsSummaryRow(); } else { $this->addRow($row); } @@ -1901,23 +1894,35 @@ class DataTable implements DataTableInterface, \IteratorAggregate, \ArrayAccess throw new Exception($message); } $rowFound = $this->getRowFromLabel($labelToLookFor); - if ($rowFound === false) { - if ($labelToLookFor === self::LABEL_SUMMARY_ROW) { - $this->addSummaryRow($row); + // if we find the summary row in the other table, ignore it, since we're aggregating normal rows in this method. + // the summary row is aggregated explicitly after this method is called. + if (!empty($rowFound) + && $rowFound->isSummaryRow() + ) { + $rowFound = false; + } + $this->aggregateRow($rowFound, $row, $columnAggregationOps, $isSummaryRow = false); + } + + private function aggregateRow($thisRow, Row $otherRow, $columnAggregationOps, $isSummaryRow) + { + if (empty($thisRow)) { + if ($isSummaryRow) { + $this->addSummaryRow($otherRow); } else { - $this->addRow($row); + $this->addRow($otherRow); } } else { - $rowFound->sumRow($row, $copyMeta = true, $columnAggregationOps); + $thisRow->sumRow($otherRow, $copyMeta = true, $columnAggregationOps); // if the row to add has a subtable whereas the current row doesn't // we simply add it (cloning the subtable) // if the row has the subtable already // then we have to recursively sum the subtables - $subTable = $row->getSubtable(); + $subTable = $otherRow->getSubtable(); if ($subTable) { $subTable->metadata[self::COLUMN_AGGREGATION_OPS_METADATA_NAME] = $columnAggregationOps; - $rowFound->sumSubtable($subTable); + $thisRow->sumSubtable($subTable); } } } diff --git a/core/DataTable/Filter/ReplaceSummaryRowLabel.php b/core/DataTable/Filter/ReplaceSummaryRowLabel.php index e5c46be7da..e8257f2aea 100644 --- a/core/DataTable/Filter/ReplaceSummaryRowLabel.php +++ b/core/DataTable/Filter/ReplaceSummaryRowLabel.php @@ -55,11 +55,6 @@ class ReplaceSummaryRowLabel extends BaseFilter $row = $table->getRowFromId(DataTable::ID_SUMMARY_ROW); if ($row) { $row->setColumn('label', $this->newLabel); - } else { - $row = $table->getRowFromLabel(DataTable::LABEL_SUMMARY_ROW); - if ($row) { - $row->setColumn('label', $this->newLabel); - } } // recurse diff --git a/core/DataTable/Row.php b/core/DataTable/Row.php index 3704cd683c..cff5b24bb6 100644 --- a/core/DataTable/Row.php +++ b/core/DataTable/Row.php @@ -33,7 +33,7 @@ class Row extends \ArrayObject * @var array */ private static $unsummableColumns = array( - 'label' => true, + 'label' => true, 'full_url' => true // column used w/ old Piwik versions, ); @@ -48,6 +48,8 @@ class Row extends \ArrayObject */ public $subtableId = null; + private $isSummaryRow = false; + const COLUMNS = 0; const METADATA = 1; const DATATABLE_ASSOCIATED = 3; @@ -406,8 +408,8 @@ class Row extends \ArrayObject * Add many columns to this row. * * @param array $columns Name/Value pairs, e.g., `array('name' => $value , ...)` - * @throws Exception if any column name does not exist. * @return void + * @throws Exception if any column name does not exist. */ public function addColumns($columns) { @@ -557,7 +559,7 @@ class Row extends \ArrayObject // we need to aggregate value before value is overwritten by maybe another row foreach ($aggregationOperations as $column => $operation) { $thisMetadata = $this->getMetadata($column); - $sumMetadata = $rowToSum->getMetadata($column); + $sumMetadata = $rowToSum->getMetadata($column); if ($thisMetadata === false && $sumMetadata === false) { continue; @@ -586,14 +588,18 @@ class Row extends \ArrayObject } /** - * Returns `true` if this row is the summary row, `false` if otherwise. This function - * depends on the label of the row, and so, is not 100% accurate. + * Returns `true` if this row was added to a datatable as the summary row, `false` if otherwise. * * @return bool */ public function isSummaryRow() { - return $this->getColumn('label') === DataTable::LABEL_SUMMARY_ROW; + return $this->isSummaryRow; + } + + public function setIsSummaryRow() + { + $this->isSummaryRow = true; } /** diff --git a/plugins/Actions/ArchivingHelper.php b/plugins/Actions/ArchivingHelper.php index 5f580928a7..597f5c2849 100644 --- a/plugins/Actions/ArchivingHelper.php +++ b/plugins/Actions/ArchivingHelper.php @@ -570,10 +570,12 @@ class ArchivingHelper */ private static function createSummaryRow() { - return new Row(array( + $summaryRow = new Row(array( Row::COLUMNS => array('label' => DataTable::LABEL_SUMMARY_ROW) + self::getDefaultRowColumns() )); + $summaryRow->setIsSummaryRow(); // this should be set in DataTable::addSummaryRow(), but we set it here as well to be safe + return $summaryRow; } private static function splitNameByDelimiter($name, $type) diff --git a/plugins/Referrers/tests/System/expected/test_phpSerialized74__Referrers.getReferrerType_year.original b/plugins/Referrers/tests/System/expected/test_phpSerialized74__Referrers.getReferrerType_year.original index 7dec60397f..bcc5ced235 100644 --- a/plugins/Referrers/tests/System/expected/test_phpSerialized74__Referrers.getReferrerType_year.original +++ b/plugins/Referrers/tests/System/expected/test_phpSerialized74__Referrers.getReferrerType_year.original @@ -1 +1 @@ -O:15:"Piwik\DataTable":4:{s:7:"*rows";a:2:{i:0;O:19:"Piwik\DataTable\Row":3:{i:0;i:0;i:1;a:9:{s:5:"label";s:14:"Search Engines";s:9:"nb_visits";i:31;s:10:"nb_actions";i:31;s:11:"max_actions";d:1;s:16:"sum_visit_length";i:0;s:12:"bounce_count";i:31;s:19:"nb_visits_converted";i:0;s:26:"sum_daily_nb_uniq_visitors";i:31;s:18:"sum_daily_nb_users";i:0;}i:2;a:4:{s:15:"maxVisitsSummed";i:0;s:29:"Piwik\DataTable\Rowmetadata";a:2:{s:7:"segment";s:20:"referrerType==search";s:13:"referrer_type";i:2;}s:37:"Piwik\DataTable\RowisSubtableLoaded";b:0;s:10:"subtableId";N;}}i:1;O:19:"Piwik\DataTable\Row":3:{i:0;i:0;i:1;a:12:{s:5:"label";s:8:"Websites";s:9:"nb_visits";i:31;s:10:"nb_actions";i:31;s:11:"max_actions";d:1;s:16:"sum_visit_length";i:11315;s:12:"bounce_count";i:31;s:19:"nb_visits_converted";i:31;s:5:"goals";a:2:{s:8:"idgoal=1";a:3:{s:14:"nb_conversions";i:31;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}s:8:"idgoal=2";a:3:{s:14:"nb_conversions";i:62;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}}s:14:"nb_conversions";i:93;s:7:"revenue";d:0;s:26:"sum_daily_nb_uniq_visitors";i:31;s:18:"sum_daily_nb_users";i:0;}i:2;a:4:{s:15:"maxVisitsSummed";i:0;s:29:"Piwik\DataTable\Rowmetadata";a:2:{s:7:"segment";s:21:"referrerType==website";s:13:"referrer_type";i:3;}s:37:"Piwik\DataTable\RowisSubtableLoaded";b:0;s:10:"subtableId";N;}}}s:13:"*summaryRow";N;s:11:"*metadata";a:7:{s:11:"ts_archived";s:19:"today-date-removed-in-tests";s:4:"site";O:10:"Piwik\Site":2:{s:5:"*id";i:1;s:16:"Piwik\Sitesite";a:20:{s:6:"idsite";i:1;s:4:"name";s:10:"Piwik test";s:8:"main_url";s:16:"http://piwik.net";s:10:"ts_created";s:19:"2010-01-31 11:22:33";s:9:"ecommerce";i:0;s:10:"sitesearch";i:1;s:29:"sitesearch_keyword_parameters";s:0:"";s:30:"sitesearch_category_parameters";s:0:"";s:8:"timezone";s:3:"UTC";s:8:"currency";s:3:"USD";s:20:"exclude_unknown_urls";i:0;s:12:"excluded_ips";s:0:"";s:19:"excluded_parameters";s:0:"";s:20:"excluded_user_agents";s:0:"";s:5:"group";s:0:"";s:4:"type";s:7:"website";s:17:"keep_url_fragment";i:0;s:13:"creator_login";s:14:"superUserLogin";s:13:"timezone_name";s:3:"UTC";s:13:"currency_name";s:9:"US Dollar";}}s:6:"period";O:17:"Piwik\Period\Year":1:{s:7:"*date";O:10:"Piwik\Date":2:{s:12:"*timestamp";i:1262304000;s:11:"*timezone";s:3:"UTC";}}s:7:"segment";s:0:"";s:13:"segmentPretty";s:10:"All visits";s:6:"totals";a:15:{s:9:"nb_visits";i:62;s:10:"nb_actions";i:62;s:11:"max_actions";d:1;s:16:"sum_visit_length";i:11315;s:12:"bounce_count";i:62;s:19:"nb_visits_converted";i:31;s:26:"sum_daily_nb_uniq_visitors";i:62;s:18:"sum_daily_nb_users";i:0;s:5:"goals";a:2:{s:8:"idgoal=1";a:3:{s:14:"nb_conversions";i:31;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}s:8:"idgoal=2";a:3:{s:14:"nb_conversions";i:62;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}}s:14:"nb_conversions";i:93;s:7:"revenue";d:0;s:15:"conversion_rate";s:3:"50%";s:20:"nb_actions_per_visit";d:1;s:16:"avg_time_on_site";d:183;s:11:"bounce_rate";s:4:"100%";}s:17:"totalsUnformatted";a:15:{s:9:"nb_visits";i:62;s:10:"nb_actions";i:62;s:11:"max_actions";d:1;s:16:"sum_visit_length";i:11315;s:12:"bounce_count";i:62;s:19:"nb_visits_converted";i:31;s:26:"sum_daily_nb_uniq_visitors";i:62;s:18:"sum_daily_nb_users";i:0;s:5:"goals";a:2:{s:8:"idgoal=1";a:3:{s:14:"nb_conversions";i:31;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}s:8:"idgoal=2";a:3:{s:14:"nb_conversions";i:62;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}}s:14:"nb_conversions";i:93;s:7:"revenue";d:0;s:15:"conversion_rate";d:0.5;s:20:"nb_actions_per_visit";d:1;s:16:"avg_time_on_site";d:183;s:11:"bounce_rate";d:1;}}s:12:"*totalsRow";N;}
\ No newline at end of file +O:15:"Piwik\DataTable":4:{s:7:"*rows";a:2:{i:0;O:19:"Piwik\DataTable\Row":3:{i:0;i:0;i:1;a:9:{s:5:"label";s:14:"Search Engines";s:9:"nb_visits";i:31;s:10:"nb_actions";i:31;s:11:"max_actions";d:1;s:16:"sum_visit_length";i:0;s:12:"bounce_count";i:31;s:19:"nb_visits_converted";i:0;s:26:"sum_daily_nb_uniq_visitors";i:31;s:18:"sum_daily_nb_users";i:0;}i:2;a:5:{s:15:"maxVisitsSummed";i:0;s:29:"Piwik\DataTable\Rowmetadata";a:2:{s:7:"segment";s:20:"referrerType==search";s:13:"referrer_type";i:2;}s:37:"Piwik\DataTable\RowisSubtableLoaded";b:0;s:10:"subtableId";N;s:33:"Piwik\DataTable\RowisSummaryRow";b:0;}}i:1;O:19:"Piwik\DataTable\Row":3:{i:0;i:0;i:1;a:12:{s:5:"label";s:8:"Websites";s:9:"nb_visits";i:31;s:10:"nb_actions";i:31;s:11:"max_actions";d:1;s:16:"sum_visit_length";i:11315;s:12:"bounce_count";i:31;s:19:"nb_visits_converted";i:31;s:5:"goals";a:2:{s:8:"idgoal=1";a:3:{s:14:"nb_conversions";i:31;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}s:8:"idgoal=2";a:3:{s:14:"nb_conversions";i:62;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}}s:14:"nb_conversions";i:93;s:7:"revenue";d:0;s:26:"sum_daily_nb_uniq_visitors";i:31;s:18:"sum_daily_nb_users";i:0;}i:2;a:5:{s:15:"maxVisitsSummed";i:0;s:29:"Piwik\DataTable\Rowmetadata";a:2:{s:7:"segment";s:21:"referrerType==website";s:13:"referrer_type";i:3;}s:37:"Piwik\DataTable\RowisSubtableLoaded";b:0;s:10:"subtableId";N;s:33:"Piwik\DataTable\RowisSummaryRow";b:0;}}}s:13:"*summaryRow";N;s:11:"*metadata";a:7:{s:11:"ts_archived";s:19:"today-date-removed-in-tests";s:4:"site";O:10:"Piwik\Site":2:{s:5:"*id";i:1;s:16:"Piwik\Sitesite";a:20:{s:6:"idsite";i:1;s:4:"name";s:10:"Piwik test";s:8:"main_url";s:16:"http://piwik.net";s:10:"ts_created";s:19:"2010-01-31 11:22:33";s:9:"ecommerce";i:0;s:10:"sitesearch";i:1;s:29:"sitesearch_keyword_parameters";s:0:"";s:30:"sitesearch_category_parameters";s:0:"";s:8:"timezone";s:3:"UTC";s:8:"currency";s:3:"USD";s:20:"exclude_unknown_urls";i:0;s:12:"excluded_ips";s:0:"";s:19:"excluded_parameters";s:0:"";s:20:"excluded_user_agents";s:0:"";s:5:"group";s:0:"";s:4:"type";s:7:"website";s:17:"keep_url_fragment";i:0;s:13:"creator_login";s:14:"superUserLogin";s:13:"timezone_name";s:3:"UTC";s:13:"currency_name";s:9:"US Dollar";}}s:6:"period";O:17:"Piwik\Period\Year":1:{s:7:"*date";O:10:"Piwik\Date":2:{s:12:"*timestamp";i:1262304000;s:11:"*timezone";s:3:"UTC";}}s:7:"segment";s:0:"";s:13:"segmentPretty";s:10:"All visits";s:6:"totals";a:15:{s:9:"nb_visits";i:62;s:10:"nb_actions";i:62;s:11:"max_actions";d:1;s:16:"sum_visit_length";i:11315;s:12:"bounce_count";i:62;s:19:"nb_visits_converted";i:31;s:26:"sum_daily_nb_uniq_visitors";i:62;s:18:"sum_daily_nb_users";i:0;s:5:"goals";a:2:{s:8:"idgoal=1";a:3:{s:14:"nb_conversions";i:31;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}s:8:"idgoal=2";a:3:{s:14:"nb_conversions";i:62;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}}s:14:"nb_conversions";i:93;s:7:"revenue";d:0;s:15:"conversion_rate";s:3:"50%";s:20:"nb_actions_per_visit";d:1;s:16:"avg_time_on_site";d:183;s:11:"bounce_rate";s:4:"100%";}s:17:"totalsUnformatted";a:15:{s:9:"nb_visits";i:62;s:10:"nb_actions";i:62;s:11:"max_actions";d:1;s:16:"sum_visit_length";i:11315;s:12:"bounce_count";i:62;s:19:"nb_visits_converted";i:31;s:26:"sum_daily_nb_uniq_visitors";i:62;s:18:"sum_daily_nb_users";i:0;s:5:"goals";a:2:{s:8:"idgoal=1";a:3:{s:14:"nb_conversions";i:31;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}s:8:"idgoal=2";a:3:{s:14:"nb_conversions";i:62;s:19:"nb_visits_converted";i:31;s:7:"revenue";d:0;}}s:14:"nb_conversions";i:93;s:7:"revenue";d:0;s:15:"conversion_rate";d:0.5;s:20:"nb_actions_per_visit";d:1;s:16:"avg_time_on_site";d:183;s:11:"bounce_rate";d:1;}}s:12:"*totalsRow";N;}
\ No newline at end of file diff --git a/plugins/Referrers/tests/System/expected/test_phpSerialized__Referrers.getReferrerType_year.original b/plugins/Referrers/tests/System/expected/test_phpSerialized__Referrers.getReferrerType_year.original Binary files differindex 0177566092..861bf264b3 100644 --- a/plugins/Referrers/tests/System/expected/test_phpSerialized__Referrers.getReferrerType_year.original +++ b/plugins/Referrers/tests/System/expected/test_phpSerialized__Referrers.getReferrerType_year.original diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php b/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php index e279138dd8..1ef910065c 100644 --- a/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php +++ b/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php @@ -39,6 +39,7 @@ class ManyVisitsWithMockLocationProvider extends Fixture $this->setMockLocationProvider(); $this->trackVisits(); + $this->trackVisitsForNegativeOneRowAndSummary(); ManyVisitsWithGeoIP::unsetLocationProvider(); } @@ -55,6 +56,23 @@ class ManyVisitsWithMockLocationProvider extends Fixture } } + private function trackVisitsForNegativeOneRowAndSummary() + { + $t = self::getTracker($this->idSite, '2015-02-03 00:00:00'); + $t->enableBulkTracking(); + + $t->setUrl('http://piwik.net/page'); + $t->doTrackEvent('-1', '-1', '-1'); + + for ($i = 0; $i != 20; ++$i) { + $t->setUrl('http://piwik.net/page'); + $t->setIp('120.34.5.' . $i); + $t->doTrackEvent('event category ' . $i, 'event action ' . $i, 'event name ' . $i); + } + + Fixture::checkBulkTrackingResponse($t->doBulkTrack()); + } + private function trackVisits() { $linuxFirefoxA = "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0"; diff --git a/tests/PHPUnit/Integration/ArchiveProcessingTest.php b/tests/PHPUnit/Integration/ArchiveProcessingTest.php index b1df5a98a9..b5fad41104 100644 --- a/tests/PHPUnit/Integration/ArchiveProcessingTest.php +++ b/tests/PHPUnit/Integration/ArchiveProcessingTest.php @@ -635,6 +635,79 @@ END; $this->assertEquals(ArchiveWriter::DONE_PARTIAL, $archiveDoneFlag); } + public function test_aggregateDataTableRecords_handlesNegativeOneLabels() + { + $table1 = new DataTable(); + $table1->addRowsFromSimpleArray([ + ['label' => 'a', 'nb_visits' => 5, 'nb_actions' => 1], + ['label' => '-1', 'nb_visits' => 3, 'nb_actions' => 1], + ]); + $table1->addSummaryRow(new DataTable\Row([ + DataTable\Row::COLUMNS => ['label' => -1, 'nb_visits' => 10, 'nb_actions' => 15], + ])); + $table2 = new DataTable(); + $table2->addRowsFromSimpleArray([ + ['label' => 'a', 'nb_visits' => 2, 'nb_actions' => 2], + ['label' => -1, 'nb_visits' => 9, 'nb_actions' => 5], + ]); + $table2->addSummaryRow(new DataTable\Row([ + DataTable\Row::COLUMNS => ['label' => -1, 'nb_visits' => 15, 'nb_actions' => 25], + ])); + + $tables = [ + '2015-02-03' => $table1, + '2015-02-04' => $table2, + ]; + + $site = $this->_createWebsite('UTC'); + + foreach ($tables as $date => $table) { + /** @var ArchiveWriter $archiveWriter */ + list($archiveProcessor, $archiveWriter) = $this->_createArchiveProcessorInst('day', $date, $site->getId()); + $archiveWriter->initNewArchive(); + + $tableSerialized = $table->getSerialized(); + $archiveProcessor->insertBlobRecord('Actions_test_value', $tableSerialized); + + $archiveWriter->finalizeArchive(); + } + + list($archiveProcessor, $archiveWriter) = $this->_createArchiveProcessorInst('week', '2015-02-03', $site->getId()); + $archiveWriter->initNewArchive(); + + $archiveProcessor->captureInserts(); + $archiveProcessor->aggregateDataTableRecords('Actions_test_value'); + + $archiveWriter->finalizeArchive(); + + $capturedInserts = $archiveProcessor->getCapturedInserts(); + $capturedInsertTable = DataTable::fromSerializedArray($capturedInserts[0][1][0]); + $capturedInsertTable = $this->getXml($capturedInsertTable); + + $expectedXml = <<<END +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>a</label> + <nb_visits>7</nb_visits> + <nb_actions>3</nb_actions> + </row> + <row> + <label>-1</label> + <nb_visits>12</nb_visits> + <nb_actions>6</nb_actions> + </row> + <row> + <label>-1</label> + <nb_visits>25</nb_visits> + <nb_actions>40</nb_actions> + </row> +</result> +END; + + $this->assertEquals($expectedXml, $capturedInsertTable); + } + protected function _checkTableIsExpected($table, $data) { $fetched = Db::fetchAll('SELECT * FROM ' . $table); diff --git a/tests/PHPUnit/System/BlobReportLimitingTest.php b/tests/PHPUnit/System/BlobReportLimitingTest.php index 9f1f5fa717..666ec84ea2 100644 --- a/tests/PHPUnit/System/BlobReportLimitingTest.php +++ b/tests/PHPUnit/System/BlobReportLimitingTest.php @@ -87,6 +87,13 @@ class BlobReportLimitingTest extends SystemTestCase 'xmlFieldsToRemove' => ['label', 'segment', 'url', 'exit_nb_visits', 'exit_rate', 'bounce_count', 'bounce_rate'], ), ), + + ['Events', [ + 'idSite' => 1, + 'date' => '2015-02-03', + 'period' => ['day'], + 'testSuffix' => 'withNegOneLabel_', + ]], ); } diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getAction_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getAction_day.xml new file mode 100644 index 0000000000..cd2e176bea --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getAction_day.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventAction==-1</segment> + <subtable> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>event action 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventAction==event+action+0</segment> + <subtable> + <row> + <label>event name 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>Others</label> + <nb_uniq_visitors>19</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getCategory_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getCategory_day.xml new file mode 100644 index 0000000000..135998e73f --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getCategory_day.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventCategory==-1</segment> + <subtable> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>event category 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventCategory==event+category+0</segment> + <subtable> + <row> + <label>event action 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>Others</label> + <nb_uniq_visitors>19</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getName_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getName_day.xml new file mode 100644 index 0000000000..9f4a5318dc --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel___Events.getName_day.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventName==-1</segment> + <subtable> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>event name 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventName==event+name+0</segment> + <subtable> + <row> + <label>event action 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>Others</label> + <nb_uniq_visitors>19</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getAction_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getAction_day.xml new file mode 100644 index 0000000000..07a0d6c515 --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getAction_day.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>Others</label> + <nb_uniq_visitors>19</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <is_summary>1</is_summary> + <Events_EventAction>Others</Events_EventAction> + </row> + <row> + <label>-1 - -1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <Events_EventAction>-1</Events_EventAction> + <Events_EventName>-1</Events_EventName> + </row> + <row> + <label>event action 0 - event name 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <Events_EventAction>event action 0</Events_EventAction> + <Events_EventName>event name 0</Events_EventName> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getCategory_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getCategory_day.xml new file mode 100644 index 0000000000..3a6b3be7f1 --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getCategory_day.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>Others</label> + <nb_uniq_visitors>19</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <is_summary>1</is_summary> + <Events_EventCategory>Others</Events_EventCategory> + </row> + <row> + <label>-1 - -1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <Events_EventCategory>-1</Events_EventCategory> + <Events_EventAction>-1</Events_EventAction> + </row> + <row> + <label>event category 0 - event action 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <Events_EventCategory>event category 0</Events_EventCategory> + <Events_EventAction>event action 0</Events_EventAction> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getName_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getName_day.xml new file mode 100644 index 0000000000..c61d47a9d6 --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__flattened__Events.getName_day.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>Others</label> + <nb_uniq_visitors>19</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <is_summary>1</is_summary> + <Events_EventName>Others</Events_EventName> + </row> + <row> + <label>-1 - -1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <Events_EventName>-1</Events_EventName> + <Events_EventAction>-1</Events_EventAction> + </row> + <row> + <label>event name 0 - event action 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <Events_EventName>event name 0</Events_EventName> + <Events_EventAction>event action 0</Events_EventAction> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getAction_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getAction_day.xml new file mode 100644 index 0000000000..77f8fc302f --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getAction_day.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventAction==-1</segment> + <subtable> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>event action 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventAction==event+action+0</segment> + <subtable> + <row> + <label>event name 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>Others</label> + <nb_uniq_visitors>3</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getCategory_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getCategory_day.xml new file mode 100644 index 0000000000..980dbf0267 --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getCategory_day.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventCategory==-1</segment> + <subtable> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>event category 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventCategory==event+category+0</segment> + <subtable> + <row> + <label>event action 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>Others</label> + <nb_uniq_visitors>3</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getName_day.xml b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getName_day.xml new file mode 100644 index 0000000000..8e12635faa --- /dev/null +++ b/tests/PHPUnit/System/expected/test_reportLimitingwithNegOneLabel__rankingQuery__Events.getName_day.xml @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventName==-1</segment> + <subtable> + <row> + <label>-1</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>event name 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + <segment>eventName==event+name+0</segment> + <subtable> + <row> + <label>event action 0</label> + <nb_uniq_visitors>1</nb_uniq_visitors> + <nb_visits>1</nb_visits> + <nb_events>1</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> + </subtable> + </row> + <row> + <label>Others</label> + <nb_uniq_visitors>3</nb_uniq_visitors> + <nb_visits>19</nb_visits> + <nb_events>19</nb_events> + <nb_events_with_value>0</nb_events_with_value> + <sum_event_value>0</sum_event_value> + <min_event_value>0</min_event_value> + <max_event_value>0</max_event_value> + <avg_event_value>0</avg_event_value> + </row> +</result>
\ No newline at end of file diff --git a/tests/PHPUnit/Unit/DataTableTest.php b/tests/PHPUnit/Unit/DataTableTest.php index 22adb1abe2..8e8d18c823 100644 --- a/tests/PHPUnit/Unit/DataTableTest.php +++ b/tests/PHPUnit/Unit/DataTableTest.php @@ -935,6 +935,85 @@ class DataTableTest extends \PHPUnit\Framework\TestCase $this->assertTrue(DataTable::isEqual($table, $tableExpected)); } + public function test_addDataTable_whenThereIsNoSummaryRowInOneTable_andASummaryRowInTheOtherTable() + { + $table1 = new DataTable(); + $table1->addRowsFromSimpleArray([ + ['label' => 'a', 'value' => 5], + ]); + $table1->addSummaryRow(new Row([ + Row::COLUMNS => [ + 'label' => DataTable::LABEL_SUMMARY_ROW, + 'value' => 15, + ], + ])); + + $table2 = new DataTable(); + $table2->addRowsFromSimpleArray([ + ['label' => 'a', 'value' => 10], + ['label' => -1, 'value' => 30], + ]); + $table2->addSummaryRow(new Row([ + Row::COLUMNS => [ + 'label' => DataTable::LABEL_SUMMARY_ROW, + 'value' => 5, + ], + ])); + + $table1->addDataTable($table2); + + $expectedRows = [ + 0 => ['label' => 'a', 'value' => 15], + 1 => ['label' => -1, 'value' => 30], + DataTable::ID_SUMMARY_ROW => ['label' => -1, 'value' => 20], + ]; + + $actualRows = $table1->getRows(); + $actualRows = array_map(function (Row $r) { return $r->getColumns(); }, $actualRows); + + $this->assertEquals($expectedRows, $actualRows); + } + + public function test_addDataTable_whenThereIsASummaryRow_andRowWithNegativeOneLabel() + { + $table1 = new DataTable(); + $table1->addRowsFromSimpleArray([ + ['label' => 'a', 'value' => 5], + ['label' => '-1', 'value' => 20], + ]); + $table1->addSummaryRow(new Row([ + Row::COLUMNS => [ + 'label' => DataTable::LABEL_SUMMARY_ROW, + 'value' => 15, + ], + ])); + + $table2 = new DataTable(); + $table2->addRowsFromSimpleArray([ + ['label' => 'a', 'value' => 10], + ['label' => -1, 'value' => 30], + ]); + $table2->addSummaryRow(new Row([ + Row::COLUMNS => [ + 'label' => DataTable::LABEL_SUMMARY_ROW, + 'value' => 5, + ], + ])); + + $table1->addDataTable($table2); + + $expectedRows = [ + 0 => ['label' => 'a', 'value' => 15], + 1 => ['label' => -1, 'value' => 50], + DataTable::ID_SUMMARY_ROW => ['label' => -1, 'value' => 20], + ]; + + $actualRows = $table1->getRows(); + $actualRows = array_map(function (Row $r) { return $r->getColumns(); }, $actualRows); + + $this->assertEquals($expectedRows, $actualRows); + } + public function testUnrelatedDataTableNotDestructed() { $mockedDataTable = $this->createPartialMock('\Piwik\DataTable', array('__destruct')); |