aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dbal')
-rw-r--r--tests/dbal/auto_increment_test.php5
-rw-r--r--tests/dbal/boolean_processor_test.php321
-rw-r--r--tests/dbal/connect_test.php6
-rw-r--r--tests/dbal/cross_join_test.php3
-rw-r--r--tests/dbal/db_tools_test.php66
-rw-r--r--tests/dbal/ext/foo/bar/acp/acp_test_info.php37
-rw-r--r--tests/dbal/ext/foo/bar/acp/acp_test_module.php25
-rw-r--r--tests/dbal/ext/foo/bar/composer.json24
-rw-r--r--tests/dbal/ext/foo/bar/ucp/ucp_test_info.php37
-rw-r--r--tests/dbal/ext/foo/bar/ucp/ucp_test_module.php25
-rw-r--r--tests/dbal/fixtures/boolean_processor.xml90
-rw-r--r--tests/dbal/migration/revert_table.php39
-rw-r--r--tests/dbal/migration/revert_table_with_dependency.php52
-rw-r--r--tests/dbal/migrator_test.php53
-rw-r--r--tests/dbal/migrator_tool_module_test.php228
-rw-r--r--tests/dbal/migrator_tool_permission_test.php8
-rw-r--r--tests/dbal/schema_test.php2
-rw-r--r--tests/dbal/select_test.php3
-rw-r--r--tests/dbal/write_sequence_test.php2
-rw-r--r--tests/dbal/write_test.php4
20 files changed, 966 insertions, 64 deletions
diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php
index 1ed8ea29e3..950a4fc8f7 100644
--- a/tests/dbal/auto_increment_test.php
+++ b/tests/dbal/auto_increment_test.php
@@ -11,8 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
{
protected $db;
@@ -30,7 +28,8 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
parent::setUp();
$this->db = $this->new_dbal();
- $this->tools = new \phpbb\db\tools($this->db);
+ $factory = new \phpbb\db\tools\factory();
+ $this->tools = $factory->get($this->db);
$this->table_data = array(
'COLUMNS' => array(
diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php
new file mode 100644
index 0000000000..c69f60a1a8
--- /dev/null
+++ b/tests/dbal/boolean_processor_test.php
@@ -0,0 +1,321 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_boolean_processor_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml');
+ }
+
+ public function test_single_not_like()
+ {
+ $db = $this->new_dbal();
+
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.user_id',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ ),
+ 'WHERE' => array('u.username_clean', 'NOT_LIKE', 'gr' . $db->get_any_char()),
+ 'ORDER_BY' => 'u.user_id',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array('user_id' => '1'),
+ array('user_id' => '2'),
+ array('user_id' => '3'),
+ array('user_id' => '6'),
+ ), $db->sql_fetchrowset($result),
+ ($result === false) ?
+ "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() :
+ var_export($sql, true) . ' ' . var_export($result, true)
+ );
+ }
+
+ public function test_single_like()
+ {
+ $db = $this->new_dbal();
+
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.user_id',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ ),
+ 'WHERE' => array('u.username_clean', 'LIKE', 'gr' . $db->get_any_char()),
+ 'ORDER_BY' => 'u.user_id',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array('user_id' => '4'),
+ array('user_id' => '5'),
+ ), $db->sql_fetchrowset($result),
+ ($result === false) ?
+ "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() :
+ var_export($sql, true) . ' ' . var_export($result, true)
+ );
+ }
+
+ public function test_single_not_in()
+ {
+ $db = $this->new_dbal();
+
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.user_id',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ ),
+ 'WHERE' => array('u.user_id', 'NOT_IN', array(3,4,5)),
+ 'ORDER_BY' => 'u.user_id',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array('user_id' => '1'),
+ array('user_id' => '2'),
+ array('user_id' => '6'),
+ ), $db->sql_fetchrowset($result),
+ ($result === false) ?
+ "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() :
+ var_export($sql, true) . ' ' . var_export($result, true)
+ );
+ }
+
+ public function test_single_in()
+ {
+ $db = $this->new_dbal();
+
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.user_id',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ ),
+ 'WHERE' => array('u.user_id', 'IN', array(3,4,5)),
+ 'ORDER_BY' => 'u.user_id',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array('user_id' => '3'),
+ array('user_id' => '4'),
+ array('user_id' => '5'),
+ ), $db->sql_fetchrowset($result),
+ ($result === false) ?
+ "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() :
+ var_export($sql, true) . ' ' . var_export($result, true)
+ );
+ }
+
+ public function test_and_of_or_of_and()
+ {
+ $db = $this->new_dbal();
+
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.user_id',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ 'phpbb_user_group' => 'ug',
+ ),
+ 'LEFT_JOIN' => array(
+ array(
+ 'FROM' => array(
+ 'phpbb_banlist' => 'b',
+ ),
+ 'ON' => 'u.user_id = b.ban_userid',
+ ),
+ ),
+ 'WHERE' => array('AND',
+ array(
+ array('OR',
+ array(
+ array('AND',
+ array(
+ array('ug.user_id', 'IN', array(1, 2, 3, 4)),
+ array('ug.group_id', '=', 2),
+ ),
+ ),
+ array('AND',
+ array(
+ array('ug.group_id', '=', 1),
+ array('b.ban_id', 'IS_NOT', NULL),
+ ),
+ ),
+ ),
+ ),
+ array('u.user_id', '=', 'ug.user_id'),
+ ),
+ ),
+ 'ORDER_BY' => 'u.user_id',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array('user_id' => '2'),
+ array('user_id' => '4'),
+ ), $db->sql_fetchrowset($result),
+ ($result === false) ?
+ "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() :
+ var_export($sql, true) . ' ' . var_export($result, true)
+ );
+ }
+
+ public function test_triple_and_with_in()
+ {
+ $db = $this->new_dbal();
+
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.user_id',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ 'phpbb_user_group' => 'ug',
+ ),
+ 'WHERE' => array('AND',
+ array(
+ array('ug.user_id', 'IN', array(1, 2, 3, 4)),
+ array('ug.group_id', '=', 1),
+ array('u.user_id', '=', 'ug.user_id'),
+ ),
+ ),
+ 'ORDER_BY' => 'u.user_id',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array('user_id' => '1'),
+ array('user_id' => '2'),
+ array('user_id' => '3'),
+ ), $db->sql_fetchrowset($result),
+ ($result === false) ?
+ "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() :
+ var_export($sql, true) . ' ' . var_export($result, true)
+ );
+
+ }
+
+ public function test_double_and_with_not_of_or()
+ {
+ $db = $this->new_dbal();
+
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.user_id',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ 'phpbb_user_group' => 'ug',
+ ),
+ 'WHERE' => array('AND',
+ array(
+ array('NOT',
+ array(
+ array('OR',
+ array(
+ array('ug.group_id', '=', 1),
+ array('ug.group_id', '=', 2),
+ ),
+ ),
+ ),
+ ),
+ array('u.user_id', '=', 'ug.user_id'),
+ ),
+ ),
+ 'ORDER_BY' => 'u.user_id',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(), $db->sql_fetchrowset($result),
+ ($result === false) ?
+ "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() :
+ var_export($sql, true) . ' ' . var_export($result, true)
+ );
+ }
+
+ public function test_triple_and_with_is_null()
+ {
+ $db = $this->new_dbal();
+
+ $db->sql_return_on_error(true);
+
+ $sql_ary = array(
+ 'SELECT' => 'u.username',
+ 'FROM' => array(
+ 'phpbb_users' => 'u',
+ 'phpbb_user_group' => 'ug',
+ ),
+ 'LEFT_JOIN' => array(
+ array(
+ 'FROM' => array(
+ 'phpbb_banlist' => 'b',
+ ),
+ 'ON' => 'u.user_id = b.ban_userid',
+ ),
+ ),
+ 'WHERE' => array('AND',
+ array(
+ array('ug.group_id', '=', 1),
+ array('u.user_id', '=', 'ug.user_id'),
+ array('b.ban_id', 'IS', NULL),
+ ),
+ ),
+ 'ORDER_BY' => 'u.username',
+ );
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+
+ $db->sql_return_on_error(false);
+
+ $this->assertEquals(array(
+ array('username' => 'helper'),
+ array('username' => 'mass email'),
+ ), $db->sql_fetchrowset($result),
+ ($result === false) ?
+ "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() :
+ var_export($sql, true) . ' ' . var_export($result, true)
+ );
+ }
+}
diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php
index 1ae34bd2b6..3933dab798 100644
--- a/tests/dbal/connect_test.php
+++ b/tests/dbal/connect_test.php
@@ -11,8 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_dbal_connect_test extends phpbb_database_test_case
{
public function getDataSet()
@@ -22,7 +20,9 @@ class phpbb_dbal_connect_test extends phpbb_database_test_case
public function test_failing_connect()
{
- global $phpbb_root_path, $phpEx;
+ global $phpbb_root_path, $phpEx, $phpbb_filesystem;
+
+ $phpbb_filesystem = new phpbb\filesystem\filesystem();
$config = $this->get_database_config();
diff --git a/tests/dbal/cross_join_test.php b/tests/dbal/cross_join_test.php
index 7ba937ccc6..be9258c58b 100644
--- a/tests/dbal/cross_join_test.php
+++ b/tests/dbal/cross_join_test.php
@@ -11,9 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
-
class phpbb_dbal_cross_join_test extends phpbb_database_test_case
{
public function getDataSet()
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index 5832b966d8..0365463a48 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -11,13 +11,11 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_dbal_db_tools_test extends phpbb_database_test_case
{
/** @var \phpbb\db\driver\driver_interface */
protected $db;
- /** @var \phpbb\db\tools */
+ /** @var \phpbb\db\tools\tools_interface */
protected $tools;
protected $table_exists;
protected $table_data;
@@ -32,7 +30,8 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
parent::setUp();
$this->db = $this->new_dbal();
- $this->tools = new \phpbb\db\tools($this->db);
+ $factory = new \phpbb\db\tools\factory();
+ $this->tools = $factory->get($this->db);
$this->table_data = array(
'COLUMNS' => array(
@@ -204,8 +203,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_list_columns()
{
+ $config = $this->get_database_config();
+ $table_columns = $this->table_data['COLUMNS'];
+
+ if (strpos($config['dbms'], 'mssql') !== false)
+ {
+ ksort($table_columns);
+ }
$this->assertEquals(
- array_keys($this->table_data['COLUMNS']),
+ array_keys($table_columns),
array_values($this->tools->sql_list_columns('prefix_table_name'))
);
}
@@ -340,7 +346,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_perform_schema_changes_drop_tables()
{
- $db_tools = $this->getMock('\phpbb\db\tools', array(
+ $db_tools = $this->getMock('\phpbb\db\tools\tools', array(
'sql_table_exists',
'sql_table_drop',
), array(&$this->db));
@@ -366,7 +372,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_perform_schema_changes_drop_columns()
{
- $db_tools = $this->getMock('\phpbb\db\tools', array(
+ $db_tools = $this->getMock('\phpbb\db\tools\tools', array(
'sql_column_exists',
'sql_column_remove',
), array(&$this->db));
@@ -422,4 +428,50 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_13282', array('TINT:2')));
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282'));
}
+
+ public function test_create_index_with_long_name()
+ {
+ // This constant is being used for checking table prefix.
+ $table_prefix = substr(CONFIG_TABLE, 0, -6); // strlen(config)
+
+ if (strlen($table_prefix) > 20)
+ {
+ $this->markTestIncomplete('The table prefix length is too long for proper testing of index shortening function.');
+ }
+
+ $max_index_length = 30;
+
+ if ($this->tools instanceof \phpbb\db\tools\mssql)
+ {
+ $max_length_method = new ReflectionMethod('\phpbb\db\tools\mssql', 'get_max_index_name_length');
+ $max_length_method->setAccessible(true);
+ $max_index_length = $max_length_method->invoke($this->tools);
+ }
+
+ $table_suffix = str_repeat('a', 25 - strlen($table_prefix));
+ $table_name = $table_prefix . $table_suffix;
+
+ $this->tools->sql_create_table($table_name, $this->table_data);
+
+ // Index name and table suffix and table prefix have > maximum index length chars in total.
+ // Index name and table suffix have <= maximum index length chars in total.
+ $long_index_name = str_repeat('i', $max_index_length - strlen($table_suffix));
+ $this->assertFalse($this->tools->sql_index_exists($table_name, $long_index_name));
+ $this->assertTrue($this->tools->sql_create_index($table_name, $long_index_name, array('c_timestamp')));
+ $this->assertTrue($this->tools->sql_index_exists($table_name, $long_index_name));
+
+ // Index name and table suffix have > maximum index length chars in total.
+ $very_long_index_name = str_repeat('i', $max_index_length);
+ $this->assertFalse($this->tools->sql_index_exists($table_name, $very_long_index_name));
+ $this->assertTrue($this->tools->sql_create_index($table_name, $very_long_index_name, array('c_timestamp')));
+ $this->assertTrue($this->tools->sql_index_exists($table_name, $very_long_index_name));
+
+ $this->tools->sql_table_drop($table_name);
+
+ // Index name has > maximum index length chars - that should not be possible.
+ $too_long_index_name = str_repeat('i', $max_index_length + 1);
+ $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name));
+ $this->setExpectedTriggerError(E_USER_ERROR);
+ $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp'));
+ }
}
diff --git a/tests/dbal/ext/foo/bar/acp/acp_test_info.php b/tests/dbal/ext/foo/bar/acp/acp_test_info.php
new file mode 100644
index 0000000000..ac92623c3a
--- /dev/null
+++ b/tests/dbal/ext/foo/bar/acp/acp_test_info.php
@@ -0,0 +1,37 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace foo\bar\acp;
+
+class acp_test_info
+{
+ public function module()
+ {
+ return array(
+ 'filename' => '\foo\bar\acp\acp_test_module',
+ 'title' => 'ACP_NEW_MODULE',
+ 'modes' => array(
+ 'mode_1' => array(
+ 'title' => 'ACP_NEW_MODULE_MODE_1',
+ 'auth' => '',
+ 'cat' => array('ACP_NEW_MODULE'),
+ ),
+ 'mode_2' => array(
+ 'title' => 'ACP_NEW_MODULE_MODE_2',
+ 'auth' => '',
+ 'cat' => array('ACP_NEW_MODULE'),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/ext/foo/bar/acp/acp_test_module.php b/tests/dbal/ext/foo/bar/acp/acp_test_module.php
new file mode 100644
index 0000000000..01ce5c17dc
--- /dev/null
+++ b/tests/dbal/ext/foo/bar/acp/acp_test_module.php
@@ -0,0 +1,25 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace foo\bar\acp;
+
+class acp_test_module
+{
+ var $u_action;
+
+ function main($id, $mode)
+ {
+ $this->tpl_name = 'foobar';
+ $this->page_title = 'Bertie';
+ }
+}
diff --git a/tests/dbal/ext/foo/bar/composer.json b/tests/dbal/ext/foo/bar/composer.json
new file mode 100644
index 0000000000..2edfd43d84
--- /dev/null
+++ b/tests/dbal/ext/foo/bar/composer.json
@@ -0,0 +1,24 @@
+{
+ "name": "foo/bar",
+ "type": "phpbb-extension",
+ "description": "An example/sample extension to be used for testing purposes in phpBB Development.",
+ "version": "1.0.0",
+ "time": "2012-02-15 01:01:01",
+ "license": "GNU GPL v2",
+ "authors": [{
+ "name": "John Smith",
+ "username": "JohnSmith27",
+ "email": "email@phpbb.com",
+ "homepage": "http://phpbb.com",
+ "role": "N/A"
+ }],
+ "require": {
+ "php": ">=5.4.7"
+ },
+ "extra": {
+ "display-name": "phpBB BarFoo Extension",
+ "soft-require": {
+ "phpbb/phpbb": "3.2.*@dev"
+ }
+ }
+}
diff --git a/tests/dbal/ext/foo/bar/ucp/ucp_test_info.php b/tests/dbal/ext/foo/bar/ucp/ucp_test_info.php
new file mode 100644
index 0000000000..d3489af832
--- /dev/null
+++ b/tests/dbal/ext/foo/bar/ucp/ucp_test_info.php
@@ -0,0 +1,37 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace foo\bar\ucp;
+
+class ucp_test_info
+{
+ public function module()
+ {
+ return array(
+ 'filename' => '\foo\bar\ucp\ucp_test_module',
+ 'title' => 'UCP_NEW_MODULE',
+ 'modes' => array(
+ 'mode_1' => array(
+ 'title' => 'UCP_NEW_MODULE_MODE_1',
+ 'auth' => '',
+ 'cat' => array('UCP_NEW_MODULE'),
+ ),
+ 'mode_2' => array(
+ 'title' => 'UCP_NEW_MODULE_MODE_2',
+ 'auth' => '',
+ 'cat' => array('UCP_NEW_MODULE'),
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/ext/foo/bar/ucp/ucp_test_module.php b/tests/dbal/ext/foo/bar/ucp/ucp_test_module.php
new file mode 100644
index 0000000000..b06b3238b6
--- /dev/null
+++ b/tests/dbal/ext/foo/bar/ucp/ucp_test_module.php
@@ -0,0 +1,25 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace foo\bar\ucp;
+
+class ucp_test_module
+{
+ var $u_action;
+
+ function main($id, $mode)
+ {
+ $this->tpl_name = 'foobar';
+ $this->page_title = 'Bertie';
+ }
+}
diff --git a/tests/dbal/fixtures/boolean_processor.xml b/tests/dbal/fixtures/boolean_processor.xml
new file mode 100644
index 0000000000..d31d679f45
--- /dev/null
+++ b/tests/dbal/fixtures/boolean_processor.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_banlist">
+ <column>ban_id</column>
+ <column>ban_userid</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ </row>
+ </table>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <row>
+ <value>1</value>
+ <value>mass email</value>
+ <value>mass email</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>banned</value>
+ <value>banned</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>helper</value>
+ <value>helper</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>GroupBPal</value>
+ <value>groupbpal</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>GroupBPal2</value>
+ <value>groupBPal2</value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>6</value>
+ <value>not in group</value>
+ <value>not in group</value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_user_group">
+ <column>user_id</column>
+ <column>group_id</column>
+ <column>group_leader</column>
+ <row>
+ <value>1</value>
+ <value>1</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>1</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>1</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>2</value>
+ <value>2</value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>2</value>
+ <value>2</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/dbal/migration/revert_table.php b/tests/dbal/migration/revert_table.php
new file mode 100644
index 0000000000..162421be85
--- /dev/null
+++ b/tests/dbal/migration/revert_table.php
@@ -0,0 +1,39 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_dbal_migration_revert_table extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array(
+ 'add_tables' => array(
+ 'phpbb_foobar' => array(
+ 'COLUMNS' => array(
+ 'module_id' => array('UINT:3', NULL, 'auto_increment'),
+ 'bar_column' => array('UINT', 1),
+ ),
+ 'PRIMARY_KEY' => 'module_id',
+ ),
+ ),
+ );
+ }
+
+ function revert_schema()
+ {
+ return array(
+ 'drop_tables' => array(
+ 'phpbb_foobar',
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migration/revert_table_with_dependency.php b/tests/dbal/migration/revert_table_with_dependency.php
new file mode 100644
index 0000000000..f26ad076e6
--- /dev/null
+++ b/tests/dbal/migration/revert_table_with_dependency.php
@@ -0,0 +1,52 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_dbal_migration_revert_table_with_dependency extends \phpbb\db\migration\migration
+{
+ static public function depends_on()
+ {
+ return array('phpbb_dbal_migration_revert_table');
+ }
+
+ function update_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ 'phpbb_foobar' => array(
+ 'baz_column' => array('UINT', 1),
+ ),
+ ),
+ 'drop_columns' => array(
+ 'phpbb_foobar' => array(
+ 'bar_column',
+ ),
+ ),
+ );
+ }
+
+ function revert_schema()
+ {
+ return array(
+ 'add_columns' => array(
+ 'phpbb_foobar' => array(
+ 'bar_column' => array('UINT', 1),
+ ),
+ ),
+ 'drop_columns' => array(
+ 'phpbb_foobar' => array(
+ 'baz_column',
+ ),
+ ),
+ );
+ }
+}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index 798200eef1..372b2dbe1e 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -11,23 +11,32 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/migration/dummy.php';
require_once dirname(__FILE__) . '/migration/unfulfillable.php';
require_once dirname(__FILE__) . '/migration/if.php';
require_once dirname(__FILE__) . '/migration/recall.php';
require_once dirname(__FILE__) . '/migration/revert.php';
require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
+require_once dirname(__FILE__) . '/migration/revert_table.php';
+require_once dirname(__FILE__) . '/migration/revert_table_with_dependency.php';
require_once dirname(__FILE__) . '/migration/fail.php';
require_once dirname(__FILE__) . '/migration/installed.php';
require_once dirname(__FILE__) . '/migration/schema.php';
class phpbb_dbal_migrator_test extends phpbb_database_test_case
{
+ /** @var \phpbb\db\driver\driver_interface */
protected $db;
+
+ /** @var \phpbb\db\tools\tools_interface */
protected $db_tools;
+
+ /** @var \phpbb\db\migrator */
protected $migrator;
+ /** @var \phpbb\config\config */
+ protected $config;
+
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
@@ -38,7 +47,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
parent::setUp();
$this->db = $this->new_dbal();
- $this->db_tools = new \phpbb\db\tools($this->db);
+ $factory = new \phpbb\db\tools\factory();
+ $this->db_tools = $factory->get($this->db);
$this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config');
@@ -62,14 +72,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
);
$container->set('migrator', $this->migrator);
$container->set('dispatcher', new phpbb_mock_event_dispatcher());
- $user = new \phpbb\user('\phpbb\datetime');
$this->extension_manager = new \phpbb\extension\manager(
$container,
$this->db,
$this->config,
- new phpbb\filesystem(),
- $user,
+ new phpbb\filesystem\filesystem(),
'phpbb_ext',
dirname(__FILE__) . '/../../phpBB/',
'php',
@@ -243,6 +251,41 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertEquals(1, $migrator_test_revert_counter, 'Revert did call custom function again');
}
+ public function test_revert_table()
+ {
+ // Make sure there are no other migrations in the db, this could cause issues
+ $this->db->sql_query("DELETE FROM phpbb_migrations");
+ $this->migrator->load_migration_state();
+
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_revert_table', 'phpbb_dbal_migration_revert_table_with_dependency'));
+
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_table'));
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_table_with_dependency'));
+
+ // Install the migration first
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_table') !== false);
+ $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_table_with_dependency') !== false);
+
+ $this->assertTrue($this->db_tools->sql_column_exists('phpbb_foobar', 'baz_column'));
+ $this->assertFalse($this->db_tools->sql_column_exists('phpbb_foobar', 'bar_column'));
+
+ // Revert migrations
+ while ($this->migrator->migration_state('phpbb_dbal_migration_revert_table') !== false)
+ {
+ $this->migrator->revert('phpbb_dbal_migration_revert_table');
+ }
+
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_table'));
+ $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_table_with_dependency'));
+
+ $this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar'));
+ }
+
public function test_fail()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_fail'));
diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php
index bbe543f347..e34ee7b59c 100644
--- a/tests/dbal/migrator_tool_module_test.php
+++ b/tests/dbal/migrator_tool_module_test.php
@@ -11,7 +11,8 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/ext/foo/bar/acp/acp_test_info.php';
+require_once dirname(__FILE__) . '/ext/foo/bar/ucp/ucp_test_info.php';
class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
{
@@ -27,19 +28,27 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
parent::setup();
- // Force add_log function to not be used
+ // Disable the logs
$skip_add_log = true;
$db = $this->db = $this->new_dbal();
- $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);
- $user = $this->user = new \phpbb\user('\phpbb\user');
+ $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);
+ $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
+ $lang = new \phpbb\language\language($lang_loader);
+ $user = $this->user = new \phpbb\user($lang, '\phpbb\datetime');
$cache = new phpbb_mock_cache;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$auth = $this->getMock('\phpbb\auth\auth');
$phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
- $this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules');
+ // Correctly set the root path for this test to this directory, so the classes can be found
+ $phpbb_root_path = dirname(__FILE__) . '/';
+
+ $phpbb_extension_manager = new phpbb_mock_extension_manager($phpbb_root_path);
+ $module_manager = new \phpbb\module\module_manager($cache, $this->db, $phpbb_extension_manager, MODULES_TABLE, $phpbb_root_path, $phpEx);
+
+ $this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $module_manager, $phpbb_root_path, $phpEx, 'phpbb_modules');
}
public function exists_data_acp()
@@ -49,11 +58,39 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
array(
'',
'ACP_CAT',
+ false,
true,
),
array(
0,
'ACP_CAT',
+ false,
+ true,
+ ),
+ array(
+ false,
+ 'ACP_CAT',
+ false,
+ true,
+ ),
+
+ // Test the existing category lazily
+ array(
+ '',
+ 'ACP_CAT',
+ true,
+ true,
+ ),
+ array(
+ 0,
+ 'ACP_CAT',
+ true,
+ true,
+ ),
+ array(
+ false,
+ 'ACP_CAT',
+ true,
true,
),
@@ -62,16 +99,39 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
'',
'ACP_MODULE',
false,
+ false,
+ ),
+ array(
+ false,
+ 'ACP_MODULE',
+ false,
+ true,
+ ),
+ array(
+ 'ACP_CAT',
+ 'ACP_MODULE',
+ false,
+ true,
+ ),
+
+ // Test the existing module lazily
+ array(
+ '',
+ 'ACP_MODULE',
+ true,
+ false,
),
array(
false,
'ACP_MODULE',
true,
+ true,
),
array(
'ACP_CAT',
'ACP_MODULE',
true,
+ true,
),
// Test for non-existant modules
@@ -79,10 +139,38 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
'',
'ACP_NON_EXISTANT_CAT',
false,
+ false,
+ ),
+ array(
+ false,
+ 'ACP_NON_EXISTANT_CAT',
+ false,
+ false,
+ ),
+ array(
+ 'ACP_CAT',
+ 'ACP_NON_EXISTANT_MODULE',
+ false,
+ false,
+ ),
+
+ // Test for non-existant modules lazily
+ array(
+ '',
+ 'ACP_NON_EXISTANT_CAT',
+ true,
+ false,
+ ),
+ array(
+ false,
+ 'ACP_NON_EXISTANT_CAT',
+ true,
+ false,
),
array(
'ACP_CAT',
'ACP_NON_EXISTANT_MODULE',
+ true,
false,
),
);
@@ -91,9 +179,9 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
/**
* @dataProvider exists_data_acp
*/
- public function test_exists_acp($parent, $module, $expected)
+ public function test_exists_acp($parent, $module, $lazy, $expected)
{
- $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module));
+ $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module, $lazy));
}
public function exists_data_ucp()
@@ -103,12 +191,40 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
array(
'',
'UCP_MAIN_CAT',
+ false,
+ true,
+ ),
+ array(
+ 0,
+ 'UCP_MAIN_CAT',
+ false,
+ true,
+ ),
+ array(
+ false,
+ 'UCP_MAIN_CAT',
+ false,
+ true,
+ ),
+
+ // Test the existing category lazily
+ array(
+ '',
+ 'UCP_MAIN_CAT',
+ true,
true,
),
array(
0,
'UCP_MAIN_CAT',
true,
+ true,
+ ),
+ array(
+ false,
+ 'UCP_MAIN_CAT',
+ true,
+ true,
),
// Test the existing module
@@ -116,21 +232,51 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
'',
'UCP_SUBCATEGORY',
false,
+ false,
+ ),
+ array(
+ false,
+ 'UCP_SUBCATEGORY',
+ false,
+ true,
+ ),
+ array(
+ 'UCP_MAIN_CAT',
+ 'UCP_SUBCATEGORY',
+ false,
+ true,
+ ),
+ array(
+ 'UCP_SUBCATEGORY',
+ 'UCP_MODULE',
+ false,
+ true,
+ ),
+
+ // Test the existing module lazily
+ array(
+ '',
+ 'UCP_SUBCATEGORY',
+ true,
+ false,
),
array(
false,
'UCP_SUBCATEGORY',
true,
+ true,
),
array(
'UCP_MAIN_CAT',
'UCP_SUBCATEGORY',
true,
+ true,
),
array(
'UCP_SUBCATEGORY',
'UCP_MODULE',
true,
+ true,
),
// Test for non-existant modules
@@ -138,10 +284,26 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
'',
'UCP_NON_EXISTANT_CAT',
false,
+ false,
+ ),
+ array(
+ 'UCP_MAIN_CAT',
+ 'UCP_NON_EXISTANT_MODULE',
+ false,
+ false,
+ ),
+
+ // Test for non-existant modules lazily
+ array(
+ '',
+ 'UCP_NON_EXISTANT_CAT',
+ true,
+ false,
),
array(
'UCP_MAIN_CAT',
'UCP_NON_EXISTANT_MODULE',
+ true,
false,
),
);
@@ -150,9 +312,9 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
/**
* @dataProvider exists_data_ucp
*/
- public function test_exists_ucp($parent, $module, $expected)
+ public function test_exists_ucp($parent, $module, $lazy, $expected)
{
- $this->assertEquals($expected, $this->tool->exists('ucp', $parent, $module));
+ $this->assertEquals($expected, $this->tool->exists('ucp', $parent, $module, $lazy));
}
public function test_add()
@@ -192,25 +354,6 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
// Test adding module when plural parent module_langname exists
// PHPBB3-14703
- // Adding fail
- try
- {
- $this->tool->add('acp', 'ACP_FORUM_BASED_PERMISSIONS', array(
- 'module_basename' => 'acp_new_permissions_module',
- 'module_langname' => 'ACP_NEW_PERMISSIONS_MODULE',
- 'module_mode' => 'test',
- 'module_auth' => '',
- ));
- $this->fail('Exception not thrown');
- }
- catch (Exception $e)
- {
- $this->assertEquals('phpbb\db\migration\exception', get_class($e));
- $this->assertEquals('MODULE_EXIST_MULTIPLE', $e->getMessage());
- }
-
- // Test adding module when plural parent module_langname exists
- // PHPBB3-14703
// Adding success
try
{
@@ -266,6 +409,35 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
$this->fail($e);
}
$this->assertEquals(true, $this->tool->exists('ucp', 'UCP_NEW_SUBCAT', 'UCP_NEW_MODULE'));
+
+ // Test adding new UCP module the automatic way, single mode
+ try
+ {
+ $this->tool->add('ucp', 'UCP_NEW_CAT', array(
+ 'module_basename' => '\foo\bar\ucp\ucp_test_module',
+ 'modes' => array('mode_1'),
+ ));
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('ucp', 'UCP_NEW_CAT', 'UCP_NEW_MODULE_MODE_1'));
+ $this->assertEquals(false, $this->tool->exists('ucp', 'UCP_NEW_CAT', 'UCP_NEW_MODULE_MODE_2'));
+
+ // Test adding new ACP module the automatic way, all modes
+ try
+ {
+ $this->tool->add('acp', 'ACP_NEW_CAT', array(
+ 'module_basename' => '\foo\bar\acp\acp_test_module',
+ ));
+ }
+ catch (Exception $e)
+ {
+ $this->fail($e);
+ }
+ $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE_MODE_1'));
+ $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE_MODE_2'));
}
public function test_remove()
diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php
index 2d673864f7..ccad6a1387 100644
--- a/tests/dbal/migrator_tool_permission_test.php
+++ b/tests/dbal/migrator_tool_permission_test.php
@@ -11,8 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
{
public $group_ids = array(
@@ -34,7 +32,7 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
parent::setup();
$db = $this->db = $this->new_dbal();
- $cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);
+ $cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);
$this->auth = new \phpbb\auth\auth();
$this->tool = new \phpbb\db\migration\tool\permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx);
@@ -165,7 +163,7 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
$this->assertFalse($this->tool->exists('global_test', true));
}
- public function test_permission_set_data()
+ public function data_test_permission_set()
{
return array(
array(
@@ -190,7 +188,7 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
}
/**
- * @dataProvider test_permission_set_data
+ * @dataProvider data_test_permission_set
*/
public function test_permission_set($group_name, $auth_option, $type, $has_permission)
{
diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php
index f13c7ce032..59965655ad 100644
--- a/tests/dbal/schema_test.php
+++ b/tests/dbal/schema_test.php
@@ -11,8 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_dbal_schema_test extends phpbb_database_test_case
{
public function getDataSet()
diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php
index b7074552ba..0dac66fc46 100644
--- a/tests/dbal/select_test.php
+++ b/tests/dbal/select_test.php
@@ -11,9 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
-
class phpbb_dbal_select_test extends phpbb_database_test_case
{
public function getDataSet()
diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php
index a1b589c578..a2d5921797 100644
--- a/tests/dbal/write_sequence_test.php
+++ b/tests/dbal/write_sequence_test.php
@@ -11,8 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_dbal_write_sequence_test extends phpbb_database_test_case
{
public function getDataSet()
diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php
index 2426f2b0be..4fa5cc37a2 100644
--- a/tests/dbal/write_test.php
+++ b/tests/dbal/write_test.php
@@ -11,8 +11,6 @@
*
*/
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
class phpbb_dbal_write_test extends phpbb_database_test_case
{
public function getDataSet()
@@ -69,7 +67,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case
$result = $db->sql_query($sql);
$rows = $db->sql_fetchrowset($result);
- $this->assertEquals(1, sizeof($rows));
+ $this->assertEquals(1, count($rows));
$this->assertEquals('config2', $rows[0]['config_name']);
$db->sql_freeresult($result);