mirror of
https://github.com/phpbb/phpbb.git
synced 2025-01-17 22:28:46 +01:00
[feature/functional-tests] Configure functional tests through config file
The functional tests now also use the test database PHPBB3-10414
This commit is contained in:
parent
637d8eabe7
commit
0ffe494edd
@ -40,46 +40,14 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||
|
||||
public function get_database_config()
|
||||
{
|
||||
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
||||
{
|
||||
return array(
|
||||
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
|
||||
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
|
||||
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
|
||||
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
|
||||
'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '',
|
||||
'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : '',
|
||||
);
|
||||
}
|
||||
else if (file_exists(dirname(__FILE__) . '/../test_config.php'))
|
||||
{
|
||||
include(dirname(__FILE__) . '/../test_config.php');
|
||||
$config = phpbb_test_case_helpers::get_test_config();
|
||||
|
||||
return array(
|
||||
'dbms' => $dbms,
|
||||
'dbhost' => $dbhost,
|
||||
'dbport' => $dbport,
|
||||
'dbname' => $dbname,
|
||||
'dbuser' => $dbuser,
|
||||
'dbpasswd' => $dbpasswd,
|
||||
);
|
||||
}
|
||||
else if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
|
||||
{
|
||||
// Silently use sqlite
|
||||
return array(
|
||||
'dbms' => 'sqlite',
|
||||
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
|
||||
'dbport' => '',
|
||||
'dbname' => '',
|
||||
'dbuser' => '',
|
||||
'dbpasswd' => '',
|
||||
);
|
||||
}
|
||||
else
|
||||
if (!isset($config['dbms']))
|
||||
{
|
||||
$this->markTestSkipped('Missing test_config.php: See first error.');
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function getConnection()
|
||||
|
@ -14,6 +14,8 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
protected $client;
|
||||
protected $root_url;
|
||||
|
||||
static protected $config;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->client = new Goutte\Client();
|
||||
@ -29,35 +31,32 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
if (!isset($_SERVER['PHPBB_FUNCTIONAL_URL']))
|
||||
self::$config = phpbb_test_case_helpers::get_test_config();
|
||||
|
||||
if (!isset(self::$config['phpbb_functional_url']))
|
||||
{
|
||||
self::markTestSkipped("The 'PHPBB_FUNCTIONAL_URL' environment variable was not set.");
|
||||
self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
|
||||
}
|
||||
|
||||
if (!file_exists($phpbb_root_path . "config.$phpEx"))
|
||||
self::$config['table_prefix'] = 'phpbb_';
|
||||
self::recreate_database(self::$config);
|
||||
|
||||
if (file_exists($phpbb_root_path . "config.$phpEx"))
|
||||
{
|
||||
self::markTestSkipped("config.php does not exist, it is required for running functional tests.");
|
||||
if (!file_exists($phpbb_root_path . "config_dev.$phpEx"))
|
||||
{
|
||||
rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx");
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($phpbb_root_path . "config.$phpEx");
|
||||
}
|
||||
}
|
||||
|
||||
require $phpbb_root_path . "config.$phpEx";
|
||||
|
||||
$db_config = array(
|
||||
'dbhost' => $dbhost,
|
||||
'dbport' => $dbport,
|
||||
'dbname' => $dbname,
|
||||
'dbuser' => $dbuser,
|
||||
'dbpasswd' => $dbpasswd,
|
||||
'dbms' => $dbms,
|
||||
'table_prefix' => 'phpbb_',
|
||||
);
|
||||
self::recreate_database($db_config);
|
||||
|
||||
rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "_config.$phpEx");
|
||||
|
||||
// begin data
|
||||
$data = array();
|
||||
|
||||
$data = array_merge($data, $db_config);
|
||||
$data = array_merge($data, self::$config);
|
||||
|
||||
$data = array_merge($data, array(
|
||||
'default_lang' => 'en',
|
||||
@ -68,7 +67,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
'board_email2' => 'nobody@example.com',
|
||||
));
|
||||
|
||||
$parseURL = parse_url($_SERVER['PHPBB_FUNCTIONAL_URL']);
|
||||
$parseURL = parse_url(self::$config['phpbb_functional_url']);
|
||||
|
||||
$data = array_merge($data, array(
|
||||
'email_enable' => false,
|
||||
@ -89,16 +88,23 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
$content = self::do_request('install');
|
||||
self::assertContains('Welcome to Installation', $content);
|
||||
|
||||
self::do_request('create_table', $data);
|
||||
|
||||
self::do_request('config_file', $data);
|
||||
|
||||
rename($phpbb_root_path . "_config.$phpEx", $phpbb_root_path . "config.$phpEx");
|
||||
if (file_exists($phpbb_root_path . "config.$phpEx"))
|
||||
{
|
||||
copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
|
||||
}
|
||||
|
||||
self::do_request('create_table', $data);
|
||||
self::do_request('final', $data);
|
||||
}
|
||||
|
||||
static public function tearDownAfterClass()
|
||||
{
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
copy($phpbb_root_path . "config_dev.$phpEx", $phpbb_root_path . "config.$phpEx");
|
||||
}
|
||||
|
||||
static private function do_request($sub, $post_data = null)
|
||||
@ -117,7 +123,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
));
|
||||
}
|
||||
|
||||
return file_get_contents($_SERVER['PHPBB_FUNCTIONAL_URL'] . 'install/index.php?mode=install&sub=' . $sub, false, $context);
|
||||
return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context);
|
||||
}
|
||||
|
||||
static private function recreate_database($config)
|
||||
|
@ -46,4 +46,56 @@ class phpbb_test_case_helpers
|
||||
{
|
||||
mkdir($path, 0777, true);
|
||||
}
|
||||
|
||||
static public function get_test_config()
|
||||
{
|
||||
if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
|
||||
{
|
||||
$config = array(
|
||||
'dbms' => 'sqlite',
|
||||
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
|
||||
'dbport' => '',
|
||||
'dbname' => '',
|
||||
'dbuser' => '',
|
||||
'dbpasswd' => '',
|
||||
'phpbb_functional_url' => 'http://localhost/',
|
||||
);
|
||||
}
|
||||
|
||||
if (file_exists(dirname(__FILE__) . '/../test_config.php'))
|
||||
{
|
||||
include(dirname(__FILE__) . '/../test_config.php');
|
||||
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => $dbms,
|
||||
'dbhost' => $dbhost,
|
||||
'dbport' => $dbport,
|
||||
'dbname' => $dbname,
|
||||
'dbuser' => $dbuser,
|
||||
'dbpasswd' => $dbpasswd,
|
||||
'phpbb_functional_url' => isset($phpbb_functional_url) ? $phpbb_functional_url : 'http://localhost/',
|
||||
));
|
||||
}
|
||||
|
||||
if (isset($_SERVER['PHPBB_TEST_DBMS']))
|
||||
{
|
||||
$config = array_merge($config, array(
|
||||
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
|
||||
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
|
||||
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
|
||||
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',
|
||||
'dbuser' => isset($_SERVER['PHPBB_TEST_DBUSER']) ? $_SERVER['PHPBB_TEST_DBUSER'] : '',
|
||||
'dbpasswd' => isset($_SERVER['PHPBB_TEST_DBPASSWD']) ? $_SERVER['PHPBB_TEST_DBPASSWD'] : ''
|
||||
));
|
||||
}
|
||||
|
||||
if (isset($_SERVER['PHPBB_FUNCTIONAL_URL']))
|
||||
{
|
||||
$config = array_merge($config, array(
|
||||
'phpbb_functional_url' => isset($_SERVER['PHPBB_FUNCTIONAL_URL']) ? $_SERVER['PHPBB_FUNCTIONAL_URL'] : '',
|
||||
));
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user