Skip to content

Commit

Permalink
Make UI tests use the test config in config.ini.php
Browse files Browse the repository at this point in the history
The command that runs UI tests now writes a /tests/UI/config.js file that contains the variable configured in config.ini.php. If a file already exists and wasn't autogenerated by this command, it is not overwritten.

That allows to run UI tests with another remote than localhost, which happens for example with Docker where phantomjs runs in another container than Piwik.
  • Loading branch information
mnapoli committed Jul 21, 2015
1 parent cbf4f92 commit 2bbee20
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions plugins/TestRunner/Commands/TestsRunUI.php
Expand Up @@ -8,7 +8,9 @@
namespace Piwik\Plugins\TestRunner\Commands;

use Piwik\AssetManager;
use Piwik\Config;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Tests\Framework\Fixture;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -47,6 +49,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
AssetManager::getInstance()->removeMergedAssets();
}

$this->writeJsConfig();

$options = array();
if ($persistFixtureData) {
$options[] = "--persist-fixture-data";
Expand Down Expand Up @@ -87,4 +91,40 @@ protected function execute(InputInterface $input, OutputInterface $output)

passthru($cmd);
}

/**
* We override the default values of tests/UI/config.dist.js with config
* values from the local INI config.
*/
private function writeJsConfig()
{
$localConfigFile = PIWIK_INCLUDE_PATH . '/tests/UI/config.js';
$tag = 'File generated by the tests:run-ui command';

// If the file wasn't generated by this command, we don't ovewrite it
if (file_exists($localConfigFile)) {
$fileContent = file_get_contents($localConfigFile);
if (strpos($fileContent, $tag) === false) {
return;
}
}

$url = Fixture::getRootUrl();
$host = Config::getInstance()->tests['http_host'];
$uri = Config::getInstance()->tests['request_uri'];

$js = <<<JS
/**
* $tag
*/
exports.piwikUrl = "$url";
exports.phpServer = {
HTTP_HOST: '$host',
REQUEST_URI: '$uri',
REMOTE_ADDR: '127.0.0.1'
};
JS;

file_put_contents(PIWIK_INCLUDE_PATH . '/tests/UI/config.js', $js);
}
}

0 comments on commit 2bbee20

Please sign in to comment.