[Piwik-svn] r142 - in trunk: config misc modules modules/API modules/LogStats modules/ViewDataTable plugins/Home plugins/Installation plugins/UsersManager tests tests/modules tests/modules/ArchiveProcessing
svnmaster at piwik.org
svnmaster at piwik.org
Fri Jan 11 01:19:27 CET 2008
Author: matt
Date: 2008-01-11 01:19:26 +0100 (Fri, 11 Jan 2008)
New Revision: 142
Added:
trunk/tests/modules/LogStats_Db.test.php
Modified:
trunk/config/global.ini.php
trunk/misc/generateVisits.php
trunk/modules/API/Request.php
trunk/modules/Config.php
trunk/modules/LogStats/Action.php
trunk/modules/LogStats/Db.php
trunk/modules/LogStats/Visit.php
trunk/modules/Piwik.php
trunk/modules/TablePartitioning.php
trunk/modules/Url.php
trunk/modules/ViewDataTable.php
trunk/modules/ViewDataTable/Html.php
trunk/plugins/Home/Controller.php
trunk/plugins/Installation/Controller.php
trunk/plugins/UsersManager/API.php
trunk/tests/config_test.php
trunk/tests/modules/ArchiveProcessing/Day.test.php
trunk/tests/modules/PHP_Related.test.php
trunk/tests/modules/Piwik.test.php
trunk/tests/modules/SitesManager.test.php
trunk/tests/modules/TablePartitioning.test.php
trunk/tests/modules/UsersManager.test.php
Log:
- removed all TODO
- added smart "low population" exclusion; now rows with values less than 2% are automatically deleted
- factoring some code
- added tests
- Fixed tests
Modified: trunk/config/global.ini.php
===================================================================
--- trunk/config/global.ini.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/config/global.ini.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -69,9 +69,10 @@
; default number of elements in the datatable
dataTable_default_limit = 10
-minimumPhpVersion = 5.1
-minimumMemoryLimit = 128
+minimum_php_version = 5.1
+minimum_memory_limit = 128
+
[LogStats]
; set to 0 if you want to stop tracking the visitors. Useful if you need to stop all the connections on the DB.
record_statistics = 1
Modified: trunk/misc/generateVisits.php
===================================================================
--- trunk/misc/generateVisits.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/misc/generateVisits.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -35,6 +35,8 @@
$generator = new Piwik_LogStats_Generator;
$generator->setMaximumUrlDepth(4);
$generator->disableProfiler();
+$nbActionsTotal = 0;
+
//$generator->emptyAllLogTables();
$generator->init();
@@ -43,9 +45,11 @@
/*
* Generate visits / actions for the last 31 days
*/
+
$daysToCompute = 1;
+
+// do NOT edit this line
$startTime = time() - ($daysToCompute-1)*86400;
-$nbActionsTotal = 10;
while($startTime <= time())
{
$visits = rand(1,2);
Modified: trunk/modules/API/Request.php
===================================================================
--- trunk/modules/API/Request.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/API/Request.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -235,7 +235,7 @@
// if asked for original dataStructure
if($format == 'original')
{
- // if the original dataStructure is a simple data structure
+ // if the original dataStructure is a simpleDataTable and has only one row, we return the value
if($dataTable instanceof Piwik_DataTable_Simple
&& $dataTable->getRowsCount() == 1)
{
Modified: trunk/modules/Config.php
===================================================================
--- trunk/modules/Config.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/Config.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -4,11 +4,12 @@
* @package Piwik
*/
require_once "Zend/Config/Ini.php";
-require_once "Zend/Registry.php";
+require_once "Zend/Registry.php";
+
class Piwik_Config
{
protected $urlToPiwikHelpMissingValueInConfigurationFile =
- 'http://piwik.svn.sourceforge.net/viewvc/piwik/trunk/config/global.ini.php';
+ 'http://dev.piwik.org/trac/browser/trunk/config/global.ini.php?format=raw';
protected $defaultConfig = null;
protected $userConfig = null;
Modified: trunk/modules/LogStats/Action.php
===================================================================
--- trunk/modules/LogStats/Action.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/LogStats/Action.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -22,9 +22,7 @@
*
* We make sure it is clean and displayable.
* If the name is empty we set it to a default name.
- *
- * TODO UTF8 handling to test
- *
+ *
* Specifications
*
* - Download tracking
Modified: trunk/modules/LogStats/Db.php
===================================================================
--- trunk/modules/LogStats/Db.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/LogStats/Db.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -4,8 +4,6 @@
* Simple database PDO wrapper.
* We can't afford to have a dependency with the Zend_Db module in the LogStats module.
*
- * TODO write the mysqli wrapper
- *
* @package Piwik_LogStats
*/
@@ -15,8 +13,8 @@
private $username;
private $password;
- //TODO test that in production is false
- static private $profiling = false;
+ static private $profiling = false;
+
protected $queriesProfiling;
/**
@@ -28,7 +26,19 @@
$this->username = $username;
$this->password = $password;
}
-
+
+
+ /**
+ * Returns true if the profiler is enabled
+ * Only used by the unit test that tests that the profiler is off on a production server
+ *
+ * @return bool
+ */
+ static public function isProfilingEnabled()
+ {
+ return self::$profiling;
+ }
+
/**
* Enables the profiling.
* For each query, saves in the DB the time spent on this query.
Modified: trunk/modules/LogStats/Visit.php
===================================================================
--- trunk/modules/LogStats/Visit.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/LogStats/Visit.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -17,8 +17,9 @@
{
protected $cookieLog = null;
protected $visitorInfo = array();
- protected $userSettingsInformation = null;
-
+ protected $userSettingsInformation = null;
+
+
function __construct( $db )
{
$this->db = $db;
@@ -571,194 +572,195 @@
* - referer_url : the same for all the referer types
*
*/
- //TODO split this big method getRefererInformation into small methods
private function getRefererInformation()
{
- // bool that says if the referer detection is done
- $refererAnalyzed = false;
- $typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
- $nameRefererAnalyzed = '';
- $keywordRefererAnalyzed = '';
-
+ // default values for the referer_* fields
+ $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
+ $this->nameRefererAnalyzed = '';
+ $this->keywordRefererAnalyzed = '';
+
+ // get the urls and parse them
$refererUrl = Piwik_Common::getRequestVar( 'urlref', '', 'string');
$currentUrl = Piwik_Common::getRequestVar( 'url', '', 'string');
- $refererUrlParse = @parse_url($refererUrl);
- $currentUrlParse = @parse_url($currentUrl);
-
- if( !empty($refererUrlParse['host']) )
+ $this->refererUrlParse = @parse_url($refererUrl);
+ $this->currentUrlParse = @parse_url($currentUrl);
+
+ // if we have a referer available we try to detect something interesting
+ // otherwise it's defaulted to "the visitor is a direct entry"
+ if( !empty($this->refererUrlParse['host']) )
{
- $refererHost = $refererUrlParse['host'];
- $refererSH = $refererUrlParse['scheme'].'://'.$refererUrlParse['host'];
+ $this->refererHost = $this->refererUrlParse['host'];
- /*
- * Search engine detection
- */
- if( !$refererAnalyzed )
- {
- /*
- * A referer is a search engine if the URL's host is in the SearchEngines array
- * and if we found the keyword in the URL.
- *
- * For example if someone comes from http://www.google.com/partners.html this will not
- * be counted as a search engines, but as a website referer from google.com (because the
- * keyword couldn't be found in the URL)
- */
- require PIWIK_DATAFILES_INCLUDE_PATH . "/SearchEngines.php";
-
- if(array_key_exists($refererHost, $GLOBALS['Piwik_SearchEngines']))
- {
- // which search engine ?
- $searchEngineName = $GLOBALS['Piwik_SearchEngines'][$refererHost][0];
- $variableName = $GLOBALS['Piwik_SearchEngines'][$refererHost][1];
-
- // if there is a query, there may be a keyword...
- if(isset($refererUrlParse['query']))
- {
- $query = $refererUrlParse['query'];
-
- // search for keywords now &vname=keyword
- $key = trim(strtolower(Piwik_Common::getParameterFromQueryString($query, $variableName)));
-
- //TODO test the search engine non-utf8 support
- // for search engines that don't use utf-8
- if((function_exists('iconv'))
- && (isset($GLOBALS['Piwik_SearchEngines'][$refererHost][2])))
- {
- $charset = trim($GLOBALS['Piwik_SearchEngines'][$refererHost][2]);
-
- if(!empty($charset))
- {
- $key = htmlspecialchars(
- @iconv( $charset,
- 'utf-8//TRANSLIT',
- htmlspecialchars_decode($key, Piwik_Common::HTML_ENCODING_QUOTE_STYLE))
- , Piwik_Common::HTML_ENCODING_QUOTE_STYLE);
- }
- }
-
-
- if(!empty($key))
- {
- $refererAnalyzed = true;
- $typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_SEARCH_ENGINE;
- $nameRefererAnalyzed = $searchEngineName;
- $keywordRefererAnalyzed = $key;
- }
- }
- }
+ if( !$this->detectRefererSearchEngine()
+ && !$this->detectRefererNewsletter()
+ && !$this->detectRefererPartner()
+ && !$this->detectRefererCampaign()
+ && !$this->detectRefererDirectEntry()
+ )
+ {
+ // Normal website referer
+ $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_WEBSITE;
+ $this->nameRefererAnalyzed = $this->refererHost;
}
-
- /*
- * Newsletter analysis
- */
- if( !$refererAnalyzed )
- {
- if(isset($currentUrlParse['query']))
- {
- $newsletterVariableName = Piwik_LogStats_Config::getInstance()->LogStats['newsletter_var_name'];
- $newsletterVar = Piwik_Common::getParameterFromQueryString( $currentUrlParse['query'], $newsletterVariableName);
-
- if(!empty($newsletterVar))
- {
- $refererAnalyzed = true;
- $typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_NEWSLETTER;
- $nameRefererAnalyzed = $newsletterVar;
- }
- }
- }
-
- /*
- * Partner analysis
- */
- if( !$refererAnalyzed )
- {
- if(isset($currentUrlParse['query']))
- {
- $partnerVariableName = Piwik_LogStats_Config::getInstance()->LogStats['partner_var_name'];
- $partnerVar = Piwik_Common::getParameterFromQueryString($currentUrlParse['query'], $partnerVariableName);
-
- if(!empty($partnerVar))
- {
- $refererAnalyzed = true;
- $typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_PARTNER;
- $nameRefererAnalyzed = $partnerVar;
- }
- }
- }
-
- /*
- * Campaign analysis
- */
- if( !$refererAnalyzed )
- {
- if(isset($currentUrlParse['query']))
- {
- $campaignVariableName = Piwik_LogStats_Config::getInstance()->LogStats['campaign_var_name'];
- $campaignName = Piwik_Common::getParameterFromQueryString($currentUrlParse['query'], $campaignVariableName);
-
- if( !empty($campaignName))
- {
- $campaignKeywordVariableName = Piwik_LogStats_Config::getInstance()->LogStats['campaign_keyword_var_name'];
- $campaignKeyword = Piwik_Common::getParameterFromQueryString($currentUrlParse['query'], $campaignKeywordVariableName);
-
- $refererAnalyzed = true;
- $typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_CAMPAIGN;
- $nameRefererAnalyzed = $campaignName;
-
- if(!empty($campaignKeyword))
- {
- $keywordRefererAnalyzed = $campaignKeyword;
- }
- }
- }
- }
-
- /*
- * Direct entry (referer host is similar to current host)
- * And we have previously tried to detect the newsletter/partner/campaign variables in the URL
- * so it can only be a direct access
- */
- if( !$refererAnalyzed )
- {
- $currentUrlParse = @parse_url($currentUrl);
-
- if(isset($currentUrlParse['host']))
- {
- $currentHost = $currentUrlParse['host'];
- $currentSH = $currentUrlParse['scheme'].'://'.$currentUrlParse['host'];
-
- if($currentHost == $refererHost)
- {
- $refererAnalyzed = true;
- $typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
- }
- }
-
- }
-
- /*
- * Normal website referer
- */
- if( !$refererAnalyzed )
- {
- $refererAnalyzed = true;
- $typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_WEBSITE;
- $nameRefererAnalyzed = $refererHost;
- }
}
-
$refererInformation = array(
- 'referer_type' => $typeRefererAnalyzed,
- 'referer_name' => $nameRefererAnalyzed,
- 'referer_keyword' => $keywordRefererAnalyzed,
+ 'referer_type' => $this->typeRefererAnalyzed,
+ 'referer_name' => $this->nameRefererAnalyzed,
+ 'referer_keyword' => $this->keywordRefererAnalyzed,
'referer_url' => $refererUrl,
);
return $refererInformation;
}
-
+
+ /*
+ * Search engine detection
+ */
+ private function detectRefererSearchEngine()
+ {
+ /*
+ * A referer is a search engine if the URL's host is in the SearchEngines array
+ * and if we found the keyword in the URL.
+ *
+ * For example if someone comes from http://www.google.com/partners.html this will not
+ * be counted as a search engines, but as a website referer from google.com (because the
+ * keyword couldn't be found in the URL)
+ */
+ require PIWIK_DATAFILES_INCLUDE_PATH . "/SearchEngines.php";
+
+ if(array_key_exists($this->refererHost, $GLOBALS['Piwik_SearchEngines']))
+ {
+ // which search engine ?
+ $searchEngineName = $GLOBALS['Piwik_SearchEngines'][$this->refererHost][0];
+ $variableName = $GLOBALS['Piwik_SearchEngines'][$this->refererHost][1];
+
+ // if there is a query, there may be a keyword...
+ if(isset($this->refererUrlParse['query']))
+ {
+ $query = $this->refererUrlParse['query'];
+
+ // search for keywords now &vname=keyword
+ $key = trim(strtolower(Piwik_Common::getParameterFromQueryString($query, $variableName)));
+
+ if((function_exists('iconv'))
+ && (isset($GLOBALS['Piwik_SearchEngines'][$this->refererHost][2])))
+ {
+ $charset = trim($GLOBALS['Piwik_SearchEngines'][$this->refererHost][2]);
+
+ if(!empty($charset))
+ {
+ $key = htmlspecialchars(
+ @iconv( $charset,
+ 'utf-8//TRANSLIT',
+ htmlspecialchars_decode($key, Piwik_Common::HTML_ENCODING_QUOTE_STYLE))
+ , Piwik_Common::HTML_ENCODING_QUOTE_STYLE);
+ }
+ }
+
+
+ if(!empty($key))
+ {
+ $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_SEARCH_ENGINE;
+ $this->nameRefererAnalyzed = $searchEngineName;
+ $this->keywordRefererAnalyzed = $key;
+
+ return true;
+ }
+ }
+ }
+ }
+
+ /*
+ * Newsletter analysis
+ */
+ private function detectRefererNewsletter()
+ {
+ if(isset($this->currentUrlParse['query']))
+ {
+ $newsletterVariableName = Piwik_LogStats_Config::getInstance()->LogStats['newsletter_var_name'];
+ $newsletterVar = Piwik_Common::getParameterFromQueryString( $this->currentUrlParse['query'], $newsletterVariableName);
+
+ if(!empty($newsletterVar))
+ {
+ $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_NEWSLETTER;
+ $this->nameRefererAnalyzed = $newsletterVar;
+
+ return true;
+ }
+ }
+ }
+
+ /*
+ * Partner analysis
+ */
+ private function detectRefererPartner()
+ {
+ if(isset($this->currentUrlParse['query']))
+ {
+ $partnerVariableName = Piwik_LogStats_Config::getInstance()->LogStats['partner_var_name'];
+ $partnerVar = Piwik_Common::getParameterFromQueryString($this->currentUrlParse['query'], $partnerVariableName);
+
+ if(!empty($partnerVar))
+ {
+ $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_PARTNER;
+ $this->nameRefererAnalyzed = $partnerVar;
+
+ return true;
+ }
+ }
+ }
+
+ /*
+ * Campaign analysis
+ */
+ private function detectRefererCampaign()
+ {
+ if(isset($this->currentUrlParse['query']))
+ {
+ $campaignVariableName = Piwik_LogStats_Config::getInstance()->LogStats['campaign_var_name'];
+ $campaignName = Piwik_Common::getParameterFromQueryString($this->currentUrlParse['query'], $campaignVariableName);
+
+ if( !empty($campaignName))
+ {
+ $campaignKeywordVariableName = Piwik_LogStats_Config::getInstance()->LogStats['campaign_keyword_var_name'];
+ $campaignKeyword = Piwik_Common::getParameterFromQueryString($this->currentUrlParse['query'], $campaignKeywordVariableName);
+
+ $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_CAMPAIGN;
+ $this->nameRefererAnalyzed = $campaignName;
+
+ if(!empty($campaignKeyword))
+ {
+ $this->keywordRefererAnalyzed = $campaignKeyword;
+ }
+
+ return true;
+ }
+ }
+ }
+
+ /*
+ * Direct entry (referer host is similar to current host)
+ * And we have previously tried to detect the newsletter/partner/campaign variables in the URL
+ * so it can only be a direct access
+ */
+
+ private function detectRefererDirectEntry()
+ {
+ if(isset($this->currentUrlParse['host']))
+ {
+ $currentHost = $this->currentUrlParse['host'];
+
+ if($currentHost == $this->refererHost)
+ {
+ $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
+
+ return true;
+ }
+ }
+
+ }
/**
* Returns a MD5 of all the configuration settings
* @return string
Modified: trunk/modules/Piwik.php
===================================================================
--- trunk/modules/Piwik.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/Piwik.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -154,8 +154,15 @@
);
exit;
}
-
- //TODO TEST secureDiv
+
+ /**
+ * Computes the division of i1 by i2. If either i1 or i2 are not number, or if i2 has a value of zero
+ * we return 0 to avoid the division by zero.
+ *
+ * @param numeric $i1
+ * @param numeric $i2
+ * @return numeric The result of the division or zero
+ */
static public function secureDiv( $i1, $i2 )
{
if ( is_numeric($i1) && is_numeric($i2) && floatval($i2) != 0)
@@ -589,9 +596,9 @@
// at this point we have only the piwik tables which is good
// but we still miss the piwik generated tables (using the class Piwik_TablePartitioning)
- $allArchiveNumeric = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."archive_numeric%'");
- $allArchiveBlob = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."archive_blob%'");
-
+ $allArchiveNumeric = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."archive_numeric%'");
+ $allArchiveBlob = $db->fetchCol("SHOW TABLES LIKE '".$prefixTables."archive_blob%'");
+
$allTablesReallyInstalled = array_merge($tablesInstalled, $allArchiveNumeric, $allArchiveBlob);
return $allTablesReallyInstalled;
Modified: trunk/modules/TablePartitioning.php
===================================================================
--- trunk/modules/TablePartitioning.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/TablePartitioning.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -1,5 +1,8 @@
<?php
/**
+ *
+ * NB: When a new table is partitionned using this class, we have to update the method
+ * Piwik::getTablesInstalled() to add the new table to the list of tablename_* to fetch
*
* @package Piwik
*/
Modified: trunk/modules/Url.php
===================================================================
--- trunk/modules/Url.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/Url.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -12,13 +12,23 @@
static function getCurrentQueryStringWithParametersModified( $params )
{
$urlValues = self::getArrayFromCurrentQueryString();
+
// var_dump($urlValues);
foreach($params as $key => $value)
{
$urlValues[$key] = $value;
}
- return '?' . http_build_query($urlValues);
+ $query = http_build_query($urlValues);
+
+ if(strlen($query) > 0)
+ {
+ return '?'.$query;
+ }
+ else
+ {
+ return '';
+ }
}
static public function redirectToUrl( $url )
Modified: trunk/modules/ViewDataTable/Html.php
===================================================================
--- trunk/modules/ViewDataTable/Html.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/ViewDataTable/Html.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -59,10 +59,8 @@
$view->nbColumns = $nbColumns;
- $view->javascriptVariablesToSet
- = $this->getJavascriptVariablesToSet();
+ $view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
-
$this->view = $view;
}
Modified: trunk/modules/ViewDataTable.php
===================================================================
--- trunk/modules/ViewDataTable.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/modules/ViewDataTable.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -77,7 +77,9 @@
$this->idSubtable = Piwik_Common::getRequestVar('idSubtable', false, 'int');
- $this->method = $moduleNameAndMethod;
+ $this->method = $moduleNameAndMethod;
+
+
$this->variablesDefault['filter_excludelowpop_default'] = 'false';
$this->variablesDefault['filter_excludelowpop_value_default'] = 'false';
}
@@ -309,20 +311,27 @@
}
- public function setExcludeLowPopulation( $value = 30 )
+ public function setExcludeLowPopulation( $value = null )
{
- $this->variablesDefault['filter_excludelowpop_default'] = 2;
- $this->variablesDefault['filter_excludelowpop_value_default'] = $value;
- $this->variablesDefault['filter_excludelowpop'] = 2;
- $this->variablesDefault['filter_excludelowpop_value'] = $value;
+ if( is_null( $value) )
+ {
+ throw new Exception("setExcludeLowPopulation() value shouldn't be null");
+ }
+
+ // column to use to enable low population exclusion if != false
+ $this->variablesDefault['filter_excludelowpop_default']
+ = $this->variablesDefault['filter_excludelowpop']
+ = 2;
+
+ // the minimum value a row must have to be returned
+ $this->variablesDefault['filter_excludelowpop_value_default']
+ = $this->variablesDefault['filter_excludelowpop_value']
+ = $value;
}
-
-
public function setDefaultLimit( $limit )
{
$this->variablesDefault['filter_limit'] = $limit;
}
-
-
+
}
\ No newline at end of file
Modified: trunk/plugins/Home/Controller.php
===================================================================
--- trunk/plugins/Home/Controller.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/plugins/Home/Controller.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -156,7 +156,12 @@
$view->setColumnsToDisplay( array(0,1) );
$view->setDefaultLimit( 100 );
- $view->setExcludeLowPopulation( 5 );
+
+ // computing minimum value to exclude
+ $visitsInfo = $this->getVisitsSummary();
+ $nbActions = $visitsInfo->getColumn('nb_actions');
+ $nbActionsLowPopulationThreshold = floor(0.02 * $nbActions); // 2 percent of the total number of actions
+ $view->setExcludeLowPopulation( $nbActionsLowPopulationThreshold );
$view->main();
// we need to rewrite the phpArray so it contains all the recursive arrays
@@ -238,10 +243,10 @@
return $this->renderView($view, $fetch);
}
function getOutlinks($fetch = false)
- {
+ {
$view = $this->getActionsView( __FUNCTION__,
'Actions.getOutlinks',
- 'getOutlinksSubDataTable' );
+ 'getOutlinksSubDataTable' );
return $this->renderView($view, $fetch);
}
@@ -259,7 +264,7 @@
*/
function getVisitsSummary()
{
- $requestString = 'method='."VisitsSummary.get".'&format=original';
+ $requestString = 'method=' . "VisitsSummary.get" . '&format=original';
$request = new Piwik_API_Request($requestString);
return $request->process();
}
Modified: trunk/plugins/Installation/Controller.php
===================================================================
--- trunk/plugins/Installation/Controller.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/plugins/Installation/Controller.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -395,8 +395,8 @@
protected function getSystemInformation()
{
- $minimumPhpVersion = Zend_Registry::get('config')->General->minimumPhpVersion;
- $minimumMemoryLimit = Zend_Registry::get('config')->General->minimumMemoryLimit;
+ $minimumPhpVersion = Zend_Registry::get('config')->General->minimum_php_version;
+ $minimumMemoryLimit = Zend_Registry::get('config')->General->minimum_memory_limit;
$infos = array();
Modified: trunk/plugins/UsersManager/API.php
===================================================================
--- trunk/plugins/UsersManager/API.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/plugins/UsersManager/API.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -43,7 +43,6 @@
*
* @return array the list of all the users login
*/
- //TODO test this method
static public function getUsersLogin()
{
Piwik::checkUserHasSomeAdminAccess();
@@ -248,8 +247,9 @@
self::checkEmail($email);
$alias = self::getCleanAlias($alias,$userLogin);
- $token_auth = self::getTokenAuth($userLogin,$password);
$passwordTransformed = self::getCleanPassword($password);
+
+ $token_auth = self::getTokenAuth($userLogin, $passwordTransformed);
$db = Zend_Registry::get('db');
Modified: trunk/tests/config_test.php
===================================================================
--- trunk/tests/config_test.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/tests/config_test.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -11,9 +11,11 @@
if(!defined('PIWIK_INCLUDE_PATH'))
{
define('PIWIK_INCLUDE_PATH', PATH_TEST_TO_ROOT);
-}
+}
-set_include_path(PATH_TEST_TO_ROOT .'/'
+set_include_path( PATH_TEST_TO_ROOT .'/'
+ . PATH_SEPARATOR . PATH_TEST_TO_ROOT .'/../'
+ . PATH_SEPARATOR . '../' . PATH_TEST_TO_ROOT
. PATH_SEPARATOR . getcwd()
. PATH_SEPARATOR . getcwd() . '/../'
. PATH_SEPARATOR . PATH_TEST_TO_ROOT2
@@ -35,8 +37,9 @@
. PATH_SEPARATOR . PATH_TEST_TO_ROOT2 . '/config/'
. PATH_SEPARATOR . PATH_TEST_TO_ROOT2 . '/plugins/'
. PATH_SEPARATOR . PATH_TEST_TO_ROOT2 . '/modules/'
- . PATH_SEPARATOR . PATH_TEST_TO_ROOT2 . '/tests/'
- . PATH_SEPARATOR . get_include_path()
+ . PATH_SEPARATOR . PATH_TEST_TO_ROOT2 . '/tests/'
+ . PATH_SEPARATOR . get_include_path()
+ . PATH_SEPARATOR . get_include_path() . '../'
);
require_once 'simpletest/autorun.php';
Modified: trunk/tests/modules/ArchiveProcessing/Day.test.php
===================================================================
--- trunk/tests/modules/ArchiveProcessing/Day.test.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/tests/modules/ArchiveProcessing/Day.test.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -25,11 +25,10 @@
{
}
- //TODO test with a label in the column list that is composed of numbers only
function test_generateDataTable_simple()
{
$row1 = new Piwik_DataTable_Row( array( Piwik_DataTable_Row::COLUMNS =>
- array( 'label' => 'page1', 'visits' => 1, 'actions' => 2)));
+ array( 'label' => 'page1', 'visits' => 1, 'actions' => 2, '666' => 'evil' )));
$input = array(
'page1' => $row1,
Added: trunk/tests/modules/LogStats_Db.test.php
===================================================================
--- trunk/tests/modules/LogStats_Db.test.php (rev 0)
+++ trunk/tests/modules/LogStats_Db.test.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -0,0 +1,37 @@
+<?php
+if(!defined("PATH_TEST_TO_ROOT")) {
+ define('PATH_TEST_TO_ROOT', '..');
+}
+if(!defined('CONFIG_TEST_INCLUDED'))
+{
+ require_once PATH_TEST_TO_ROOT ."/../tests/config_test.php";
+}
+
+require 'LogStats/Db.php';
+//Zend_Loader::loadClass('Piwik_');
+
+class Test_Piwik_LogStats_Db extends UnitTestCase
+{
+ function __construct( $title = '')
+ {
+ parent::__construct( $title );
+ }
+
+ public function setUp()
+ {
+ }
+
+ public function tearDown()
+ {
+ }
+
+
+ /**
+ * test that the profiler is disabled (mandatory on a production server)
+ */
+ public function test_profilingDisabledProduction()
+ {
+ $this->assertTrue(Piwik_LogStats_Db::isProfilingEnabled() === false, 'PROFILER SHOULD BE DISABLED IN PRODUCTION!! See Piwik_LogStats_Db::$profiling');
+ }
+}
+
Modified: trunk/tests/modules/PHP_Related.test.php
===================================================================
--- trunk/tests/modules/PHP_Related.test.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/tests/modules/PHP_Related.test.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -86,9 +86,9 @@
usort($a, "countSort");
// in the function used count nb of times called
- print("called ".self::$countSort." times to sort the 1000 elements array");
+// print("called ".self::$countSort." times to sort the 1000 elements array");
- echo $timer;
+// echo $timer;
}
/**
@@ -135,10 +135,9 @@
$xml = array_to_simplexml($test);
- print("<pre>START");print($xml);print("START2");
- print_r($xml->asXML());
-
- print("</pre>");
+// print("<pre>START");print($xml);print("START2");
+// print_r($xml->asXML());
+// print("</pre>");
}
/**
* misc tests for performance
Modified: trunk/tests/modules/Piwik.test.php
===================================================================
--- trunk/tests/modules/Piwik.test.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/tests/modules/Piwik.test.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -71,6 +71,17 @@
{
$this->assertFalse(Piwik::isValidFilename($toTest), $toTest." valid but shouldn't!");
}
+ }
+
+ public function test_secureDiv()
+ {
+ $this->assertTrue( Piwik::secureDiv( 9,3 ) === 3 );
+ $this->assertTrue( Piwik::secureDiv( 9,0 ) === 0 );
+ $this->assertTrue( Piwik::secureDiv( 10,1 ) === 10 );
+ $this->assertTrue( Piwik::secureDiv( 10.0, 1.0 ) === 10.0 );
+ $this->assertTrue( Piwik::secureDiv( 11.0, 2 ) === 5.5 );
+ $this->assertTrue( Piwik::secureDiv( 11.0, 'a' ) === 0 );
+
}
}
Modified: trunk/tests/modules/SitesManager.test.php
===================================================================
--- trunk/tests/modules/SitesManager.test.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/tests/modules/SitesManager.test.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -1,11 +1,11 @@
<?php
-if(!defined("PATH_TEST_TO_ROOT")) {
- define('PATH_TEST_TO_ROOT', '..');
+if(!defined("PATH_TEST_TO_ROOT")) {
+ define('PATH_TEST_TO_ROOT', getcwd().'/../../');
+}
+if(!defined('CONFIG_TEST_INCLUDED'))
+{
+ require_once PATH_TEST_TO_ROOT."tests/config_test.php";
}
-if(!defined('CONFIG_TEST_INCLUDED'))
-{
- require_once PATH_TEST_TO_ROOT ."/../tests/config_test.php";
-}
require_once "Database.test.php";
require_once 'SitesManager/API.php';
Modified: trunk/tests/modules/TablePartitioning.test.php
===================================================================
--- trunk/tests/modules/TablePartitioning.test.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/tests/modules/TablePartitioning.test.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -1,14 +1,14 @@
<?php
if(!defined("PATH_TEST_TO_ROOT")) {
- define('PATH_TEST_TO_ROOT', '..');
+ define('PATH_TEST_TO_ROOT', getcwd().'/../../');
}
if(!defined('CONFIG_TEST_INCLUDED'))
{
- require_once PATH_TEST_TO_ROOT ."/../tests/config_test.php";
+ require_once PATH_TEST_TO_ROOT."tests/config_test.php";
}
require_once "Database.test.php";
-Zend_Loader::loadClass('Piwik_TablePartitioning');
+require_once 'TablePartitioning.php';
class Test_Piwik_TablePartitioning extends Test_Database
{
function __construct()
@@ -37,7 +37,7 @@
// test table absent => create
function test_noTable()
{
- $tableName ='log_visit';
+ $tableName ='archive_numeric';
$p = new Piwik_TablePartitioning_Monthly($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09";
@@ -47,8 +47,9 @@
$p->setTimestamp( $timestamp );
- $allTablesInstalled = Piwik::getTablesInstalled();
- $this->assertTrue( in_array($tablename, $allTablesInstalled));
+ $allTablesInstalled = Piwik::getTablesInstalled();
+
+ $this->assertTrue( in_array($tablename, $allTablesInstalled), "$tablename !==".var_export($allTablesInstalled,true));
$this->assertTrue( $tablename, $p->getTableName());
$this->assertEqual( $tablename, (string)$p);
}
@@ -56,7 +57,7 @@
// test table present => nothing
function test_tablePresent()
{
- $tableName ='log_visit';
+ $tableName ='archive_numeric';
$p = new Piwik_TablePartitioning_Monthly($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09";
@@ -78,7 +79,7 @@
function test_monthlyPartition()
{
- $tableName ='log_visit';
+ $tableName ='archive_numeric';
$p = new Piwik_TablePartitioning_Monthly($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09";
@@ -98,7 +99,7 @@
function test_dailyPartition()
{
- $tableName ='log_visit';
+ $tableName ='archive_numeric';
$p = new Piwik_TablePartitioning_Daily($tableName);
$timestamp = strtotime("10 September 2000");
$suffixShouldBe = "_2000_09_10";
Modified: trunk/tests/modules/UsersManager.test.php
===================================================================
--- trunk/tests/modules/UsersManager.test.php 2008-01-10 21:19:43 UTC (rev 141)
+++ trunk/tests/modules/UsersManager.test.php 2008-01-11 00:19:26 UTC (rev 142)
@@ -1,11 +1,11 @@
<?php
-if(!defined("PATH_TEST_TO_ROOT")) {
- define('PATH_TEST_TO_ROOT', '..');
-}
-if(!defined('CONFIG_TEST_INCLUDED'))
-{
- require_once PATH_TEST_TO_ROOT ."/../tests/config_test.php";
-}
+if(!defined("PATH_TEST_TO_ROOT")) {
+ define('PATH_TEST_TO_ROOT', getcwd().'/../../');
+}
+if(!defined('CONFIG_TEST_INCLUDED'))
+{
+ require_once PATH_TEST_TO_ROOT."tests/config_test.php";
+}
require_once "Database.test.php";
@@ -31,7 +31,59 @@
FakeAccess::$superUser = true;
Zend_Registry::set('access', $pseudoMockAccess);
- }
+ }
+
+ private function _checkUserHasNotChanged($user, $newPassword, $newEmail = null, $newAlias= null)
+ {
+ if(is_null($newEmail))
+ {
+ $newEmail = $user['email'];
+ }
+ if(is_null($newAlias))
+ {
+ $newAlias = $user['alias'];
+ }
+ $userAfter = Piwik_UsersManager_API::getUser($user["login"]);
+ unset($userAfter['date_registered']);
+
+ // we now compute what the token auth should be, it should always be a hash of the login and the current password
+ // if the password has changed then the token_auth has changed!
+ $user['token_auth']= Piwik_UsersManager_API::getTokenAuth($user["login"], md5($newPassword) );
+
+ $user['password']=md5($newPassword);
+ $user['email']=$newEmail;
+ $user['alias']=$newAlias;
+ $this->assertEqual($user,$userAfter);
+ }
+
+ /**
+ * bad password => exception
+ */
+ function test_updateUser_badpasswd()
+ {
+ $login="login";
+ $user = array('login'=>$login,
+ 'password'=>"geqgeagae",
+ 'email'=>"test at test.com",
+ 'alias'=>"alias");
+
+ Piwik_UsersManager_API::addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
+
+
+ try {
+ Piwik_UsersManager_API::updateUser( $login, "pas");
+ }
+ catch (Exception $expected) {
+ $this->assertPattern("(password)", $expected->getMessage());
+
+ $this->_checkUserHasNotChanged($user,$user['password']);
+ return;
+ }
+ $this->fail("Exception not raised.");
+
+ }
+//} class test{
+
/**
* wrong login / integer => exception
*/
@@ -278,7 +330,7 @@
$this->assertEqual(strlen($user['password']), 32);
// that the password has been md5
- $this->assertEqual($user['token_auth'], md5($login.$password));
+ $this->assertEqual($user['token_auth'], md5($login.md5($password)));
// check that all fields are the same
$this->assertEqual($user['login'], $login);
@@ -447,6 +499,23 @@
);
}
+
+ /**
+ * normal case
+ */
+ function test_getUsersLogin()
+ {
+
+ Piwik_UsersManager_API::addUser("gegg4564eqgeqag", "geqgegagae", "tegst at tesgt.com", "alias");
+ Piwik_UsersManager_API::addUser("geggeqge632ge56a4qag", "geqgegeagae", "tesggt at tesgt.com", "alias");
+ Piwik_UsersManager_API::addUser("geggeqgeqagqegg", "geqgeaggggae", "tesgggt at tesgt.com");
+
+ $logins = Piwik_UsersManager_API::getUsersLogin();
+
+ $this->assertEqual($logins,
+ array( "gegg4564eqgeqag", "geggeqge632ge56a4qag", "geggeqgeqagqegg")
+ );
+ }
/**
@@ -715,52 +784,7 @@
$this->fail("Exception not raised.");
}
- /**
- * bad password => exception
- */
- function test_updateUser_badpasswd()
- {
- $login="login";
- $user = array('login'=>$login,
- 'password'=>"geqgeagae",
- 'email'=>"test at test.com",
- 'alias'=>"alias");
-
- Piwik_UsersManager_API::addUser($user['login'],$user['password'] ,$user['email'] ,$user['alias'] );
-
-
- try {
- Piwik_UsersManager_API::updateUser( $login, "pas");
- }
- catch (Exception $expected) {
- $this->assertPattern("(password)", $expected->getMessage());
-
- $this->_checkUserHasNotChanged($user,$user['password']);
- return;
- }
- $this->fail("Exception not raised.");
- }
- private function _checkUserHasNotChanged($user, $newPassword, $newEmail = null, $newAlias= null)
- {
- if(is_null($newEmail))
- {
- $newEmail = $user['email'];
- }
- if(is_null($newAlias))
- {
- $newAlias = $user['alias'];
- }
- $userAfter = Piwik_UsersManager_API::getUser($user["login"]);
- unset($userAfter['date_registered']);
- $user['token_auth']= Piwik_UsersManager_API::getTokenAuth($user["login"], $newPassword );
-
- $user['password']=md5($newPassword);
- $user['email']=$newEmail;
- $user['alias']=$newAlias;
- $this->assertEqual($user,$userAfter);
- }
-
/**
* no email no alias => keep old ones
*/
More information about the Piwik-svn
mailing list