Skip to content

Commit

Permalink
adding failing integration test for this issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Dec 15, 2014
1 parent 732b759 commit 4000817
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion tests/PHPUnit/Integration/TrackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Piwik\Tests\Integration;

use Piwik\Common;
use Piwik\Config;
use Piwik\EventDispatcher;
use Piwik\Piwik;
use Piwik\Plugin;
Expand Down Expand Up @@ -66,7 +67,10 @@ public function setUp()

public function tearDown()
{
$this->tracker->disconnectDatabase();
$this->restoreConfigFile();
if($this->tracker) {
$this->tracker->disconnectDatabase();
}
EventDispatcher::getInstance()->clearObservers('Tracker.makeNewVisitObject');
if (array_key_exists('PIWIK_TRACKER_DEBUG', $GLOBALS)) {
unset($GLOBALS['PIWIK_TRACKER_DEBUG']);
Expand Down Expand Up @@ -126,13 +130,40 @@ public function test_loadTrackerEnvironment_shouldSetGlobalsDebugVar()

public function test_loadTrackerEnvironment_shouldEnableTrackerMode()
{
$this->assertTrue(!array_key_exists('PIWIK_TRACKER_DEBUG', $GLOBALS));

$this->assertFalse(SettingsServer::isTrackerApiRequest());

Tracker::loadTrackerEnvironment();

$this->assertTrue(SettingsServer::isTrackerApiRequest());
}

public function test_loadTrackerEnvironment_shouldNotThrow_whenConfigNotFound()
{
$this->assertTrue(!array_key_exists('PIWIK_TRACKER_DEBUG', $GLOBALS));

$this->assertFalse(SettingsServer::isTrackerApiRequest());

$this->assertTrue(Config::getInstance()->existsLocalConfig());

$this->removeConfigFile();
Config::getInstance()->clear();

$this->assertFalse(Config::getInstance()->existsLocalConfig());

Tracker::loadTrackerEnvironment();

$this->assertTrue(SettingsServer::isTrackerApiRequest());
}

protected function restoreConfigFile()
{
$backupConfig = $this->getLocalConfigPathMoved();
$localConfig = $this->getLocalConfigPath();
@shell_exec("mv $backupConfig $localConfig 2> /dev/null");
}

public function test_isDatabaseConnected_shouldReturnFalse_IfNotConnected()
{
$this->tracker->disconnectDatabase();
Expand Down Expand Up @@ -318,4 +349,31 @@ private function buildRequest($params)
return new Request($params);
}

/**
* @return string
*/
protected function getLocalConfigPath()
{
return PIWIK_USER_PATH . "/config/config.ini.php ";
}

/**
* @return string
*/
protected function getLocalConfigPathMoved()
{
return PIWIK_USER_PATH . "/config/tmp-config.ini.php";
}

/**
* @return array
*/
protected function removeConfigFile()
{
$localConfig = $this->getLocalConfigPath();
$backupConfig = $this->getLocalConfigPathMoved();
shell_exec("mv $localConfig $backupConfig");
return array($localConfig, $backupConfig);
}

}

0 comments on commit 4000817

Please sign in to comment.