[feature/tests] Add extension-testframework from phpBB gallery

This commit is contained in:
Marc Alexander
2013-10-29 15:02:51 +01:00
parent e3fb1073be
commit d757d7396d
33 changed files with 14630 additions and 3 deletions

30
tests/bootstrap.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
define('IN_PHPBB', true);
$phpbb_root_path = '../../../';
$phpEx = 'php';
require_once $phpbb_root_path . 'includes/startup.' . $phpEx;
$table_prefix = 'phpbb_';
require_once $phpbb_root_path . 'includes/constants.' . $phpEx;
require_once $phpbb_root_path . 'phpbb/class_loader.' . $phpEx;
$phpbb_class_loader_mock = new \phpbb\class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php");
$phpbb_class_loader_mock->register();
$phpbb_class_loader_ext = new \phpbb\class_loader('\\', $phpbb_root_path . 'ext/', "php");
$phpbb_class_loader_ext->register();
$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', $phpbb_root_path . 'phpbb/', "php");
$phpbb_class_loader->register();
require_once $phpbb_root_path . '../tests/test_framework/phpbb_test_case_helpers.' . $phpEx;
require_once $phpbb_root_path . '../tests/test_framework/phpbb_test_case.' . $phpEx;
require_once $phpbb_root_path . '../tests/test_framework/phpbb_database_test_case.' . $phpEx;
require_once $phpbb_root_path . '../tests/test_framework/phpbb_database_test_connection_manager.' . $phpEx;
require_once $phpbb_root_path . '../tests/test_framework/phpbb_functional_test_case.' . $phpEx;

View File

@@ -0,0 +1,179 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ScopeInterface;
class phpbb_mock_container_builder implements ContainerInterface
{
protected $services = array();
protected $parameters = array();
/**
* Sets a service.
*
* @param string $id The service identifier
* @param object $service The service instance
* @param string $scope The scope of the service
*
* @api
*/
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
{
$this->services[$id] = $service;
}
/**
* Gets a service.
*
* @param string $id The service identifier
* @param int $invalidBehavior The behavior when the service does not exist
*
* @return object The associated service
*
* @throws InvalidArgumentException if the service is not defined
* @throws ServiceCircularReferenceException When a circular reference is detected
* @throws ServiceNotFoundException When the service is not defined
*
* @see Reference
*
* @api
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
if ($this->has($id))
{
return $this->services[$id];
}
throw new Exception('Could not find service: ' . $id);
}
/**
* Returns true if the given service is defined.
*
* @param string $id The service identifier
*
* @return Boolean true if the service is defined, false otherwise
*
* @api
*/
public function has($id)
{
return isset($this->services[$id]);
}
/**
* Gets a parameter.
*
* @param string $name The parameter name
*
* @return mixed The parameter value
*
* @throws InvalidArgumentException if the parameter is not defined
*
* @api
*/
public function getParameter($name)
{
if ($this->hasParameter($name))
{
return $this->parameters[$name];
}
throw new Exception('Could not find parameter: ' . $name);
}
/**
* Checks if a parameter exists.
*
* @param string $name The parameter name
*
* @return Boolean The presence of parameter in container
*
* @api
*/
public function hasParameter($name)
{
return isset($this->parameters[$name]);
}
/**
* Sets a parameter.
*
* @param string $name The parameter name
* @param mixed $value The parameter value
*
* @api
*/
public function setParameter($name, $value)
{
$this->parameters[$name] = $value;
}
/**
* Enters the given scope
*
* @param string $name
*
* @api
*/
public function enterScope($name)
{
}
/**
* Leaves the current scope, and re-enters the parent scope
*
* @param string $name
*
* @api
*/
public function leaveScope($name)
{
}
/**
* Adds a scope to the container
*
* @param ScopeInterface $scope
*
* @api
*/
public function addScope(ScopeInterface $scope)
{
}
/**
* Whether this container has the given scope
*
* @param string $name
*
* @return Boolean
*
* @api
*/
public function hasScope($name)
{
}
/**
* Determines whether the given scope is currently active.
*
* It does however not check if the scope actually exists.
*
* @param string $name
*
* @return Boolean
*
* @api
*/
public function isScopeActive($name)
{
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbbgallery\core\tests\systemtests;
class base_database_test extends \phpbbgallery\core\tests\testframework\database_test_case
{
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/basetests.xml');
}
public function test_check()
{
$sql = 'SELECT session_user_id, album_name
FROM phpbb_sessions s
LEFT JOIN phpbb_gallery_albums a
ON (s.session_album_id = a.album_id)';
$result = $this->db->sql_query($sql);
$this->assertEquals(array(
array(
'session_user_id' => 4,
'album_name' => 'Testalbum',
),
), $this->db->sql_fetchrowset($result));
$this->db->sql_freeresult($result);
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbbgallery\core\tests\systemtests;
class base_test extends \phpbbgallery\core\tests\testframework\test_case
{
public function test_check()
{
$this->assertTrue(true);
}
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
<table name="phpbb_sessions">
<column>session_id</column>
<column>session_user_id</column>
<column>session_album_id</column>
<column>session_ip</column>
<column>session_browser</column>
<column>session_admin</column>
<row>
<value>bar_session000000000000000000000</value>
<value>4</value>
<value>42</value>
<value>127.0.0.1</value>
<value>user agent</value>
<value>1</value>
</row>
</table>
<table name="phpbb_gallery_albums">
<column>album_id</column>
<column>album_name</column>
<column>album_parents</column>
<column>album_desc</column>
<row>
<value>42</value>
<value>Testalbum</value>
<value></value>
<value></value>
</row>
</table>
</dataset>

View File

@@ -0,0 +1,7 @@
<?php
$dbms = 'phpbb\\db\\driver\\mysqli';
$dbhost = 'localhost';
$dbport = '';
$dbname = 'phpbb_test';
$dbuser = 'root';
$dbpasswd = '';

View File

@@ -0,0 +1,50 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbbgallery\core\tests\testframework;
abstract class database_test_case extends \phpbb_database_test_case
{
protected $db;
public function setUp()
{
parent::setUp();
global $db;
$db = $this->db = $this->new_dbal();
}
protected function create_connection_manager($config)
{
return new \phpbbgallery\core\tests\testframework\database_test_connection_manager($config);
}
public function get_database_config()
{
$config = \phpbbgallery\core\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 \phpbbgallery\core\tests\testframework\test_case_helpers($this);
}
return $this->test_case_helpers;
}
}

View File

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

View File

@@ -0,0 +1,14 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbbgallery\core\tests\testframework;
abstract class functional_test_case extends \phpbb_functional_test_case
{
}

View File

@@ -0,0 +1,23 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbbgallery\core\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 \phpbbgallery\core\tests\testframework\test_case_helpers($this);
}
return $this->test_case_helpers;
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
*
* @package phpBB Gallery Testing
* @copyright (c) 2013 nickvergessen
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbbgallery\core\tests\testframework;
abstract 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;
}
}