Use new testing framework, weeeeh

This commit is contained in:
Joas Schilling
2014-06-10 23:29:48 +02:00
parent 9ee1edcb8c
commit fe33179197
33 changed files with 122 additions and 4141 deletions

View File

@@ -11,6 +11,11 @@ namespace board3\portal\tests\testframework;
abstract class database_test_case extends \phpbb_database_test_case
{
static protected function setup_extensions()
{
return array('board3/portal');
}
protected $db;
public function setUp()
@@ -19,31 +24,4 @@ abstract class database_test_case extends \phpbb_database_test_case
global $db;
$db = $this->db = $this->new_dbal();
}
protected function create_connection_manager($config)
{
return new \board3\portal\tests\testframework\database_test_connection_manager($config);
}
public function get_database_config()
{
$config = \board3\portal\tests\testframework\test_case_helpers::get_test_config();
if (!isset($config['dbms']))
{
$this->markTestSkipped('Missing test_config.php: See first error.');
}
return $config;
}
public function get_test_case_helpers()
{
if (!$this->test_case_helpers)
{
$this->test_case_helpers = new \board3\portal\tests\testframework\test_case_helpers($this);
}
return $this->test_case_helpers;
}
}

View File

@@ -1,22 +0,0 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace board3\portal\tests\testframework;
class database_test_connection_manager extends \phpbb_database_test_connection_manager
{
public function load_schema($db)
{
$this->ensure_connected(__METHOD__);
$directory = dirname(__FILE__) . '/../schemas/';
$this->load_schema_from_file($directory, $db);
}
}

View File

@@ -11,55 +11,8 @@ namespace board3\portal\tests\testframework;
abstract class functional_test_case extends \phpbb_functional_test_case
{
protected $portal_enabled = false;
public function enable_board3_portal_ext()
static protected function setup_extensions()
{
$enable_portal = false;
if ($this->portal_enabled === true || $this->check_if_enabled())
{
return;
}
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
$disabled_extensions = $crawler->filter('tr.ext_disabled')->extract(array('_text'));
foreach ($disabled_extensions as $extension)
{
if (strpos($extension, 'Board3 Portal') !== false)
{
$enable_portal = true;
}
}
if ($enable_portal)
{
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=board3%2fportal&sid=' . $this->sid);
$form = $crawler->selectButton('Enable')->form();
$crawler = self::submit($form);
$this->assertContains('The extension was enabled successfully', $crawler->text());
$this->portal_enabled = true;
$this->set_enabled();
}
}
protected function check_if_enabled()
{
$this->db = $this->get_db();
$sql = "SELECT config_value FROM phpbb_config WHERE config_name = 'b3p_ext_enabled'";
$result = $this->db->sql_query($sql);
$enabled = $this->db->sql_fetchfield('config_value');
$this->db->sql_freeresult($result);
return $enabled;
}
protected function set_enabled()
{
$this->db = $this->get_db();
$sql = "INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('b3p_ext_enabled', 1, 1)";
$this->db->sql_query($sql);
return array('board3/portal');
}
}

View File

@@ -11,13 +11,4 @@ namespace board3\portal\tests\testframework;
abstract class test_case extends \phpbb_test_case
{
public function get_test_case_helpers()
{
if (!$this->test_case_helpers)
{
$this->test_case_helpers = new \board3\portal\tests\testframework\test_case_helpers($this);
}
return $this->test_case_helpers;
}
}

View File

@@ -1,116 +0,0 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace board3\portal\tests\testframework;
class test_case_helpers extends \phpbb_test_case_helpers
{
/**
* Copied from phpbb_test_case_helpers::get_test_config() to fix some paths
*/
static public function get_test_config()
{
$config = array();
if (extension_loaded('sqlite') && version_compare(\PHPUnit_Runner_Version::id(), '3.4.15', '>='))
{
$config = array_merge($config, array(
'dbms' => 'phpbb_db_driver_sqlite',
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
'dbport' => '',
'dbname' => '',
'dbuser' => '',
'dbpasswd' => '',
));
}
if (isset($_SERVER['PHPBB_TEST_CONFIG']))
{
// Could be an absolute path
$test_config = $_SERVER['PHPBB_TEST_CONFIG'];
}
else
{
$test_config = dirname(__FILE__) . '/../test_config.php';
}
if (file_exists($test_config))
{
include($test_config);
if (!function_exists('phpbb_convert_30_dbms_to_31'))
{
global $phpbb_root_path;
require_once $phpbb_root_path . 'includes/functions.php';
}
$config = array_merge($config, array(
'dbms' => phpbb_convert_30_dbms_to_31($dbms),
'dbhost' => $dbhost,
'dbport' => $dbport,
'dbname' => $dbname,
'dbuser' => $dbuser,
'dbpasswd' => $dbpasswd,
'custom_dsn' => isset($custom_dsn) ? $custom_dsn : '',
));
if (isset($phpbb_functional_url))
{
$config['phpbb_functional_url'] = $phpbb_functional_url;
}
if (isset($phpbb_redis_host))
{
$config['redis_host'] = $phpbb_redis_host;
}
if (isset($phpbb_redis_port))
{
$config['redis_port'] = $phpbb_redis_port;
}
}
if (isset($_SERVER['PHPBB_TEST_DBMS']))
{
if (!function_exists('phpbb_convert_30_dbms_to_31'))
{
global $phpbb_root_path;
require_once $phpbb_root_path . 'includes/functions.php';
}
$config = array_merge($config, array(
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_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'] : '',
'custom_dsn' => isset($_SERVER['PHPBB_TEST_CUSTOM_DSN']) ? $_SERVER['PHPBB_TEST_CUSTOM_DSN'] : '',
));
}
if (isset($_SERVER['PHPBB_FUNCTIONAL_URL']))
{
$config = array_merge($config, array(
'phpbb_functional_url' => isset($_SERVER['PHPBB_FUNCTIONAL_URL']) ? $_SERVER['PHPBB_FUNCTIONAL_URL'] : '',
));
}
if (isset($_SERVER['PHPBB_TEST_REDIS_HOST']))
{
$config['redis_host'] = $_SERVER['PHPBB_TEST_REDIS_HOST'];
}
if (isset($_SERVER['PHPBB_TEST_REDIS_PORT']))
{
$config['redis_port'] = $_SERVER['PHPBB_TEST_REDIS_PORT'];
}
return $config;
}
}