Skip to content
Extraits de code Groupes Projets
Valider 57eee9b9 rédigé par benakamoorthi's avatar benakamoorthi
Parcourir les fichiers

Cache result of Piwik::getPiwikUrl and overwrite in tests so scheduled report...

Cache result of Piwik::getPiwikUrl and overwrite in tests so scheduled report tests pass in visualphpunit.


git-svn-id: http://dev.piwik.org/svn/trunk@7463 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent a59cf05a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -136,6 +136,13 @@ class Piwik ...@@ -136,6 +136,13 @@ class Piwik
Piwik_Common::deleteTrackerCache(); Piwik_Common::deleteTrackerCache();
} }
/**
* Cache for result of getPiwikUrl. Can be overwritten for testing purposes.
*
* @var string
*/
static public $piwikUrlCache = null;
/** /**
* Returns the cached the Piwik URL, eg. http://demo.piwik.org/ or http://example.org/piwik/ * Returns the cached the Piwik URL, eg. http://demo.piwik.org/ or http://example.org/piwik/
* If not found, then tries to cache it and returns the value. * If not found, then tries to cache it and returns the value.
...@@ -146,29 +153,34 @@ class Piwik ...@@ -146,29 +153,34 @@ class Piwik
*/ */
static public function getPiwikUrl() static public function getPiwikUrl()
{ {
$key = 'piwikUrl'; if (self::$piwikUrlCache === null)
$url = Piwik_GetOption($key);
if(Piwik_Common::isPhpCliMode()
// in case archive.php is triggered with domain localhost
|| Piwik_Common::isArchivePhpTriggered()
|| defined('PIWIK_MODE_ARCHIVE'))
{
return $url;
}
$currentUrl = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrlWithoutFileName());
if(empty($url)
// if URL changes, always update the cache
|| $currentUrl != $url)
{ {
if(strlen($currentUrl) >= strlen('http://a/')) $key = 'piwikUrl';
$url = Piwik_GetOption($key);
if(Piwik_Common::isPhpCliMode()
// in case archive.php is triggered with domain localhost
|| Piwik_Common::isArchivePhpTriggered()
|| defined('PIWIK_MODE_ARCHIVE'))
{ {
Piwik_SetOption($key, $currentUrl, $autoload = true); $piwikUrlCache = $url;
}
else
{
$currentUrl = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrlWithoutFileName());
if(empty($url)
// if URL changes, always update the cache
|| $currentUrl != $url)
{
if(strlen($currentUrl) >= strlen('http://a/'))
{
Piwik_SetOption($key, $currentUrl, $autoload = true);
}
$url = $currentUrl;
}
} }
$url = $currentUrl;
} }
return $url; return self::$piwikUrlCache;
} }
/* /*
......
...@@ -49,6 +49,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase ...@@ -49,6 +49,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
public static function setUpBeforeClass( $dbName = false, $createEmptyDatabase = true, $createConfig = true ) public static function setUpBeforeClass( $dbName = false, $createEmptyDatabase = true, $createConfig = true )
{ {
try { try {
Piwik::$piwikUrlCache = '';
if ($createConfig) if ($createConfig)
{ {
self::createTestConfig(); self::createTestConfig();
...@@ -117,6 +119,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase ...@@ -117,6 +119,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
public static function tearDownAfterClass( $dropDatabase = true ) public static function tearDownAfterClass( $dropDatabase = true )
{ {
Piwik::$piwikUrlCache = null;
try { try {
$plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins(); $plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins();
foreach($plugins AS $plugin) { foreach($plugins AS $plugin) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter