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
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/
* If not found, then tries to cache it and returns the value.
......@@ -146,29 +153,34 @@ class Piwik
*/
static public function getPiwikUrl()
{
$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'))
{
return $url;
}
$currentUrl = Piwik_Common::sanitizeInputValue(Piwik_Url::getCurrentUrlWithoutFileName());
if(empty($url)
// if URL changes, always update the cache
|| $currentUrl != $url)
if (self::$piwikUrlCache === null)
{
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
public static function setUpBeforeClass( $dbName = false, $createEmptyDatabase = true, $createConfig = true )
{
try {
Piwik::$piwikUrlCache = '';
if ($createConfig)
{
self::createTestConfig();
......@@ -117,6 +119,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase
public static function tearDownAfterClass( $dropDatabase = true )
{
Piwik::$piwikUrlCache = null;
try {
$plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins();
foreach($plugins AS $plugin) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter