[Piwik-svn] r181 - in trunk: config misc modules/ArchiveProcessing modules/DataTable/Renderer plugins plugins/UsersManager tests/modules/DataTable
svnmaster at piwik.org
svnmaster at piwik.org
Fri Jan 18 00:39:40 CET 2008
Author: matt
Date: 2008-01-18 00:39:40 +0100 (Fri, 18 Jan 2008)
New Revision: 181
Modified:
trunk/config/global.ini.php
trunk/misc/api_internal_call.php
trunk/modules/ArchiveProcessing/Day.php
trunk/modules/DataTable/Renderer/Csv.php
trunk/modules/DataTable/Renderer/Json.php
trunk/modules/DataTable/Renderer/Php.php
trunk/modules/DataTable/Renderer/Xml.php
trunk/plugins/Login.php
trunk/plugins/UsersManager/API.php
trunk/tests/modules/DataTable/Renderer.test.php
Log:
- Historical data works !!!!!!
try with date=last30 or date=last5 for example
- updated all renderer to correctly handle the new data structure: DataTable_Array which is an array of DataTable
- added complete tests of all renderers
Modified: trunk/config/global.ini.php
===================================================================
--- trunk/config/global.ini.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/config/global.ini.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -15,7 +15,7 @@
host = localhost
username = root
password =
-dbname = piwik_tests6
+dbname = piwik_tests7
tables_prefix = piwiktests_
adapter = PDO_MYSQL
@@ -54,7 +54,7 @@
[General]
; Time in seconds after which an archive will be computed again.
; This setting is used only for today's statistics.
-time_before_archive_considered_outdated = 6000
+time_before_archive_considered_outdated = 600
; character used to automatically create categories in the "Action" "Downloads" reports
; for example a URL like "example.com/blog/development/first-post" will create
Modified: trunk/misc/api_internal_call.php
===================================================================
--- trunk/misc/api_internal_call.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/misc/api_internal_call.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -14,7 +14,7 @@
&idSite=1
&date=yesterday
&period=week
- &format=JSON
+ &format=XML
&filter_limit=5
');
$result = $request->process();
Modified: trunk/modules/ArchiveProcessing/Day.php
===================================================================
--- trunk/modules/ArchiveProcessing/Day.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/modules/ArchiveProcessing/Day.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -21,6 +21,7 @@
*/
class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing
{
+ public $isThereSomeVisits = false;
/**
* Constructor
*/
Modified: trunk/modules/DataTable/Renderer/Csv.php
===================================================================
--- trunk/modules/DataTable/Renderer/Csv.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/modules/DataTable/Renderer/Csv.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -45,18 +45,58 @@
protected function renderTable($table)
{
- $csv = array();
-
- // keep track of all the existing columns in the csv file
- $allColumns = array();
+ if($table instanceof Piwik_DataTable_Array)
+ {
+ $str = $header = '';
+ $prefixColumns = $table->getNameKey() . $this->separator;
+ foreach($table->getArray() as $currentLinePrefix => $dataTable)
+ {
+ $returned = explode("\n",$this->renderTable($dataTable));
+ // get the columns names
+ if(empty($header))
+ {
+ $header = $returned[0];
+ }
+ $returned = array_slice($returned,1);
+ foreach($returned as &$row)
+ {
+ $row = $currentLinePrefix . $this->separator . $row;
+ }
+ $str .= "\n" . implode("\n", $returned);
+ }
+// var_dump($header);exit;
+ if(!empty($header))
+ {
+ $str = $prefixColumns . $header . $str;
+ }
+ else
+ {
+ $str = 'No data available';
+ }
+ }
+ else
+ {
+ $str = $this->renderDataTable($table);
+ }
+
+ return $this->output($str);
+ }
+
+ protected function renderDataTable( $table )
+ {
if($table instanceof Piwik_DataTable_Simple
&& $table->getRowsCount() ==1)
{
$str = 'value' . $this->lineEnd . $table->getRowFromId(0)->getColumn('value');
- return $this->output($str);
+ return $str;
}
+ $csv = array();
+
+ // keep track of all the existing columns in the csv file
+ $allColumns = array();
+
foreach($table->getRows() as $row)
{
$csvRow = array();
@@ -111,31 +151,26 @@
}
}
// var_dump($csv);exit;
- $str = '';
-
-
- // specific case, we have only one column and this column wasn't named properly (indexed by a number)
- // we don't print anything in the CSV file => an empty line
+ $str = '';
+
+ // specific case, we have only one column and this column wasn't named properly (indexed by a number)
+ // we don't print anything in the CSV file => an empty line
if(sizeof($allColumns) == 1
&& reset($allColumns)
- && !is_string(key($allColumns)) )
- {
- $str .= '';
- }
- else
+ && !is_string(key($allColumns)))
{
+ $str .= '';
+ }
+ else
+ {
$keys = array_keys($allColumns);
-// foreach($keys as &$key)
-// {
-// $key = '"' . $key . '"';
-// }
- $str .= implode($this->separator, $keys);
- }
+ $str .= implode($this->separator, $keys);
+ }
// we render the CSV
foreach($csv as $theRow)
{
- $rowStr = $this->lineEnd;
+ $rowStr = '';
foreach($allColumns as $columnName => $true)
{
$rowStr .= $theRow[$columnName] . $this->separator;
@@ -143,17 +178,15 @@
// remove the last separator
$rowStr = substr_replace($rowStr,"",-strlen($this->separator));
- $str .= $rowStr;
+ $str .= $this->lineEnd . $rowStr;
}
-
- return $this->output($str);
+ return $str;
}
-
protected function output( $str )
{
// silent fail otherwise unit tests fail
- @header("Content-type: application/vnd.ms-excel");
- @header("Content-Disposition: attachment; filename=piwik-report-export.csv");
+// @header("Content-type: application/vnd.ms-excel");
+// @header("Content-Disposition: attachment; filename=piwik-report-export.csv");
return $str;
}
}
\ No newline at end of file
Modified: trunk/modules/DataTable/Renderer/Json.php
===================================================================
--- trunk/modules/DataTable/Renderer/Json.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/modules/DataTable/Renderer/Json.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -31,7 +31,12 @@
protected function renderTable($table)
{
$renderer = new Piwik_DataTable_Renderer_Php($table, $serialize = false);
- $array = $renderer->flatRender();
+ $array = $renderer->flatRender();
+
+ if(!is_array($array))
+ {
+ $array = array('value' => $array);
+ }
$str = json_encode($array);
return $str;
}
Modified: trunk/modules/DataTable/Renderer/Php.php
===================================================================
--- trunk/modules/DataTable/Renderer/Php.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/modules/DataTable/Renderer/Php.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -68,9 +68,11 @@
$flatArray = array();
foreach($dataTable->getArray() as $keyName => $table)
{
+ $serializeSave = $this->serialize;
+ $this->serialize = false;
$flatArray[$keyName] = $this->flatRender($table);
+ $this->serialize = $serializeSave;
}
- return $flatArray;
}
// A DataTable_Simple is already flattened so no need to do some crazy stuff to convert it
Modified: trunk/modules/DataTable/Renderer/Xml.php
===================================================================
--- trunk/modules/DataTable/Renderer/Xml.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/modules/DataTable/Renderer/Xml.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -31,117 +31,154 @@
}
protected function renderTable($table)
- {
-// echo $table;exit;
+ {
$renderer = new Piwik_DataTable_Renderer_Php($table, $serialize = false);
+
$array = $renderer->flatRender();
-
-// var_dump($array); exit;
-
- $options = array(
- XML_SERIALIZER_OPTION_INDENT => ' ',
- XML_SERIALIZER_OPTION_LINEBREAKS => "\n",
- XML_SERIALIZER_OPTION_ROOT_NAME => 'row',
- XML_SERIALIZER_OPTION_MODE => XML_SERIALIZER_MODE_SIMPLEXML
- );
- $rootName = 'result';
-
+
// case DataTable_Array
if($table instanceof Piwik_DataTable_Array)
{
-
- // CASE 1
- //array
- // 'day1' => string '14' (length=2)
- // 'day2' => string '6' (length=1)
- $firstTable = current($array);
- if(!is_array( $firstTable ))
+ return $this->renderDataTableArray($table, $array);
+ }
+
+ if($table instanceof Piwik_DataTable_Simple)
+ {
+ if(is_array($array))
{
- $xml = "<results>\n";
- $nameDescriptionAttribute = $table->getNameKey();
- foreach($array as $valueAttribute => $value)
- {
- $xml .= "\t<result $nameDescriptionAttribute=\"$valueAttribute\">$value</result>\n";
- }
- $xml .= "</results>";
- return $this->output($xml);
+ $out = $this->renderDataTableSimple($array);
+ $out = "<result>\n".$out."</result>";
+ return $this->output($out);
}
-
- $subTables = $table->getArray();
- $firstTable = current($subTables);
-
- // CASE 2
- //array
- // 'day1' =>
- // array
- // 'nb_uniq_visitors' => string '18'
- // 'nb_visits' => string '101'
- // 'day2' =>
- // array
- // 'nb_uniq_visitors' => string '28'
- // 'nb_visits' => string '11'
- if( $firstTable instanceof Piwik_DataTable_Simple)
+ else
{
- $xml = "<results>\n";
- $nameDescriptionAttribute = $table->getNameKey();
- foreach($array as $valueAttribute => $value)
- {
- $xml .= "\t<result $nameDescriptionAttribute=\"$valueAttribute\">".''."</result>\n";
- }
- $xml .= "</results>";
- return $this->output($xml);
+ $out = "<result>".$array."</result>";
+ return $this->output($out);
}
-
- // CASE 3
- //array
- // 'day1' =>
- // array
- // 0 =>
- // array
- // 'label' => string 'phpmyvisites'
- // 'nb_unique_visitors' => int 11
- // 'nb_visits' => int 13
- // 1 =>
- // array
- // 'label' => string 'phpmyvisits'
- // 'nb_unique_visitors' => int 2
- // 'nb_visits' => int 2
- // 'day2' =>
- // array
- // 0 =>
- // array
- // 'label' => string 'piwik'
- // 'nb_unique_visitors' => int 121
- // 'nb_visits' => int 130
- // 1 =>
- // array
- // 'label' => string 'piwik bis'
- // 'nb_unique_visitors' => int 20
- // 'nb_visits' => int 120
}
-
- $serializer = new XML_Serializer($options);
+ if($table instanceof Piwik_DataTable)
+ {
+ $out = $this->renderDataTable($array);
+ $out = "<result>\n$out</result>";
+ return $this->output($out);
+ }
- if($table instanceof Piwik_DataTable_Simple)
+
+ }
+
+ protected function renderDataTableArray($table, $array)
+ {
+ // CASE 1
+ //array
+ // 'day1' => string '14' (length=2)
+ // 'day2' => string '6' (length=1)
+ $firstTable = current($array);
+ if(!is_array( $firstTable ))
{
- $serializer->setOption(XML_SERIALIZER_OPTION_ROOT_NAME, 'result');
+ $xml = "<results>\n";
+ $nameDescriptionAttribute = $table->getNameKey();
+ foreach($array as $valueAttribute => $value)
+ {
+ $xml .= "\t<result $nameDescriptionAttribute=\"$valueAttribute\">$value</result>\n";
+ }
+ $xml .= "</results>";
+ return $this->output($xml);
}
- $result = $serializer->serialize($array);
-
- $xmlStr = $serializer->getSerializedData();
+ $subTables = $table->getArray();
+ $firstTable = current($subTables);
- if($table instanceof Piwik_DataTable
- || $table instanceof Piwik_DataTable_Array)
+ // CASE 2
+ //array
+ // 'day1' =>
+ // array
+ // 'nb_uniq_visitors' => string '18'
+ // 'nb_visits' => string '101'
+ // 'day2' =>
+ // array
+ // 'nb_uniq_visitors' => string '28'
+ // 'nb_visits' => string '11'
+ if( $firstTable instanceof Piwik_DataTable_Simple)
{
- $xmlStr = "<$rootName>\n".$xmlStr."\n</$rootName>";
- $xmlStr = str_replace(">\n", ">\n\t",$xmlStr);
- $xmlStr = str_replace("\t</$rootName>", "</$rootName>",$xmlStr);
+ $xml = "<results>\n";
+ $nameDescriptionAttribute = $table->getNameKey();
+ foreach($array as $valueAttribute => $dataTableSimple)
+ {
+ $dataTableSimple = $this->renderDataTableSimple($dataTableSimple, "\t");
+ $xml .= "\t<result $nameDescriptionAttribute=\"$valueAttribute\">\n".$dataTableSimple."\t</result>\n";
+ }
+ $xml .= "</results>";
+ return $this->output($xml);
}
- return $this->output($xmlStr);
+
+ // CASE 3
+ //array
+ // 'day1' =>
+ // array
+ // 0 =>
+ // array
+ // 'label' => string 'phpmyvisites'
+ // 'nb_unique_visitors' => int 11
+ // 'nb_visits' => int 13
+ // 1 =>
+ // array
+ // 'label' => string 'phpmyvisits'
+ // 'nb_unique_visitors' => int 2
+ // 'nb_visits' => int 2
+ // 'day2' =>
+ // array
+ // 0 =>
+ // array
+ // 'label' => string 'piwik'
+ // 'nb_unique_visitors' => int 121
+ // 'nb_visits' => int 130
+ // 1 =>
+ // array
+ // 'label' => string 'piwik bis'
+ // 'nb_unique_visitors' => int 20
+ // 'nb_visits' => int 120
+ if($firstTable instanceof Piwik_DataTable)
+ {
+ $out = "<results>\n";
+ $nameDescriptionAttribute = $table->getNameKey();
+ foreach($array as $keyName => $arrayForSingleDate)
+ {
+ $out .= "\t<result $nameDescriptionAttribute=\"$keyName\">\n";
+
+ $out .= $this->renderDataTable( $arrayForSingleDate, "\t" );
+ $out .= "\t</result>\n";
+ }
+ $out .= "</results>";
+ return $this->output($out);
+ }
}
+ protected function renderDataTable( $array, $prefixLine = "" )
+ {
+// var_dump($array);exit;
+
+ $out = '';
+ foreach($array as $row)
+ {
+ $out .= $prefixLine."\t<row>\n";
+ foreach($row as $name => $value)
+ {
+ $out .= $prefixLine."\t\t<$name>$value</$name>\n";
+ }
+ $out .= $prefixLine."\t</row>\n";
+ }
+ return $out;
+ }
+ protected function renderDataTableSimple( $array, $prefixLine = "")
+ {
+ $out = '';
+ foreach($array as $keyName => $value)
+ {
+ $out .= $prefixLine."\t<$keyName>$value</$keyName>\n";
+ }
+ return $out;
+ }
protected function output( $xml )
{
// silent fail because otherwise it throws an exception in the unit tests
Modified: trunk/plugins/Login.php
===================================================================
--- trunk/plugins/Login.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/plugins/Login.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -89,6 +89,7 @@
// Note that the user created in the DB has a token_auth value of anonymous
$tokenAuth = 'anonymous';
+// echo $authCookie; exit;
if($authCookie->isCookieFound())
{
$login = $authCookie->get('login');
Modified: trunk/plugins/UsersManager/API.php
===================================================================
--- trunk/plugins/UsersManager/API.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/plugins/UsersManager/API.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -118,7 +118,6 @@
*/
static public function getUsersAccessFromSite( $idSite )
{
-
Piwik::checkUserHasAdminAccess( $idSite );
$db = Zend_Registry::get('db');
Modified: trunk/tests/modules/DataTable/Renderer.test.php
===================================================================
--- trunk/tests/modules/DataTable/Renderer.test.php 2008-01-17 16:32:37 UTC (rev 180)
+++ trunk/tests/modules/DataTable/Renderer.test.php 2008-01-17 23:39:40 UTC (rev 181)
@@ -9,6 +9,7 @@
require_once 'DataTable.php';
require_once 'DataTable/Simple.php';
+require_once 'DataTable/Array.php';
require_once 'DataTable/Renderer/Xml.php';
require_once 'DataTable/Renderer/Csv.php';
require_once 'DataTable/Renderer/Json.php';
@@ -31,11 +32,13 @@
/**
+ * DATA TESTS
+ * -----------------------
* for each renderer we test the case
* - datatableSimple
* - normal datatable with 2 row (including columns and details) *
*/
- protected function getTableTest1()
+ protected function getDataTableTest()
{
$array = array (
array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google', 'nb_unique_visitors' => 11, 'nb_visits' => 11, 'nb_actions' => 17, 'max_actions' => '5', 'sum_visit_length' => 517, 'bounce_count' => 9),
@@ -49,7 +52,7 @@
$dataTable->loadFromArray($array);
return $dataTable;
}
- protected function getTableTest2()
+ protected function getDataTableSimpleTest()
{
$array = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, 'nb_visits' => 66.0, 'nb_actions' => 151.0, 'sum_visit_length' => 5118.0, 'bounce_count' => 44.0, );
@@ -57,10 +60,25 @@
$table->loadFromArray($array);
return $table;
}
+ protected function getDataTableSimpleOneRowTest()
+ {
+ $array = array ( 'nb_visits' => 14.0 );
+
+ $table = new Piwik_DataTable_Simple;
+ $table->loadFromArray($array);
+ return $table;
+ }
+
+
+ /**
+ * START TESTS
+ * -----------------------
+ *
+ */
function test_XML_test1()
{
- $dataTable = $this->getTableTest1();
+ $dataTable = $this->getDataTableTest();
$render = new Piwik_DataTable_Renderer_Xml($dataTable);
$expected = '<result>
<row>
@@ -91,7 +109,7 @@
function test_XML_test2()
{
- $dataTable = $this->getTableTest2();
+ $dataTable = $this->getDataTableSimpleTest();
$render = new Piwik_DataTable_Renderer_Xml($dataTable);
$expected = '<result>
<max_actions>14</max_actions>
@@ -103,9 +121,18 @@
</result>';
$this->assertEqual( $expected,$render->render());
}
+ function test_XML_test3()
+ {
+ $dataTable = $this->getDataTableSimpleOneRowTest();
+ $render = new Piwik_DataTable_Renderer_Xml($dataTable);
+ $expected = '<result>14</result>';
+ $this->assertEqual( $expected,$render->render());
+ }
+
+
function test_CSV_test1()
{
- $dataTable = $this->getTableTest1();
+ $dataTable = $this->getDataTableTest();
$render = new Piwik_DataTable_Renderer_Csv($dataTable);
$expected = 'label,nb_unique_visitors,nb_visits,nb_actions,max_actions,sum_visit_length,bounce_count,detail_url,detail_logo
Google,11,11,17,5,517,9,http://www.google.com,./plugins/Referers/images/searchEngines/www.google.com.png
@@ -115,7 +142,7 @@
}
function test_CSV_test2()
{
- $dataTable = $this->getTableTest2();
+ $dataTable = $this->getDataTableSimpleTest();
$render = new Piwik_DataTable_Renderer_Csv($dataTable);
$expected = 'label,value
max_actions,14
@@ -128,9 +155,17 @@
$this->assertEqual( $expected,$render->render());
}
+ function test_CSV_test3()
+ {
+ $dataTable = $this->getDataTableSimpleOneRowTest();
+ $render = new Piwik_DataTable_Renderer_Csv($dataTable);
+ $expected = "value\n14";
+ $this->assertEqual( $expected,$render->render());
+ }
+
function test_JSON_test1()
{
- $dataTable = $this->getTableTest1();
+ $dataTable = $this->getDataTableTest();
$render = new Piwik_DataTable_Renderer_Json($dataTable);
$expected = '[{"label":"Google","nb_unique_visitors":11,"nb_visits":11,"nb_actions":17,"max_actions":"5","sum_visit_length":517,"bounce_count":9,"url":"http:\/\/www.google.com","logo":".\/plugins\/Referers\/images\/searchEngines\/www.google.com.png"},{"label":"Yahoo!","nb_unique_visitors":15,"nb_visits":151,"nb_actions":147,"max_actions":"50","sum_visit_length":517,"bounce_count":90,"url":"http:\/\/www.yahoo.com","logo":".\/plugins\/Referers\/images\/searchEngines\/www.yahoo.com.png"}]';
@@ -138,29 +173,394 @@
}
function test_JSON_test2()
{
- $dataTable = $this->getTableTest2();
+ $dataTable = $this->getDataTableSimpleTest();
$render = new Piwik_DataTable_Renderer_Json($dataTable);
$expected = '{"max_actions":14,"nb_uniq_visitors":57,"nb_visits":66,"nb_actions":151,"sum_visit_length":5118,"bounce_count":44}';
$this->assertEqual( $expected,$render->render());
}
+ function test_JSON_test3()
+ {
+ $dataTable = $this->getDataTableSimpleOneRowTest();
+ $render = new Piwik_DataTable_Renderer_Json($dataTable);
+ $expected = '{"value":14}';
+ $this->assertEqual( $expected,$render->render());
+ }
+
function test_PHP_test1()
{
- $dataTable = $this->getTableTest1();
+ $dataTable = $this->getDataTableTest();
$render = new Piwik_DataTable_Renderer_Php($dataTable);
- $expected = 'a:2:{i:0;a:9:{s:5:"label";s:6:"Google";s:18:"nb_unique_visitors";i:11;s:9:"nb_visits";i:11;s:10:"nb_actions";i:17;s:11:"max_actions";s:1:"5";s:16:"sum_visit_length";i:517;s:12:"bounce_count";i:9;s:3:"url";s:21:"http://www.google.com";s:4:"logo";s:58:"./plugins/Referers/images/searchEngines/www.google.com.png";}i:1;a:9:{s:5:"label";s:6:"Yahoo!";s:18:"nb_unique_visitors";i:15;s:9:"nb_visits";i:151;s:10:"nb_actions";i:147;s:11:"max_actions";s:2:"50";s:16:"sum_visit_length";i:517;s:12:"bounce_count";i:90;s:3:"url";s:20:"http://www.yahoo.com";s:4:"logo";s:57:"./plugins/Referers/images/searchEngines/www.yahoo.com.png";}}';
+ $expected = serialize(array (
+ 0 =>
+ array (
+ 'label' => 'Google',
+ 'nb_unique_visitors' => 11,
+ 'nb_visits' => 11,
+ 'nb_actions' => 17,
+ 'max_actions' => '5',
+ 'sum_visit_length' => 517,
+ 'bounce_count' => 9,
+ 'url' => 'http://www.google.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png',
+ ),
+ 1 =>
+ array (
+ 'label' => 'Yahoo!',
+ 'nb_unique_visitors' => 15,
+ 'nb_visits' => 151,
+ 'nb_actions' => 147,
+ 'max_actions' => '50',
+ 'sum_visit_length' => 517,
+ 'bounce_count' => 90,
+ 'url' => 'http://www.yahoo.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png',
+ ),
+ ));
$this->assertEqual( $expected,$render->render());
}
function test_PHP_test2()
{
- $dataTable = $this->getTableTest2();
+ $dataTable = $this->getDataTableSimpleTest();
$render = new Piwik_DataTable_Renderer_Php($dataTable);
- $expected = 'a:6:{s:11:"max_actions";d:14;s:16:"nb_uniq_visitors";d:57;s:9:"nb_visits";d:66;s:10:"nb_actions";d:151;s:16:"sum_visit_length";d:5118;s:12:"bounce_count";d:44;}';
+ $expected = serialize(array (
+ 'max_actions' => 14.0,
+ 'nb_uniq_visitors' => 57.0,
+ 'nb_visits' => 66.0,
+ 'nb_actions' => 151.0,
+ 'sum_visit_length' => 5118.0,
+ 'bounce_count' => 44.0,
+ ));
$this->assertEqual( $expected,$render->render());
}
+ function test_PHP_test3()
+ {
+ $dataTable = $this->getDataTableSimpleOneRowTest();
+ $render = new Piwik_DataTable_Renderer_Php($dataTable);
+ $expected = serialize(14.0);
+ $this->assertEqual( $expected,$render->render());
+ }
+
+
+
/**
+ * DATA OF DATATABLE_ARRAY
+ * -------------------------
+ */
+
+
+ protected function getDataTableArrayTest()
+ {
+ $array1 = array (
+ array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google', 'nb_unique_visitors' => 11, 'nb_visits' => 11, ),
+ Piwik_DataTable_Row::DETAILS => array('url' => 'http://www.google.com', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png'),
+ ),
+ array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!', 'nb_unique_visitors' => 15, 'nb_visits' => 151, ),
+ Piwik_DataTable_Row::DETAILS => array('url' => 'http://www.yahoo.com', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png'),
+ )
+ );
+ $table1 = new Piwik_DataTable();
+ $table1->loadFromArray($array1);
+
+
+ $array2 = array (
+ array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Google1', 'nb_unique_visitors' => 110, 'nb_visits' => 110,),
+ Piwik_DataTable_Row::DETAILS => array('url' => 'http://www.google.com1', 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1'),
+ ),
+ array ( Piwik_DataTable_Row::COLUMNS => array( 'label' => 'Yahoo!1', 'nb_unique_visitors' => 150, 'nb_visits' => 1510,),
+ Piwik_DataTable_Row::DETAILS => array('url' => 'http://www.yahoo.com1', 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1'),
+ )
+ );
+ $table2 = new Piwik_DataTable();
+ $table2->loadFromArray($array2);
+
+
+
+ $table = new Piwik_DataTable_Array();
+ $table->setNameKey('testKey');
+ $table->addTable($table1, 'date1');
+ $table->addTable($table2, 'date2');
+
+ return $table;
+ }
+
+ protected function getDataTableSimpleArrayTest()
+ {
+ $array1 = array ( 'max_actions' => 14.0, 'nb_uniq_visitors' => 57.0, );
+ $table1 = new Piwik_DataTable_Simple;
+ $table1->loadFromArray($array1);
+
+ $array2 = array ( 'max_actions' => 140.0, 'nb_uniq_visitors' => 570.0, );
+ $table2 = new Piwik_DataTable_Simple;
+ $table2->loadFromArray($array2);
+
+ $table = new Piwik_DataTable_Array();
+ $table->setNameKey('testKey');
+ $table->addTable($table1, 'row1');
+ $table->addTable($table2, 'row2');
+
+ return $table;
+ }
+
+ protected function getDataTableSimpleOneRowArrayTest()
+ {
+ $array1 = array ( 'nb_visits' => 14.0 );
+ $table1 = new Piwik_DataTable_Simple;
+ $table1->loadFromArray($array1);
+
+ $array2 = array ( 'nb_visits' => 15.0 );
+ $table2 = new Piwik_DataTable_Simple;
+ $table2->loadFromArray($array2);
+
+ $table = new Piwik_DataTable_Array();
+ $table->setNameKey('testKey');
+ $table->addTable($table1, 'row1');
+ $table->addTable($table2, 'row2');
+
+ return $table;
+ }
+
+
+ /**
+ * START TESTS DATATABLE_ARRAY
+ * ---------------
+ *
+ * XML
+ *
+ * PHP
+ *
+ *
+ */
+ function test_XML_Array_test1()
+ {
+ $dataTable = $this->getDataTableArrayTest();
+ $render = new Piwik_DataTable_Renderer_Xml($dataTable);
+ $expected = '<results>
+ <result testKey="date1">
+ <row>
+ <label>Google</label>
+ <nb_unique_visitors>11</nb_unique_visitors>
+ <nb_visits>11</nb_visits>
+ <url>http://www.google.com</url>
+ <logo>./plugins/Referers/images/searchEngines/www.google.com.png</logo>
+ </row>
+ <row>
+ <label>Yahoo!</label>
+ <nb_unique_visitors>15</nb_unique_visitors>
+ <nb_visits>151</nb_visits>
+ <url>http://www.yahoo.com</url>
+ <logo>./plugins/Referers/images/searchEngines/www.yahoo.com.png</logo>
+ </row>
+ </result>
+ <result testKey="date2">
+ <row>
+ <label>Google1</label>
+ <nb_unique_visitors>110</nb_unique_visitors>
+ <nb_visits>110</nb_visits>
+ <url>http://www.google.com1</url>
+ <logo>./plugins/Referers/images/searchEngines/www.google.com.png1</logo>
+ </row>
+ <row>
+ <label>Yahoo!1</label>
+ <nb_unique_visitors>150</nb_unique_visitors>
+ <nb_visits>1510</nb_visits>
+ <url>http://www.yahoo.com1</url>
+ <logo>./plugins/Referers/images/searchEngines/www.yahoo.com.png1</logo>
+ </row>
+ </result>
+</results>';
+ $this->assertEqual( $expected,$render->render());
+ }
+
+
+ function test_XML_Array_test2()
+ {
+ $dataTable = $this->getDataTableSimpleArrayTest();
+ $render = new Piwik_DataTable_Renderer_Xml($dataTable);
+ $expected = '<results>
+ <result testKey="row1">
+ <max_actions>14</max_actions>
+ <nb_uniq_visitors>57</nb_uniq_visitors>
+ </result>
+ <result testKey="row2">
+ <max_actions>140</max_actions>
+ <nb_uniq_visitors>570</nb_uniq_visitors>
+ </result>
+</results>';
+ $this->assertEqual( $expected,$render->render());
+ }
+ function test_XML_Array_test3()
+ {
+ $dataTable = $this->getDataTableSimpleOneRowArrayTest();
+ $render = new Piwik_DataTable_Renderer_Xml($dataTable);
+ $expected = '<results>
+ <result testKey="row1">14</result>
+ <result testKey="row2">15</result>
+</results>';
+ $this->assertEqual( $expected,$render->render());
+ }
+
+
+
+ function test_PHP_Array_test1()
+ {
+ $dataTable = $this->getDataTableArrayTest();
+ $render = new Piwik_DataTable_Renderer_Php($dataTable);
+ $rendered = $render->render();
+
+ $expected = serialize(array (
+ 'date1' =>
+ array (
+ 0 =>
+ array (
+ 'label' => 'Google',
+ 'nb_unique_visitors' => 11,
+ 'nb_visits' => 11,
+ 'url' => 'http://www.google.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png',
+ ),
+ 1 =>
+ array (
+ 'label' => 'Yahoo!',
+ 'nb_unique_visitors' => 15,
+ 'nb_visits' => 151,
+ 'url' => 'http://www.yahoo.com',
+ 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png',
+ ),
+ ),
+ 'date2' =>
+ array (
+ 0 =>
+ array (
+ 'label' => 'Google1',
+ 'nb_unique_visitors' => 110,
+ 'nb_visits' => 110,
+ 'url' => 'http://www.google.com1',
+ 'logo' => './plugins/Referers/images/searchEngines/www.google.com.png1',
+ ),
+ 1 =>
+ array (
+ 'label' => 'Yahoo!1',
+ 'nb_unique_visitors' => 150,
+ 'nb_visits' => 1510,
+ 'url' => 'http://www.yahoo.com1',
+ 'logo' => './plugins/Referers/images/searchEngines/www.yahoo.com.png1',
+ ),
+ ),
+ ));
+ $this->assertEqual( $expected,$rendered);
+ }
+ function test_PHP_Array_test2()
+ {
+ $dataTable = $this->getDataTableSimpleArrayTest();
+ $render = new Piwik_DataTable_Renderer_Php($dataTable);
+ $rendered = $render->render();
+
+ $expected = serialize(array (
+ 'row1' =>
+ array (
+ 'max_actions' => 14.0,
+ 'nb_uniq_visitors' => 57.0,
+ ),
+ 'row2' =>
+ array (
+ 'max_actions' => 140.0,
+ 'nb_uniq_visitors' => 570.0,
+ ),
+ ));
+ $this->assertEqual( $expected,$rendered);
+ }
+ function test_PHP_Array_test3()
+ {
+ $dataTable = $this->getDataTableSimpleOneRowArrayTest();
+ $render = new Piwik_DataTable_Renderer_Php($dataTable);
+ $rendered = $render->render();
+
+ $expected = serialize(array (
+ 'row1' => 14.0,
+ 'row2' => 15.0,
+ ));
+ $this->assertEqual( $expected,$rendered);
+ }
+
+
+
+ function test_JSON_Array_test1()
+ {
+ $dataTable = $this->getDataTableArrayTest();
+ $render = new Piwik_DataTable_Renderer_Json($dataTable);
+ $rendered = $render->render();
+ $expected = '{"date1":[{"label":"Google","nb_unique_visitors":11,"nb_visits":11,"url":"http:\/\/www.google.com","logo":".\/plugins\/Referers\/images\/searchEngines\/www.google.com.png"},{"label":"Yahoo!","nb_unique_visitors":15,"nb_visits":151,"url":"http:\/\/www.yahoo.com","logo":".\/plugins\/Referers\/images\/searchEngines\/www.yahoo.com.png"}],"date2":[{"label":"Google1","nb_unique_visitors":110,"nb_visits":110,"url":"http:\/\/www.google.com1","logo":".\/plugins\/Referers\/images\/searchEngines\/www.google.com.png1"},{"label":"Yahoo!1","nb_unique_visitors":150,"nb_visits":1510,"url":"http:\/\/www.yahoo.com1","logo":".\/plugins\/Referers\/images\/searchEngines\/www.yahoo.com.png1"}]}';
+
+ $this->assertEqual( $expected,$rendered);
+ }
+ function test_JSON_Array_test2()
+ {
+ $dataTable = $this->getDataTableSimpleArrayTest();
+ $render = new Piwik_DataTable_Renderer_Json($dataTable);
+ $rendered = $render->render();
+
+ $expected = '{"row1":{"max_actions":14,"nb_uniq_visitors":57},"row2":{"max_actions":140,"nb_uniq_visitors":570}}';
+
+ $this->assertEqual( $expected,$rendered);
+ }
+
+ function test_JSON_Array_test3()
+ {
+ $dataTable = $this->getDataTableSimpleOneRowArrayTest();
+ $render = new Piwik_DataTable_Renderer_Json($dataTable);
+ $rendered = $render->render();
+
+ $expected = '{"row1":14,"row2":15}';
+ $this->assertEqual( $expected,$rendered);
+ }
+
+
+
+
+
+ function test_CSV_Array_test1()
+ {
+ $dataTable = $this->getDataTableArrayTest();
+ $render = new Piwik_DataTable_Renderer_Csv($dataTable);
+ $expected = 'testKey,label,nb_unique_visitors,nb_visits,detail_url,detail_logo
+date1,Google,11,11,http://www.google.com,./plugins/Referers/images/searchEngines/www.google.com.png
+date1,Yahoo!,15,151,http://www.yahoo.com,./plugins/Referers/images/searchEngines/www.yahoo.com.png
+date2,Google1,110,110,http://www.google.com1,./plugins/Referers/images/searchEngines/www.google.com.png1
+date2,Yahoo!1,150,1510,http://www.yahoo.com1,./plugins/Referers/images/searchEngines/www.yahoo.com.png1';
+
+ $this->assertEqual( $expected,$render->render());
+ }
+ function test_CSV_Array_test2()
+ {
+ $dataTable = $this->getDataTableSimpleArrayTest();
+ $render = new Piwik_DataTable_Renderer_Csv($dataTable);
+ $expected = 'testKey,label,value
+row1,max_actions,14
+row1,nb_uniq_visitors,57
+row2,max_actions,140
+row2,nb_uniq_visitors,570';
+
+ $this->assertEqual( $expected,$render->render());
+ }
+
+ function test_CSV_Array_test3()
+ {
+ $dataTable = $this->getDataTableSimpleOneRowArrayTest();
+ $render = new Piwik_DataTable_Renderer_Csv($dataTable);
+ $expected = "testKey,value
+row1,14
+row2,15";
+ $this->assertEqual( $expected,$render->render());
+ }
+
+
+
+
+
+ /**
* test with a row without child
* a row with a child that has a child
* a row with w child
More information about the Piwik-svn
mailing list