aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-10-14 16:05:35 +0200
committerNils Adermann <naderman@naderman.de>2011-10-14 17:20:54 +0200
commit0ffe494edd274647ba6694648dba070c63e55d89 (patch)
tree93a0d4eb7573a6d66ffa10d5979565754cca70cb
parent637d8eabe76907ce4a1e810d8b6bd964acb1b303 (diff)
downloadforums-0ffe494edd274647ba6694648dba070c63e55d89.tar
forums-0ffe494edd274647ba6694648dba070c63e55d89.tar.gz
forums-0ffe494edd274647ba6694648dba070c63e55d89.tar.bz2
forums-0ffe494edd274647ba6694648dba070c63e55d89.tar.xz
forums-0ffe494edd274647ba6694648dba070c63e55d89.zip
[feature/functional-tests] Configure functional tests through config file
The functional tests now also use the test database PHPBB3-10414
-rw-r--r--tests/test_framework/phpbb_database_test_case.php42
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php54
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php52
3 files changed, 87 insertions, 61 deletions
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index e1b368dcea..b1484450b8 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -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');
-
- 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
+ $config = phpbb_test_case_helpers::get_test_config();
+
+ if (!isset($config['dbms']))
{
$this->markTestSkipped('Missing test_config.php: See first error.');
}
+
+ return $config;
}
public function getConnection()
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index ddaa894061..02d51d71de 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -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::markTestSkipped("The 'PHPBB_FUNCTIONAL_URL' environment variable was not set.");
- }
+ self::$config = phpbb_test_case_helpers::get_test_config();
- if (!file_exists($phpbb_root_path . "config.$phpEx"))
+ if (!isset(self::$config['phpbb_functional_url']))
{
- self::markTestSkipped("config.php does not exist, it is required for running functional tests.");
+ self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
}
- 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);
+ self::$config['table_prefix'] = 'phpbb_';
+ self::recreate_database(self::$config);
- rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "_config.$phpEx");
+ if (file_exists($phpbb_root_path . "config.$phpEx"))
+ {
+ 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");
+ }
+ }
// 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)
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 697dc93501..cbfb2540c2 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -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;
+ }
}