diff --git a/config/global.ini.php b/config/global.ini.php index 4972d400965cd1cc9cf578395ba7d3bd5e7f1bf5..580abafd46448bc2ac80a86e929fb2f9e0092560 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -29,7 +29,7 @@ schema = Mysql [database_tests] host = localhost -username = root +username = "@USERNAME@" password = dbname = piwik_tests tables_prefix = piwiktests_ diff --git a/core/Updates/2.11.1-b3.php b/core/Updates/2.11.1-b3.php new file mode 100644 index 0000000000000000000000000000000000000000..ebb82cabcfe42db4dc8a269b1f4812cb9bcb0e1c --- /dev/null +++ b/core/Updates/2.11.1-b3.php @@ -0,0 +1,39 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ + +namespace Piwik\Updates; + +use Piwik\Config; +use Piwik\Development; +use Piwik\Updates; + +class Updates_2_11_1_b3 extends Updates +{ + /** + * Here you can define any action that should be performed during the update. For instance executing SQL statements, + * renaming config entries, updating files, etc. + */ + static function update() + { + if (!Development::isEnabled()) { + return; + } + + $config = Config::getInstance(); + $dbTests = $config->database_tests; + + if ($dbTests['username'] === '@USERNAME@') { + $dbTests['username'] = 'root'; + } + + $config->database_tests = $dbTests; + + $config->forceSave(); + } +} diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php index 3a9cf799dbd35e15081e1041963e4db10aae4d7d..5a7eb7bce2d4ced0fead7406ae82f87b31329eef 100644 --- a/tests/PHPUnit/bootstrap.php +++ b/tests/PHPUnit/bootstrap.php @@ -2,8 +2,9 @@ use Piwik\Container\StaticContainer; use Piwik\Http; -use Piwik\Tests\Framework\Fixture; use Piwik\Intl\Locale; +use Piwik\Config; +use Piwik\SettingsPiwik; define('PIWIK_TEST_MODE', true); define('PIWIK_PRINT_ERROR_BACKTRACE', false); @@ -60,9 +61,9 @@ foreach($fixturesToLoad as $fixturePath) { Locale::setDefaultLocale(); -function prepareServerVariables() +function prepareServerVariables(Config $config) { - $testConfig = \Piwik\Config::getInstance()->tests; + $testConfig = $config->tests; if ('@REQUEST_URI@' === $testConfig['request_uri']) { // config not done yet, if Piwik is installed we can automatically configure request_uri and http_host @@ -72,8 +73,8 @@ function prepareServerVariables() $parsedUrl = parse_url($url); $testConfig['request_uri'] = $parsedUrl['path']; $testConfig['http_host'] = $parsedUrl['host']; - \Piwik\Config::getInstance()->tests = $testConfig; - \Piwik\Config::getInstance()->forceSave(); + $config->tests = $testConfig; + $config->forceSave(); } } @@ -82,13 +83,41 @@ function prepareServerVariables() $_SERVER['REMOTE_ADDR'] = $testConfig['remote_addr']; } -prepareServerVariables(); +function prepareTestDatabaseConfig(Config $config) +{ + $testDb = $config->database_tests; + + if ('@USERNAME@' !== $testDb['username']) { + return; // testDb is already configured, we do not want to overwrite any existing settings. + } + + $db = $config->database; + $testDb['username'] = $db['username']; + + if (empty($testDb['password'])) { + $testDb['password'] = $db['password']; + } + + if (empty($testDb['host'])) { + $testDb['host'] = $db['host']; + } -// General requirement checks & help: a webserver must be running for tests to work if not running UnitTests! -if (empty($_SERVER['argv']) || !in_array('UnitTests', $_SERVER['argv'])) { - checkPiwikSetupForTests(); + $testDb['tables_prefix'] = ''; // tables_prefix has to be empty for UI tests + + $config->database_tests = $testDb; + $config->forceSave(); +} + +if (!SettingsPiwik::isPiwikInstalled()) { + throw new Exception('Piwik needs to be installed in order to run the tests'); } +$config = Config::getInstance(); +$config->init(); +prepareServerVariables($config); +prepareTestDatabaseConfig($config); +checkPiwikSetupForTests(); + function checkPiwikSetupForTests() { if (empty($_SERVER['REQUEST_URI']) @@ -108,22 +137,4 @@ Try again."; exit(1); } - $url = Fixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php?module=TestRunner&action=check'; - $response = Http::sendHttpRequestBy('curl', $url, 5); - - if ($response === 'OK' - // The SQL error is for Travis... - || strpos($response, 'Table 'piwik_tests.option' doesn't exist') !== false - || strpos($response, 'Table 'piwik_tests.piwiktests_option' doesn't exist') !== false - || strpos($response, 'Unknown database 'piwik_tests'') !== false - || strpos($response, '<title>Piwik › Update</title>') !== false - ) { - return; - } - - throw new Exception(sprintf( - "Piwik should be running at %s but this URL returned an unexpected response: '%s'", - $url, - $response - )); }