diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2008-06-09 05:59:24 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2008-06-09 05:59:24 +0400 |
commit | 7fa9c3d3a77d6a0c15e8a3b485640927c51b7222 (patch) | |
tree | 04fd4bfce63f036fc1e94e48b8a5058d9f35d5a4 | |
parent | eb2775aa7ddf67086bd5a05d47c6e4e914f97451 (diff) |
- fixing bug in sum algorithm when there is a summary row.
22 files changed, 139 insertions, 147 deletions
diff --git a/modules/DataTable.php b/modules/DataTable.php index 7ce64d6b95..bcd7f86581 100644 --- a/modules/DataTable.php +++ b/modules/DataTable.php @@ -14,13 +14,9 @@ require_once "DataTable/Renderer/Console.php"; require_once "DataTable/Filter.php"; require_once "DataTable/Row.php"; require_once "DataTable/Manager.php"; + /** * - * Initial Specification - * --------------------------------------------------------- - * CAREFUL: It may be outdated as I have not reviewed it yet - * --------------------------------------------------------- - * * ---- DataTable * A DataTable is a data structure used to store complex tables of data. * @@ -37,8 +33,8 @@ require_once "DataTable/Manager.php"; * ---- DataTable_Row * A DataTableRow in the table is defined by * - multiple columns (a label, multiple values, ...) - * - metadata - * - [a sub DataTable associated to this row] + * - optional metadata + * - optional - a sub DataTable associated to this row * * Simple row example: * - columns = array( 'label' => 'Firefox', @@ -121,6 +117,20 @@ require_once "DataTable/Manager.php"; * $XMLstring = $xmlOutput->getOutput(); * * + * ---- Other (ideas) + * We can also imagine building a DataTable_Compare which would take 2 DataTable that have the same + * structure and would compare them, by computing the percentages of differences, etc. + * + * For example + * DataTable1 = [ keyword1, 1550 visits] + * [ keyword2, 154 visits ] + * DataTable2 = [ keyword1, 1004 visits ] + * [ keyword3, 659 visits ] + * DataTable_Compare = result of comparison of table1 with table2 + * [ keyword1, +154% ] + * [ keyword2, +1000% ] + * [ keyword3, -430% ] + * * @see Piwik_DataTable_Row A Piwik_DataTable is composed of Piwik_DataTable_Row * * @package Piwik @@ -323,11 +333,16 @@ class Piwik_DataTable { $labelToLookFor = $row->getColumn('label'); $rowFound = $this->getRowFromLabel( $labelToLookFor ); - - // the row with this label not found if($rowFound === false) { - $this->addRow( $row ); + if( $labelToLookFor === self::LABEL_SUMMARY_ROW ) + { + $this->addSummaryRow($row ); + } + else + { + $this->addRow( $row ); + } } else { @@ -388,7 +403,6 @@ class Piwik_DataTable $this->rowsIndexByLabel[$label] = $id; } } - $this->indexNotUpToDate = false; } @@ -423,6 +437,11 @@ class Piwik_DataTable $this->indexNotUpToDate = true; } + /** + * Sets the summary row (a dataTable can have only one summary row) + * + * @param Piwik_DataTable_Row $row + */ public function addSummaryRow( Piwik_DataTable_Row $row ) { $this->summaryRow = $row; @@ -982,39 +1001,17 @@ class Piwik_DataTable { $cleanRow[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $subtablePerLabel[$label]; } - $this->addRow( new Piwik_DataTable_Row($cleanRow) ); } } - - /** * At destruction we try to free memory * But php doesn't give us much control on this */ public function __destruct() { -// static $c = 0; -// $c++; -// echo " k ".$this->getId(); unset($this->rows); } } - -/** - * ---- Other - * We can also imagine building a DataTable_Compare which would take 2 DataTable that have the same - * structure and would compare them, by computing the percentages of differences, etc. - * - * For example - * DataTable1 = [ keyword1, 1550 visits] - * [ keyword2, 154 visits ] - * DataTable2 = [ keyword1, 1004 visits ] - * [ keyword3, 659 visits ] - * DataTable_Compare = result of comparison of table1 with table2 - * [ keyword1, +154% ] - * [ keyword2, +1000% ] - * [ keyword3, -430% ] - */ diff --git a/modules/DataTable/Filter.php b/modules/DataTable/Filter.php index 95155bdda2..a017d57e77 100644 --- a/modules/DataTable/Filter.php +++ b/modules/DataTable/Filter.php @@ -55,3 +55,4 @@ require_once "DataTable/Filter/PatternRecursive.php"; require_once "DataTable/Filter/ReplaceColumnNames.php"; require_once "DataTable/Filter/Sort.php"; require_once "DataTable/Filter/AddSummaryRow.php"; +require_once "DataTable/Filter/ReplaceSummaryRowLabel.php"; diff --git a/modules/DataTable/Filter/AddConstantMetadata.php b/modules/DataTable/Filter/AddConstantMetadata.php index 9d2f008b4b..33c573120b 100644 --- a/modules/DataTable/Filter/AddConstantMetadata.php +++ b/modules/DataTable/Filter/AddConstantMetadata.php @@ -24,7 +24,6 @@ class Piwik_DataTable_Filter_AddConstantMetadata extends Piwik_DataTable_Filter private $functionToApply; private $metadataToAdd; - public function __construct( $table, $metadataName, $metadataValue ) { parent::__construct($table); diff --git a/modules/DataTable/Filter/AddSummaryRow.php b/modules/DataTable/Filter/AddSummaryRow.php index a0916c5dd5..10d607dbac 100644 --- a/modules/DataTable/Filter/AddSummaryRow.php +++ b/modules/DataTable/Filter/AddSummaryRow.php @@ -1,32 +1,32 @@ <?php /** * Piwik - Open source web analytics - * + * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later * @version $Id: Limit.php 168 2008-01-14 05:26:43Z matt $ - * + * * @package Piwik_DataTable */ /** - * Add a new row to the table containing a summary + * Add a new row to the table containing a summary * of the rows from StartRowToSummarize to EndRowToSummarize. * It then deletes the rows from StartRowToSummarize to EndRowToSummarize. * The new row created has a label = 'other' - * - * This filter is useful to build a more compact view of a table, + * + * This filter is useful to build a more compact view of a table, * keeping the first records unchanged. - * - * For example we use this for the pie chart, to build the last pie part - * which is the sum of all the remaining data after the top 5 data. + * + * For example we use this for the pie chart, to build the last pie part + * which is the sum of all the remaining data after the top 5 data. * This row is assigned a label of 'Others'. - * + * * @package Piwik_DataTable - * @subpackage Piwik_DataTable_Filter + * @subpackage Piwik_DataTable_Filter */ class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter -{ +{ public $labelSummaryRow = Piwik_DataTable::LABEL_SUMMARY_ROW; public function __construct( $table, $startRowToSummarize, $columnToSortByBeforeTruncating = Piwik_Archive::INDEX_NB_VISITS ) @@ -34,7 +34,7 @@ class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter parent::__construct($table); $this->startRowToSummarize = $startRowToSummarize; $this->columnToSortByBeforeTruncating = $columnToSortByBeforeTruncating; - + if($table->getRowsCount() > $startRowToSummarize + 1) { $this->filter(); @@ -54,14 +54,14 @@ class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter { // case when the last row is a summary row, it is not indexed by $cout but by Piwik_DataTable::ID_SUMMARY_ROW $summaryRow = $this->table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW); - $newRow->sumRow($summaryRow); + $newRow->sumRow($summaryRow); } else { $newRow->sumRow($rows[$i]); } } - $newRow->addColumn('label',$this->labelSummaryRow); + $newRow->addColumn('label', $this->labelSummaryRow); $filter = new Piwik_DataTable_Filter_Limit($this->table, 0, $this->startRowToSummarize); $this->table->addSummaryRow($newRow); } diff --git a/modules/DataTable/Filter/ExcludeLowPopulation.php b/modules/DataTable/Filter/ExcludeLowPopulation.php index 7523bcd293..7e20776a46 100644 --- a/modules/DataTable/Filter/ExcludeLowPopulation.php +++ b/modules/DataTable/Filter/ExcludeLowPopulation.php @@ -40,7 +40,6 @@ class Piwik_DataTable_Filter_ExcludeLowPopulation extends Piwik_DataTable_Filter $this->columnToFilter, $function ); - } static public function excludeLowPopulation($value) diff --git a/modules/DataTable/Filter/PatternRecursive.php b/modules/DataTable/Filter/PatternRecursive.php index d242985785..1faf36a5de 100644 --- a/modules/DataTable/Filter/PatternRecursive.php +++ b/modules/DataTable/Filter/PatternRecursive.php @@ -31,7 +31,6 @@ class Piwik_DataTable_Filter_PatternRecursive extends Piwik_DataTable_Filter $this->patternToSearch = $patternToSearch;//preg_quote($patternToSearch); $this->columnToFilter = $columnToFilter; $this->filter(); -// echo $this->table; exit; } protected function filter( $table = null ) diff --git a/modules/DataTable/Filter/ReplaceColumnNames.php b/modules/DataTable/Filter/ReplaceColumnNames.php index bbe3a06df3..0580c3d3c8 100644 --- a/modules/DataTable/Filter/ReplaceColumnNames.php +++ b/modules/DataTable/Filter/ReplaceColumnNames.php @@ -27,7 +27,7 @@ class Piwik_DataTable_Filter_ReplaceColumnNames extends Piwik_DataTable_Filter { /* - * old column name => new column name + * Old column name => new column name */ protected $mappingToApply = array( Piwik_Archive::INDEX_NB_UNIQ_VISITORS => 'nb_uniq_visitors', diff --git a/modules/DataTable/Filter/ReplaceSummaryRowLabel.php b/modules/DataTable/Filter/ReplaceSummaryRowLabel.php new file mode 100644 index 0000000000..ed3b627ddc --- /dev/null +++ b/modules/DataTable/Filter/ReplaceSummaryRowLabel.php @@ -0,0 +1,42 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later + * @version $Id: ReplaceColumnNames.php 482 2008-05-18 17:22:35Z matt $ + * + * @package Piwik_DataTable + */ + +/** + * + * @package Piwik_DataTable + * @subpackage Piwik_DataTable_Filter + */ +class Piwik_DataTable_Filter_ReplaceSummaryRowLabel extends Piwik_DataTable_Filter +{ + public function __construct( $table, $newLabel = null) + { + parent::__construct($table); + if(is_null($newLabel)) + { + $newLabel = Piwik_Translate('General_Others'); + } + $this->newLabel = $newLabel; + $this->filter(); + } + + protected function filter() + { + foreach($this->table->getRows() as $row) + { + if($row->getColumn('label') === Piwik_DataTable::LABEL_SUMMARY_ROW) + { + $row->setColumn('label', $this->newLabel); + break; + } + } + } +} + diff --git a/modules/DataTable/Filter/Sort.php b/modules/DataTable/Filter/Sort.php index 2807d46733..764c050690 100644 --- a/modules/DataTable/Filter/Sort.php +++ b/modules/DataTable/Filter/Sort.php @@ -106,7 +106,6 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter } else { - if($this->naturalSort) { $methodToUse = "naturalSort"; @@ -115,9 +114,7 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter { $methodToUse = "sortString"; } - } - $this->table->sort( array($this,$methodToUse) ); } } diff --git a/modules/DataTable/Manager.php b/modules/DataTable/Manager.php index 3ef7a0e748..683c35f844 100644 --- a/modules/DataTable/Manager.php +++ b/modules/DataTable/Manager.php @@ -19,9 +19,6 @@ class Piwik_DataTable_Manager { static private $instance = null; - protected function __construct() - {} - /** * Returns instance * @@ -36,6 +33,7 @@ class Piwik_DataTable_Manager } return self::$instance; } + /** * Array used to store the DataTable * @@ -84,7 +82,6 @@ class Piwik_DataTable_Manager public function deleteTable( $id ) { -// echo "d $id ; "; if(isset($this->tables[$id])) { $this->tables[$id] = null; diff --git a/modules/DataTable/Renderer.php b/modules/DataTable/Renderer.php index 7478c623f6..4d68d8be3e 100644 --- a/modules/DataTable/Renderer.php +++ b/modules/DataTable/Renderer.php @@ -90,8 +90,7 @@ abstract class Piwik_DataTable_Renderer $className = 'Piwik_DataTable_Renderer_' . $name; if( Piwik_Common::isValidFilename($name) - && Zend_Loader::isReadable($path) - ) + && Zend_Loader::isReadable($path) ) { require_once $path; return new $className; diff --git a/modules/DataTable/Renderer/Csv.php b/modules/DataTable/Renderer/Csv.php index 1fda15e17b..886c29c7b0 100644 --- a/modules/DataTable/Renderer/Csv.php +++ b/modules/DataTable/Renderer/Csv.php @@ -56,12 +56,9 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer */ public $exportIdSubtable = true; - function __construct($table = null) { parent::__construct($table); - - } function render() @@ -71,7 +68,6 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer protected function renderTable($table) { - if($table instanceof Piwik_DataTable_Array) { $str = $header = ''; @@ -97,7 +93,6 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer $str .= "\n" . implode("\n", $returned); } } -// var_dump($header);exit; if(!empty($header)) { $str = $prefixColumns . $header . $str; diff --git a/modules/DataTable/Renderer/Html.php b/modules/DataTable/Renderer/Html.php index 202077abd7..84bab607c3 100644 --- a/modules/DataTable/Renderer/Html.php +++ b/modules/DataTable/Renderer/Html.php @@ -47,13 +47,11 @@ class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer { $out = $this->renderDataTable($table); } - return $out; } protected function renderDataTable($table) { - if($table->getRowsCount() == 0) { return "<b><i>Empty table</i></b> <br>\n"; @@ -78,7 +76,6 @@ class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer * subtable here */ $allColumns = array(); -// echo $table; foreach($table->getRows() as $row) { foreach($row->getColumns() as $column => $value) @@ -122,15 +119,6 @@ class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer $i++; } - /* - // to keep the same columns order as the columns labelled with strings - ksort($allColumns); - //replace the label first - if(isset($allColumns['label'])) - { - $allColumns = array_merge(array('label'=>true),$allColumns); - } - */ $allColumns['_metadata'] = $someMetadata; $allColumns['_idSubtable'] = $someIdSubTable; $html = "\n"; @@ -169,7 +157,6 @@ class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer if(isset($row['_subtable'])) { -// echo ".".$row['_subtable'];exit; $html .= "<tr> <td class=l{$row['_subtable']['depth']} colspan=$colspan>{$row['_subtable']['html']}</td></tr>"; } diff --git a/modules/DataTable/Renderer/Php.php b/modules/DataTable/Renderer/Php.php index 5a6b47686e..c23fa0f176 100644 --- a/modules/DataTable/Renderer/Php.php +++ b/modules/DataTable/Renderer/Php.php @@ -160,7 +160,6 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer { $array = serialize($array); } - return $array; } @@ -195,12 +194,10 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer protected function renderSimpleTable($table) { $array = array(); - foreach($table->getRows() as $row) { $array[$row->getColumn('label')] = $row->getColumn('value'); } - return $array; } }
\ No newline at end of file diff --git a/modules/DataTable/Renderer/Rss.php b/modules/DataTable/Renderer/Rss.php index 7524572572..a6511db583 100644 --- a/modules/DataTable/Renderer/Rss.php +++ b/modules/DataTable/Renderer/Rss.php @@ -121,7 +121,6 @@ class Piwik_DataTable_Renderer_Rss extends Piwik_DataTable_Renderer * subtable here */ $allColumns = array(); -// echo $table; foreach($table->getRows() as $row) { foreach($row->getColumns() as $column => $value) @@ -131,16 +130,6 @@ class Piwik_DataTable_Renderer_Rss extends Piwik_DataTable_Renderer } $i++; } - - /* - // to keep the same columns order as the columns labelled with strings - ksort($allColumns); - //replace the label first - if(isset($allColumns['label'])) - { - $allColumns = array_merge(array('label'=>true),$allColumns); - } - */ $html = "\n"; $html .= "<table border=1 width=70%>"; $html .= "\n<tr>"; @@ -174,10 +163,7 @@ class Piwik_DataTable_Renderer_Rss extends Piwik_DataTable_Renderer } $html .= "\n\n</table>"; - return $html; } } - - diff --git a/modules/DataTable/Renderer/Xml.php b/modules/DataTable/Renderer/Xml.php index 1200caadec..49521fd5bd 100644 --- a/modules/DataTable/Renderer/Xml.php +++ b/modules/DataTable/Renderer/Xml.php @@ -42,7 +42,6 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer { $array = $this->getArrayFromDataTable($table); - // case DataTable_Array if($table instanceof Piwik_DataTable_Array) { $out = $this->renderDataTableArray($table, $array, $prefixLines); @@ -75,7 +74,6 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer { $out = $array; } - if($returnOnlyDataTableXml) { return $out; @@ -156,7 +154,6 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer $nameDescriptionAttribute = $table->getKeyName(); foreach($array as $valueAttribute => $dataTableSimple) { -// var_dump($dataTableSimple);exit; if(count($dataTableSimple) == 0) { $xml .= $prefixLines . "\t<result $nameDescriptionAttribute=\"$valueAttribute\" />\n"; @@ -205,7 +202,6 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer $nameDescriptionAttribute = $table->getKeyName(); foreach($array as $keyName => $arrayForSingleDate) { -// var_dump($arrayForSingleDate);exit; $dataTableOut = $this->renderDataTable( $arrayForSingleDate, $prefixLines . "\t" ); if(empty($dataTableOut)) { diff --git a/modules/DataTable/Row.php b/modules/DataTable/Row.php index 3e439856c5..9ee3bfc9c6 100644 --- a/modules/DataTable/Row.php +++ b/modules/DataTable/Row.php @@ -402,4 +402,3 @@ class Piwik_DataTable_Row } require_once "Row/DataTableSummary.php"; - diff --git a/modules/DataTable/Row/DataTableSummary.php b/modules/DataTable/Row/DataTableSummary.php index 011014bd1b..b6d6e54785 100644 --- a/modules/DataTable/Row/DataTableSummary.php +++ b/modules/DataTable/Row/DataTableSummary.php @@ -31,4 +31,3 @@ class Piwik_DataTable_Row_DataTableSummary extends Piwik_DataTable_Row } } } - diff --git a/modules/DataTable/Simple.php b/modules/DataTable/Simple.php index 08e5d0f0d0..04cbb53c70 100644 --- a/modules/DataTable/Simple.php +++ b/modules/DataTable/Simple.php @@ -59,5 +59,3 @@ class Piwik_DataTable_Simple extends Piwik_DataTable return $row->getColumn('value'); } } - - diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php index d76ac5d51f..3a8dc15219 100644 --- a/plugins/Actions/API.php +++ b/plugins/Actions/API.php @@ -49,7 +49,8 @@ class Piwik_Actions_API extends Piwik_Apiable else
{
$dataTable = $archive->getDataTable($name, $idSubtable);
- }
+ } + $dataTable->queueFilter('Piwik_DataTable_Filter_ReplaceSummaryRowLabel');
return $dataTable;
}
diff --git a/plugins/Referers/API.php b/plugins/Referers/API.php index 040c80daa8..65ab321fe1 100644 --- a/plugins/Referers/API.php +++ b/plugins/Referers/API.php @@ -42,6 +42,7 @@ class Piwik_Referers_API extends Piwik_Apiable $dataTable = $archive->getDataTable($name, $idSubtable); } $dataTable->queueFilter('Piwik_DataTable_Filter_ReplaceColumnNames'); + $dataTable->queueFilter('Piwik_DataTable_Filter_ReplaceSummaryRowLabel'); return $dataTable; } diff --git a/tests/modules/DataTable.test.php b/tests/modules/DataTable.test.php index 0ccca2f2ab..f8f921eba2 100644 --- a/tests/modules/DataTable.test.php +++ b/tests/modules/DataTable.test.php @@ -729,48 +729,6 @@ class Test_Piwik_DataTable extends UnitTestCase $this->assertTrue( Piwik_DataTable::isEqual($table1, $tableExpected) ); } - protected function getDataTable1ForTest() - { - $idcol = Piwik_DataTable_Row::COLUMNS; - - $rows = array( - array( $idcol => array('label'=>'google', 'visits' => 1)), - array( $idcol => array('label'=>'ask', 'visits' => 2)), - array( $idcol => array('label'=>'123', 'visits' => 2)), - ); - $table = new Piwik_DataTable; - $table->loadFromArray( $rows ); - return $table; - } - - protected function getDataTable2ForTest() - { - $rows = $this->getRowsDataTable2ForTest(); - $table = new Piwik_DataTable; - $table->loadFromArray( $rows ); - return $table; - } - - protected function getRowsDataTable2ForTest() - { - $rows = array( - array( Piwik_DataTable_Row::COLUMNS => array('label'=>'test', 'visits' => 1)), - array( Piwik_DataTable_Row::COLUMNS => array('label'=>' google ', 'visits' => 3)), - array( Piwik_DataTable_Row::COLUMNS => array('label'=>'123a', 'visits' => 2)), - ); - return $rows; - } - - protected function getRowsDataTable1ForTest() - { - $rows = array( - array( Piwik_DataTable_Row::COLUMNS => array('label'=>'google', 'visits' => 1)), - array( Piwik_DataTable_Row::COLUMNS => array('label'=>'ask', 'visits' => 2)), - array( Piwik_DataTable_Row::COLUMNS => array('label'=>'123', 'visits' => 2)), - ); - return $rows; - } - /** * add 2 datatable with some common rows */ @@ -783,6 +741,7 @@ class Test_Piwik_DataTable extends UnitTestCase array( $idcol => array('label'=>'google', 'visits' => 1)), array( $idcol => array('label'=>'ask', 'visits' => 2)), array( $idcol => array('label'=>'123', 'visits' => 2)), + Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7)) ); $table = new Piwik_DataTable; $table->loadFromArray( $rows ); @@ -805,6 +764,7 @@ class Test_Piwik_DataTable extends UnitTestCase array( $idcol => array('label'=>'123', 'visits' => 4)), array( $idcol => array('label'=>'test', 'visits' => 1)), array( $idcol => array('label'=>' google ', 'visits' => 5)), + Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7)) ); $tableExpected = new Piwik_DataTable; $tableExpected->loadFromArray( $rowsExpected ); @@ -823,6 +783,7 @@ class Test_Piwik_DataTable extends UnitTestCase array( $idcol => array('label'=>'google', 'visits' => 1)), array( $idcol => array('label'=>'ask', 'visits' => 2)), array( $idcol => array('label'=>'123', 'visits' => 2)), + Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 7)) ); $table = new Piwik_DataTable; $table->loadFromArray( $rows ); @@ -832,6 +793,7 @@ class Test_Piwik_DataTable extends UnitTestCase array( $idcol => array('label'=>'google', 'visits' => -1)), array( $idcol => array('label'=>'ask', 'visits' => 0)), array( $idcol => array('label'=>'123', 'visits' => 1.5)), + Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 8)) ); $table2 = new Piwik_DataTable; $table2->loadFromArray( $rows2 ); @@ -842,6 +804,7 @@ class Test_Piwik_DataTable extends UnitTestCase array( $idcol => array('label'=>'google', 'visits' => 0)), array( $idcol => array('label'=>'ask', 'visits' => 2)), array( $idcol => array('label'=>'123', 'visits' => 3.5)), + Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 15)) ); $tableExpected = new Piwik_DataTable; $tableExpected->loadFromArray( $rowsExpected ); @@ -852,7 +815,6 @@ class Test_Piwik_DataTable extends UnitTestCase /** * test add 2 different tables to the same table */ - public function test_addDataTable2times() { @@ -862,6 +824,7 @@ class Test_Piwik_DataTable extends UnitTestCase array( $idcol => array('label'=>'google', 'visits' => 1)), array( $idcol => array('label'=>'ask', 'visits' => 0)), array( $idcol => array('label'=>'123', 'visits' => 2)), + Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 1)) ); $table = new Piwik_DataTable; $table->loadFromArray( $rows ); @@ -880,6 +843,7 @@ class Test_Piwik_DataTable extends UnitTestCase array( $idcol => array('label'=>'google2', 'visits' => -1)), array( $idcol => array('label'=>'ask', 'visits' => -10)), array( $idcol => array('label'=>'123ab', 'visits' => 1.5)), + Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 3)) ); $table3 = new Piwik_DataTable; $table3->loadFromArray( $rows3 ); @@ -895,6 +859,7 @@ class Test_Piwik_DataTable extends UnitTestCase array( $idcol => array('label'=>'google2', 'visits' => -2)), array( $idcol => array('label'=>'123456', 'visits' => 1.5)), array( $idcol => array('label'=>'123ab', 'visits' => 1.5)), + Piwik_DataTable::ID_SUMMARY_ROW => array( $idcol => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 4)) ); $tableExpected = new Piwik_DataTable; $tableExpected->loadFromArray( $rowsExpected ); @@ -902,5 +867,43 @@ class Test_Piwik_DataTable extends UnitTestCase $this->assertTrue( Piwik_DataTable::isEqual($table, $tableExpected) ); } + protected function getDataTable1ForTest() + { + $rows = $this->getRowsDataTable1ForTest(); + $table = new Piwik_DataTable; + $table->loadFromArray( $rows ); + return $table; + } + + protected function getDataTable2ForTest() + { + $rows = $this->getRowsDataTable2ForTest(); + $table = new Piwik_DataTable; + $table->loadFromArray( $rows ); + return $table; + } + + protected function getRowsDataTable1ForTest() + { + $rows = array( + array( Piwik_DataTable_Row::COLUMNS => array('label'=>'google', 'visits' => 1)), + array( Piwik_DataTable_Row::COLUMNS => array('label'=>'ask', 'visits' => 2)), + array( Piwik_DataTable_Row::COLUMNS => array('label'=>'123', 'visits' => 2)), + Piwik_DataTable::ID_SUMMARY_ROW => array( Piwik_DataTable_Row::COLUMNS => array('label'=>Piwik_DataTable::LABEL_SUMMARY_ROW, 'visits' => 4)) + + ); + return $rows; + } + + protected function getRowsDataTable2ForTest() + { + $rows = array( + array( Piwik_DataTable_Row::COLUMNS => array('label'=>'test', 'visits' => 1)), + array( Piwik_DataTable_Row::COLUMNS => array('label'=>' google ', 'visits' => 3)), + array( Piwik_DataTable_Row::COLUMNS => array('label'=>'123a', 'visits' => 2)), + ); + return $rows; + } + }
\ No newline at end of file |