1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-09 02:06:32 +02:00

Merge branch 'develop' of github.com:phpbb/phpbb3 into ticket/11103

# By Oleg Pudeyev (21) and others
# Via Andreas Fischer (7) and others
* 'develop' of github.com:phpbb/phpbb3: (56 commits)
  [ticket/11015] Move comment in the right place.
  [ticket/11015] Correctly transform 'mysqli' etc. in phpbb_convert_30_dbms_to_31
  [ticket/11015] Fix 3.0 to 3.1 dbms conversion for mysqli.
  [ticket/11015] Change permission adding in database updater to new style.
  [ticket/11015] Change more docblocks to phpbb_db_driver.
  [ticket/11015] Installer still needs 3.0-style dbms name.
  [ticket/11262] Add .lock in cache directory to .gitignore
  [ticket/11015] Include functions.php because it is not always included.
  [ticket/11265] Add assertions for board installation success.
  [ticket/11263] Fix PHP Notice: Undefined variable: extension_manager
  [ticket/11015] Convert database drivers to new spelling in post setup sync.
  [ticket/11015] Convert connect test to the new syntax.
  [ticket/11015] Restore whitespace to avoid conflict when merging develop.
  [ticket/10975] Add a test for viewing a profile.
  [ticket/10975] Test restricting by first character.
  [ticket/10975] Avoid rewriting global config twice.
  [ticket/10975] Test memberlist, not user creation.
  [ticket/10975] Some quick tests to check the memberlist behaviour
  [ticket/10491] Make recreate_database static.
  [ticket/11088] Pass required objects in as arguments
  ...

Conflicts:
	phpBB/install/database_update.php
This commit is contained in:
Nathan Guse
2012-12-13 19:21:29 -06:00
51 changed files with 472 additions and 277 deletions

View File

@@ -30,7 +30,7 @@ example for mysqli can be found below. More information on configuration
options can be found on the wiki (see below).
<?php
$dbms = 'mysqli';
$dbms = 'phpbb_db_driver_mysqli';
$dbhost = 'localhost';
$dbport = '';
$dbname = 'database';

View File

@@ -22,9 +22,7 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case
$config = $this->get_database_config();
require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php';
$dbal = 'dbal_' . $config['dbms'];
$db = new $dbal();
$db = new $config['dbms']();
// Failure to connect results in a trigger_error call in dbal.
// phpunit converts triggered errors to exceptions.

View File

@@ -9,7 +9,6 @@
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/db/dbal.php';
class phpbb_di_container_test extends phpbb_test_case
{
@@ -52,7 +51,7 @@ class phpbb_di_container_test extends phpbb_test_case
}
}
class dbal_container_mock extends dbal
class phpbb_db_driver_container_mock extends phpbb_db_driver
{
public function sql_connect()
{

View File

@@ -0,0 +1,43 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
/**
* @group functional
*/
class phpbb_functional_memberlist_test extends phpbb_functional_test_case
{
public function test_memberlist()
{
$this->create_user('memberlist-test-user');
// logs in as admin
$this->login();
$crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid);
$this->assert_response_success();
$this->assertContains('memberlist-test-user', $crawler->text());
// restrict by first character
$crawler = $this->request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid);
$this->assert_response_success();
$this->assertContains('memberlist-test-user', $crawler->text());
// make sure results for wrong character are not returned
$crawler = $this->request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid);
$this->assert_response_success();
$this->assertNotContains('memberlist-test-user', $crawler->text());
}
public function test_viewprofile()
{
$this->login();
// XXX hardcoded user id
$crawler = $this->request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid);
$this->assert_response_success();
$this->assertContains('admin', $crawler->filter('h2')->text());
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
*
* @package testing
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case
{
public function convert_30_dbms_to_31_data()
{
return array(
array('firebird'),
array('mssql'),
array('mssql_odbc'),
array('mssqlnative'),
array('mysql'),
array('mysqli'),
array('oracle'),
array('postgres'),
array('sqlite'),
);
}
/**
* @dataProvider convert_30_dbms_to_31_data
*/
public function test_convert_30_dbms_to_31($input)
{
$expected = "phpbb_db_driver_$input";
$output = phpbb_convert_30_dbms_to_31($input);
$this->assertEquals($expected, $output);
}
}

View File

@@ -59,10 +59,10 @@ class phpbb_session_testable_factory
/**
* Retrieve the configured session class instance
*
* @param dbal $dbal The database connection to use for session data
* @param phpbb_db_driver $dbal The database connection to use for session data
* @return phpbb_mock_session_testable A session instance
*/
public function get_session(dbal $dbal)
public function get_session(phpbb_db_driver $dbal)
{
// set up all the global variables used by session
global $SID, $_SID, $db, $config, $cache, $request;

View File

@@ -49,7 +49,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$db_config = $this->get_database_config();
// Firebird requires table and column names to be uppercase
if ($db_config['dbms'] == 'firebird')
if ($db_config['dbms'] == 'phpbb_db_driver_firebird')
{
$xml_data = file_get_contents($path);
$xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data);
@@ -118,9 +118,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$config = $this->get_database_config();
require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php';
$dbal = 'dbal_' . $config['dbms'];
$db = new $dbal();
$db = new $config['dbms']();
$db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']);
return $db;

View File

@@ -108,7 +108,7 @@ class phpbb_database_test_connection_manager
// These require different connection strings on the phpBB side than they do in PDO
// so you must provide a DSN string for ODBC separately
if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird'))
if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb_db_driver_mssql' || $this->config['dbms'] == 'phpbb_db_driver_firebird'))
{
$dsn = 'odbc:' . $this->config['custom_dsn'];
}
@@ -117,12 +117,12 @@ class phpbb_database_test_connection_manager
{
switch ($this->config['dbms'])
{
case 'mssql':
case 'mssql_odbc':
case 'phpbb_db_driver_mssql':
case 'phpbb_db_driver_mssql_odbc':
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
break;
case 'firebird':
case 'phpbb_db_driver_firebird':
if (!empty($this->config['custom_dsn']))
{
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
@@ -165,8 +165,8 @@ class phpbb_database_test_connection_manager
{
switch ($this->config['dbms'])
{
case 'sqlite':
case 'firebird':
case 'phpbb_db_driver_sqlite':
case 'phpbb_db_driver_firebird':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
@@ -176,7 +176,7 @@ class phpbb_database_test_connection_manager
$this->purge_extras();
break;
case 'oracle':
case 'phpbb_db_driver_oracle':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
@@ -226,39 +226,39 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
case 'mysql':
case 'mysql4':
case 'mysqli':
case 'phpbb_db_driver_mysql':
case 'phpbb_db_driver_mysql4':
case 'phpbb_db_driver_mysqli':
$sql = 'SHOW TABLES';
break;
case 'sqlite':
case 'phpbb_db_driver_sqlite':
$sql = 'SELECT name
FROM sqlite_master
WHERE type = "table"';
break;
case 'mssql':
case 'mssql_odbc':
case 'mssqlnative':
case 'phpbb_db_driver_mssql':
case 'phpbb_db_driver_mssql_odbc':
case 'phpbb_db_driver_mssqlnative':
$sql = "SELECT name
FROM sysobjects
WHERE type='U'";
break;
case 'postgres':
case 'phpbb_db_driver_postgres':
$sql = 'SELECT relname
FROM pg_stat_user_tables';
break;
case 'firebird':
case 'phpbb_db_driver_firebird':
$sql = 'SELECT rdb$relation_name
FROM rdb$relations
WHERE rdb$view_source is null
AND rdb$system_flag = 0';
break;
case 'oracle':
case 'phpbb_db_driver_oracle':
$sql = 'SELECT table_name
FROM USER_TABLES';
break;
@@ -293,8 +293,8 @@ class phpbb_database_test_connection_manager
protected function load_schema_from_file($directory)
{
$schema = $this->dbms['SCHEMA'];
if ($this->config['dbms'] == 'mysql')
if ($this->config['dbms'] == 'phpbb_db_driver_mysql')
{
$sth = $this->pdo->query('SELECT VERSION() AS version');
$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -313,7 +313,7 @@ class phpbb_database_test_connection_manager
$queries = file_get_contents($filename);
$sql = phpbb_remove_comments($queries);
$sql = split_sql_file($sql, $this->dbms['DELIM']);
foreach ($sql as $query)
@@ -328,47 +328,47 @@ class phpbb_database_test_connection_manager
protected function get_dbms_data($dbms)
{
$available_dbms = array(
'firebird' => array(
'phpbb_db_driver_firebird' => array(
'SCHEMA' => 'firebird',
'DELIM' => ';;',
'PDO' => 'firebird',
),
'mysqli' => array(
'phpbb_db_driver_mysqli' => array(
'SCHEMA' => 'mysql_41',
'DELIM' => ';',
'PDO' => 'mysql',
),
'mysql' => array(
'phpbb_db_driver_mysql' => array(
'SCHEMA' => 'mysql',
'DELIM' => ';',
'PDO' => 'mysql',
),
'mssql' => array(
'phpbb_db_driver_mssql' => array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'odbc',
),
'mssql_odbc'=> array(
'phpbb_db_driver_mssql_odbc'=> array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'odbc',
),
'mssqlnative' => array(
'phpbb_db_driver_mssqlnative' => array(
'SCHEMA' => 'mssql',
'DELIM' => 'GO',
'PDO' => 'sqlsrv',
),
'oracle' => array(
'phpbb_db_driver_oracle' => array(
'SCHEMA' => 'oracle',
'DELIM' => '/',
'PDO' => 'oci',
),
'postgres' => array(
'phpbb_db_driver_postgres' => array(
'SCHEMA' => 'postgres',
'DELIM' => ';',
'PDO' => 'pgsql',
),
'sqlite' => array(
'phpbb_db_driver_sqlite' => array(
'SCHEMA' => 'sqlite',
'DELIM' => ';',
'PDO' => 'sqlite2',
@@ -397,7 +397,7 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
case 'firebird':
case 'phpbb_db_driver_firebird':
$sql = 'SELECT RDB$GENERATOR_NAME
FROM RDB$GENERATORS
WHERE RDB$SYSTEM_FLAG = 0';
@@ -409,7 +409,7 @@ class phpbb_database_test_connection_manager
}
break;
case 'oracle':
case 'phpbb_db_driver_oracle':
$sql = 'SELECT sequence_name
FROM USER_SEQUENCES';
$result = $this->pdo->query($sql);
@@ -444,7 +444,7 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
case 'oracle':
case 'phpbb_db_driver_oracle':
// Get all of the information about the sequences
$sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value
FROM USER_TRIGGERS t
@@ -486,7 +486,7 @@ class phpbb_database_test_connection_manager
}
break;
case 'postgres':
case 'phpbb_db_driver_postgres':
// Get the sequences attached to the tables
$sql = 'SELECT column_name, table_name FROM information_schema.columns
WHERE table_name IN (' . implode(', ', $table_names) . ")

View File

@@ -34,13 +34,36 @@ class phpbb_functional_test_case extends phpbb_test_case
static protected $config = array();
static protected $already_installed = false;
public function setUp()
static public function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$config = phpbb_test_case_helpers::get_test_config();
// Important: this is used both for installation and by
// test cases for querying the tables.
// Therefore table prefix must be set before a board is
// installed, and also before each test case is run.
self::$config['table_prefix'] = 'phpbb_';
if (!isset(self::$config['phpbb_functional_url']))
{
$this->markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.');
}
if (!self::$already_installed)
{
self::install_board();
self::$already_installed = true;
}
}
public function setUp()
{
parent::setUp();
$this->bootstrap();
$this->cookieJar = new CookieJar;
$this->client = new Goutte\Client(array(), null, $this->cookieJar);
// Reset the curl handle because it is 0 at this point and not a valid
@@ -73,27 +96,16 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->backupStaticAttributesBlacklist += array(
'phpbb_functional_test_case' => array('config', 'already_installed'),
);
if (!static::$already_installed)
{
$this->install_board();
$this->bootstrap();
static::$already_installed = true;
}
}
protected function get_db()
{
global $phpbb_root_path, $phpEx;
// so we don't reopen an open connection
if (!($this->db instanceof dbal))
if (!($this->db instanceof phpbb_db_driver))
{
if (!class_exists('dbal_' . self::$config['dbms']))
{
include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx");
}
$sql_db = 'dbal_' . self::$config['dbms'];
$this->db = new $sql_db();
$dbms = self::$config['dbms'];
$this->db = new $dbms();
$this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
}
return $this->db;
@@ -137,19 +149,11 @@ class phpbb_functional_test_case extends phpbb_test_case
return $this->extension_manager;
}
protected function install_board()
static protected function install_board()
{
global $phpbb_root_path, $phpEx;
self::$config = phpbb_test_case_helpers::get_test_config();
if (!isset(self::$config['phpbb_functional_url']))
{
return;
}
self::$config['table_prefix'] = 'phpbb_';
$this->recreate_database(self::$config);
self::recreate_database(self::$config);
if (file_exists($phpbb_root_path . "config.$phpEx"))
{
@@ -194,19 +198,30 @@ class phpbb_functional_test_case extends phpbb_test_case
));
// end data
$content = $this->do_request('install');
$this->assertContains('Welcome to Installation', $content);
$content = self::do_request('install');
self::assertNotSame(false, $content);
self::assertContains('Welcome to Installation', $content);
$this->do_request('create_table', $data);
// Installer uses 3.0-style dbms name
$data['dbms'] = str_replace('phpbb_db_driver_', '', $data['dbms']);
$content = self::do_request('create_table', $data);
self::assertNotSame(false, $content);
self::assertContains('The database tables used by phpBB', $content);
// 3.0 or 3.1
self::assertContains('have been created and populated with some initial data.', $content);
$this->do_request('config_file', $data);
$content = self::do_request('config_file', $data);
self::assertNotSame(false, $content);
self::assertContains('Configuration file', $content);
file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], true, true));
$this->do_request('final', $data);
$content = self::do_request('final', $data);
self::assertNotSame(false, $content);
self::assertContains('You have successfully installed', $content);
copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
}
private function do_request($sub, $post_data = null)
static private function do_request($sub, $post_data = null)
{
$context = null;
@@ -225,7 +240,7 @@ class phpbb_functional_test_case extends phpbb_test_case
return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context);
}
private function recreate_database($config)
static private function recreate_database($config)
{
$db_conn_mgr = new phpbb_database_test_connection_manager($config);
$db_conn_mgr->recreate_db();
@@ -242,16 +257,12 @@ class phpbb_functional_test_case extends phpbb_test_case
// Required by unique_id
global $config;
if (!is_array($config))
{
$config = array();
}
$config = new phpbb_config(array());
$config['rand_seed'] = '';
$config['rand_seed_last_update'] = time() + 600;
// Required by user_add
global $db, $cache, $config, $phpbb_dispatcher;
global $db, $cache, $phpbb_dispatcher;
$db = $this->get_db();
if (!function_exists('phpbb_mock_null_cache'))
{
@@ -267,7 +278,6 @@ class phpbb_functional_test_case extends phpbb_test_case
{
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
}
$config = new phpbb_config(array());
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();

View File

@@ -54,7 +54,7 @@ class phpbb_test_case_helpers
if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
{
$config = array_merge($config, array(
'dbms' => 'sqlite',
'dbms' => 'phpbb_db_driver_sqlite',
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
'dbport' => '',
'dbname' => '',
@@ -78,7 +78,7 @@ class phpbb_test_case_helpers
include($test_config);
$config = array_merge($config, array(
'dbms' => $dbms,
'dbms' => phpbb_convert_30_dbms_to_31($dbms),
'dbhost' => $dbhost,
'dbport' => $dbport,
'dbname' => $dbname,
@@ -104,8 +104,13 @@ class phpbb_test_case_helpers
if (isset($_SERVER['PHPBB_TEST_DBMS']))
{
if (!function_exists('phpbb_convert_30_dbms_to_31'))
{
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
}
$config = array_merge($config, array(
'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $_SERVER['PHPBB_TEST_DBMS'] : '',
'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'] : '',