From d004ef093fd96e5e84b22b5461f8e82594cd1f5e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 10 Jun 2011 02:00:33 +0200 Subject: [ticket/10198] Test if schema allows reading & writing multibyte config values PHPBB3-10198 --- tests/dbal/schema_test.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/dbal/schema_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php new file mode 100644 index 0000000000..2475a85708 --- /dev/null +++ b/tests/dbal/schema_test.php @@ -0,0 +1,38 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_config_value_multibyte() + { + $db = $this->new_dbal(); + + $value = str_repeat("\xC3\x84", 255); + $sql = "INSERT INTO phpbb_config + (config_name, config_value) + VALUES ('name', '$value')"; + $result = $db->sql_query($sql); + + $sql = "SELECT config_value + FROM phpbb_config + WHERE config_name = 'name'"; + $result = $db->sql_query_limit($sql, 1); + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + $this->assertEquals($value, $row['config_value']); + } +} -- cgit v1.2.1 From ff3132a9c63be07ba0db0132faad89364da373e4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 24 Dec 2011 21:25:18 -0500 Subject: [ticket/10507] develop does not have imagesets, fix lower test. PHPBB3-10507 --- tests/dbal/fixtures/styles.xml | 4 ---- tests/dbal/order_lower_test.php | 3 --- 2 files changed, 7 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/styles.xml b/tests/dbal/fixtures/styles.xml index 47b384c47f..36fc22a48f 100644 --- a/tests/dbal/fixtures/styles.xml +++ b/tests/dbal/fixtures/styles.xml @@ -7,7 +7,6 @@ style_active template_id theme_id - imageset_id 1 prosilver @@ -15,7 +14,6 @@ 1 1 1 - 1 2 @@ -24,7 +22,6 @@ 0 2 2 - 2 3 @@ -33,7 +30,6 @@ 0 3 3 - 3 diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index fd1c950252..712efd2d2b 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -35,7 +35,6 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case 'style_active' => 1, 'template_id' => 1, 'theme_id' => 1, - 'imageset_id' => 1 ), array( 'style_id' => 3, @@ -44,7 +43,6 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case 'style_active' => 0, 'template_id' => 3, 'theme_id' => 3, - 'imageset_id' => 3 ), array( 'style_id' => 2, @@ -53,7 +51,6 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case 'style_active' => 0, 'template_id' => 2, 'theme_id' => 2, - 'imageset_id' => 2 ) ), $db->sql_fetchrowset($result) -- cgit v1.2.1 From 66c50f6b30400b729d3fea4fb06dad5eb559aa51 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 2 Jan 2012 17:14:00 +0000 Subject: [ticket/9916] Updating license in non-distributed files PHPBB3-9916 --- tests/dbal/schema_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php index 2475a85708..2a332fddba 100644 --- a/tests/dbal/schema_test.php +++ b/tests/dbal/schema_test.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From ce215658eb70a2dab7309c5f949ceb9b3e1c5a29 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 18 Feb 2012 02:01:35 +0200 Subject: [feature/merging-style-components] Adjusting unit tests Adjusting unit tests for new styles table structure PHPBB3-10632 --- tests/dbal/fixtures/styles.xml | 24 ++++++++++++++++-------- tests/dbal/order_lower_test.php | 18 ++++++++++++------ 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/styles.xml b/tests/dbal/fixtures/styles.xml index 36fc22a48f..dcbe39d3b0 100644 --- a/tests/dbal/fixtures/styles.xml +++ b/tests/dbal/fixtures/styles.xml @@ -5,31 +5,39 @@ style_name style_copyright style_active - template_id - theme_id + style_path + bbcode_bitfield + style_parent_id + style_parent_tree 1 prosilver © phpBB Group 1 - 1 - 1 + prosilver + kNg= + 0 + 2 prosilver2 © phpBB Group 0 - 2 - 2 + prosilver2 + kNg= + 0 + 3 Prosilver1 © phpBB Group 0 - 3 - 3 + prosilver1 + kNg= + 1 + prosilver diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index eaf5211508..e16c0c20ee 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -33,24 +33,30 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case 'style_name' => 'prosilver', 'style_copyright' => '© phpBB Group', 'style_active' => 1, - 'template_id' => 1, - 'theme_id' => 1, + 'style_path' => 'prosilver', + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', ), array( 'style_id' => 3, 'style_name' => 'Prosilver1', 'style_copyright' => '© phpBB Group', 'style_active' => 0, - 'template_id' => 3, - 'theme_id' => 3, + 'style_path' => 'prosilver1', + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => 1, + 'style_parent_tree' => 'prosilver', ), array( 'style_id' => 2, 'style_name' => 'prosilver2', 'style_copyright' => '© phpBB Group', 'style_active' => 0, - 'template_id' => 2, - 'theme_id' => 2, + 'style_path' => 'prosilver2', + 'bbcode_bitfield' => 'kNg=', + 'style_parent_id' => 0, + 'style_parent_tree' => '', ) ), $db->sql_fetchrowset($result) -- cgit v1.2.1 From f5bac7686b1678dbd33eddd368d845237bb18943 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 1 Apr 2012 19:14:53 +0300 Subject: [ticket/10733] Removing static from data providers Removing static from data provider functions PHPBB3-10733 --- tests/dbal/select_test.php | 14 +++++++------- tests/dbal/write_test.php | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index 21b12777dc..cc213f09bc 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -17,7 +17,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); } - public static function return_on_error_select_data() + public function return_on_error_select_data() { return array( array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))), @@ -44,7 +44,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $this->assertEquals($expected, $db->sql_fetchrowset($result)); } - public static function fetchrow_data() + public function fetchrow_data() { return array( array('', array(array('username_clean' => 'barfoo'), @@ -95,7 +95,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public static function fetchfield_data() + public function fetchfield_data() { return array( array('', array('barfoo', 'foobar', 'bertie')), @@ -125,7 +125,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $this->assertEquals($expected, $ary); } - public static function query_limit_data() + public function query_limit_data() { return array( array(0, 0, array(array('username_clean' => 'barfoo'), @@ -166,7 +166,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $this->assertEquals($expected, $ary); } - public static function like_expression_data() + public function like_expression_data() { // * = any_char; # = one_char return array( @@ -203,7 +203,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public static function in_set_data() + public function in_set_data() { return array( array('user_id', 3, false, false, array(array('username_clean' => 'bertie'))), @@ -277,7 +277,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public static function build_array_data() + public function build_array_data() { return array( array(array('username_clean' => 'barfoo'), array(array('username_clean' => 'barfoo'))), diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php index 596c50a220..987161a831 100644 --- a/tests/dbal/write_test.php +++ b/tests/dbal/write_test.php @@ -16,7 +16,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } - public static function build_array_insert_data() + public function build_array_insert_data() { return array( array(array( @@ -104,7 +104,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public static function update_data() + public function update_data() { return array( array( -- cgit v1.2.1 From dd0da6fffb3358937ebfdb3ff347089d97e64a1a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 01:50:42 +0200 Subject: [ticket/10942] Add unit tests for sql_conditional PHPBB3-10942 --- tests/dbal/conditional_test.php | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/dbal/conditional_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/conditional_test.php b/tests/dbal/conditional_test.php new file mode 100644 index 0000000000..3e01de05f6 --- /dev/null +++ b/tests/dbal/conditional_test.php @@ -0,0 +1,64 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_conditional_string() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'false', + ), + array( + 'config_name' => 'config2', + 'string' => 'true', + ), + ), + $db->sql_fetchrowset($result) + ); + } + + public function test_conditional_statement() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'foo', + ), + array( + 'config_name' => 'config2', + 'string' => '1', + ), + ), + $db->sql_fetchrowset($result) + ); + } +} -- cgit v1.2.1 From 8cea7b2a5173a69889d76b1e27469cf15e95cefc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 02:10:54 +0200 Subject: [ticket/10942] Add unit tests for sql_concatenate PHPBB3-10942 --- tests/dbal/concatenate_test.php | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/dbal/concatenate_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php new file mode 100644 index 0000000000..0891fa58a0 --- /dev/null +++ b/tests/dbal/concatenate_test.php @@ -0,0 +1,64 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_concatenate_string() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'config1append', + ), + array( + 'config_name' => 'config2', + 'string' => 'config2append', + ), + ), + $db->sql_fetchrowset($result) + ); + } + + public function test_concatenate_statement() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'config1foo', + ), + array( + 'config_name' => 'config2', + 'string' => 'config2bar', + ), + ), + $db->sql_fetchrowset($result) + ); + } +} -- cgit v1.2.1 From 4fbbbfcebb6f8ed9867cb61623767a2f4c191ed6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 02:12:48 +0200 Subject: [ticket/10942] Fix function name on order_lower_test.php PHPBB3-10942 --- tests/dbal/order_lower_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index e16c0c20ee..84d454742f 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -14,7 +14,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/styles.xml'); } - public function test_cross_join() + public function test_order_lower() { $db = $this->new_dbal(); -- cgit v1.2.1 From 089e5f5c79965058a5288590a3a34d94f3bcb833 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 20 Jun 2012 12:57:08 +0200 Subject: [ticket/10942] Rename method sql_conditional() to sql_case() PHPBB3-10942 --- tests/dbal/case_test.php | 64 +++++++++++++++++++++++++++++++++++++++++ tests/dbal/conditional_test.php | 64 ----------------------------------------- 2 files changed, 64 insertions(+), 64 deletions(-) create mode 100644 tests/dbal/case_test.php delete mode 100644 tests/dbal/conditional_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php new file mode 100644 index 0000000000..7e966c0ec1 --- /dev/null +++ b/tests/dbal/case_test.php @@ -0,0 +1,64 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function test_case_string() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'false', + ), + array( + 'config_name' => 'config2', + 'string' => 'true', + ), + ), + $db->sql_fetchrowset($result) + ); + } + + public function test_case_statement() + { + $db = $this->new_dbal(); + + $sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string + FROM phpbb_config'; + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array( + 'config_name' => 'config1', + 'string' => 'foo', + ), + array( + 'config_name' => 'config2', + 'string' => '1', + ), + ), + $db->sql_fetchrowset($result) + ); + } +} diff --git a/tests/dbal/conditional_test.php b/tests/dbal/conditional_test.php deleted file mode 100644 index 3e01de05f6..0000000000 --- a/tests/dbal/conditional_test.php +++ /dev/null @@ -1,64 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); - } - - public function test_conditional_string() - { - $db = $this->new_dbal(); - - $sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string - FROM phpbb_config'; - $result = $db->sql_query($sql); - - $db->sql_return_on_error(false); - - $this->assertEquals(array( - array( - 'config_name' => 'config1', - 'string' => 'false', - ), - array( - 'config_name' => 'config2', - 'string' => 'true', - ), - ), - $db->sql_fetchrowset($result) - ); - } - - public function test_conditional_statement() - { - $db = $this->new_dbal(); - - $sql = 'SELECT config_name, ' . $db->sql_conditional('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string - FROM phpbb_config'; - $result = $db->sql_query($sql); - - $db->sql_return_on_error(false); - - $this->assertEquals(array( - array( - 'config_name' => 'config1', - 'string' => 'foo', - ), - array( - 'config_name' => 'config2', - 'string' => '1', - ), - ), - $db->sql_fetchrowset($result) - ); - } -} -- cgit v1.2.1 From 0fd02035d8dd12db4a793af5be564911fca4f900 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 30 Jun 2012 13:00:41 +0200 Subject: [ticket/10942] Make unit tests for sql_case simpler PHPBB3-10942 --- tests/dbal/case_test.php | 50 ++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index 7e966c0ec1..684f2c26a9 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -18,47 +18,35 @@ class phpbb_dbal_case_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', "'" . $db->sql_escape('true') . "'", "'" . $db->sql_escape('false') . "'") . ' AS string + $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '0') . ' AS bool FROM phpbb_config'; - $result = $db->sql_query($sql); + $result = $db->sql_query_limit($sql, 1); - $db->sql_return_on_error(false); + $this->assertEquals(true, (bool) $db->sql_fetchfield('bool')); - $this->assertEquals(array( - array( - 'config_name' => 'config1', - 'string' => 'false', - ), - array( - 'config_name' => 'config2', - 'string' => 'true', - ), - ), - $db->sql_fetchrowset($result) - ); + $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '0') . ' AS bool + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(false, (bool) $db->sql_fetchfield('bool')); } public function test_case_statement() { $db = $this->new_dbal(); - $sql = 'SELECT config_name, ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', 'config_value') . ' AS string - FROM phpbb_config'; - $result = $db->sql_query($sql); + $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', '0') . " AS bool + FROM phpbb_config + WHERE is_dynamic = 1"; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(true, (bool) $db->sql_fetchfield('bool')); - $db->sql_return_on_error(false); + $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', '1', 'is_dynamic') . " AS bool + FROM phpbb_config + WHERE is_dynamic = 0"; + $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(array( - array( - 'config_name' => 'config1', - 'string' => 'foo', - ), - array( - 'config_name' => 'config2', - 'string' => '1', - ), - ), - $db->sql_fetchrowset($result) - ); + $this->assertEquals(false, (bool) $db->sql_fetchfield('bool')); } } -- cgit v1.2.1 From ad9d6506594f90ac7c6cdf20a5718d28042059c9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 2 Jul 2012 11:10:58 +0200 Subject: [ticket/10942] Fix up unit tests for sql_case() PHPBB3-10942 --- tests/dbal/case_test.php | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index 684f2c26a9..5219defa06 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -14,39 +14,56 @@ class phpbb_dbal_case_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } + public function test_case_int() + { + $db = $this->new_dbal(); + + $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS num + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(1, (int) $db->sql_fetchfield('num')); + + $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS num + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals(2, (int) $db->sql_fetchfield('num')); + } + public function test_case_string() { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '0') . ' AS bool + $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS string FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(true, (bool) $db->sql_fetchfield('bool')); + $this->assertEquals('foo', $db->sql_fetchfield('string')); - $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '0') . ' AS bool + $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS string FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(false, (bool) $db->sql_fetchfield('bool')); + $this->assertEquals('bar', $db->sql_fetchfield('string')); } - public function test_case_statement() + public function test_case_column() { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', 'is_dynamic', '0') . " AS bool + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string FROM phpbb_config - WHERE is_dynamic = 1"; + WHERE config_name = 'config1'"; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(true, (bool) $db->sql_fetchfield('bool')); + $this->assertEquals('config1', $db->sql_fetchfield('string')); - $sql = 'SELECT ' . $db->sql_case('is_dynamic = 1', '1', 'is_dynamic') . " AS bool + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string FROM phpbb_config - WHERE is_dynamic = 0"; + WHERE config_value = 'bar'"; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(false, (bool) $db->sql_fetchfield('bool')); + $this->assertEquals('bar', $db->sql_fetchfield('string')); } } -- cgit v1.2.1 From 1b826842aadc16ad35485479f4bb3bdef03b534c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 16 Jul 2012 16:59:40 +0200 Subject: [ticket/10942] Avoid possible conflicts with magic words in unit tests PHPBB3-10942 --- tests/dbal/case_test.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index 5219defa06..57a1729a39 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -18,52 +18,52 @@ class phpbb_dbal_case_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS num + $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(1, (int) $db->sql_fetchfield('num')); + $this->assertEquals(1, (int) $db->sql_fetchfield('test_num')); - $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS num + $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, (int) $db->sql_fetchfield('num')); + $this->assertEquals(2, (int) $db->sql_fetchfield('test_num')); } public function test_case_string() { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS string + $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals('foo', $db->sql_fetchfield('string')); + $this->assertEquals('foo', $db->sql_fetchfield('test_string')); - $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS string + $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals('bar', $db->sql_fetchfield('string')); + $this->assertEquals('bar', $db->sql_fetchfield('test_string')); } public function test_case_column() { $db = $this->new_dbal(); - $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string FROM phpbb_config WHERE config_name = 'config1'"; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals('config1', $db->sql_fetchfield('string')); + $this->assertEquals('config1', $db->sql_fetchfield('test_string')); - $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS string + $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string FROM phpbb_config WHERE config_value = 'bar'"; $result = $db->sql_query_limit($sql, 1); - $this->assertEquals('bar', $db->sql_fetchfield('string')); + $this->assertEquals('bar', $db->sql_fetchfield('test_string')); } } -- cgit v1.2.1 From 5b368dd53a2da6ab481bc608176f442dc067c4a7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 7 Dec 2012 15:32:06 -0500 Subject: [ticket/11255] Fix dbal write sequence test to run standalone. PHPBB3-11255 --- tests/dbal/write_sequence_test.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php index 8975cfbfb1..f382a971a5 100644 --- a/tests/dbal/write_sequence_test.php +++ b/tests/dbal/write_sequence_test.php @@ -33,6 +33,10 @@ class phpbb_dbal_write_sequence_test extends phpbb_database_test_case { $db = $this->new_dbal(); + // dbal uses cache + global $cache; + $cache = new phpbb_mock_cache(); + $sql = 'INSERT INTO phpbb_users ' . $db->sql_build_array('INSERT', array( 'username' => $username, 'username_clean' => $username, -- cgit v1.2.1 From f5c745d2c57840f3505bad98df48c2b6b8433b75 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 13 Dec 2012 08:09:32 -0500 Subject: [ticket/11015] Convert connect test to the new syntax. PHPBB3-11015 --- tests/dbal/connect_test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php index 505ce28fa1..1e352d6b03 100644 --- a/tests/dbal/connect_test.php +++ b/tests/dbal/connect_test.php @@ -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. -- cgit v1.2.1 From f817e20f287a21e2dddfba9721f5e02dce162d29 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 15 Jul 2011 11:57:53 -0400 Subject: [feature/migrations] Basic migrations with schema and data changes The migrator takes care of applying migrations as necessary. RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41337 PHPBB3-9737 --- tests/dbal/fixtures/migrator.xml | 27 ++++++++++++ tests/dbal/migration/dummy.php | 26 +++++++++++ tests/dbal/migration/unfulfillable.php | 26 +++++++++++ tests/dbal/migrator_test.php | 80 ++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 tests/dbal/fixtures/migrator.xml create mode 100644 tests/dbal/migration/dummy.php create mode 100644 tests/dbal/migration/unfulfillable.php create mode 100644 tests/dbal/migrator_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/migrator.xml b/tests/dbal/fixtures/migrator.xml new file mode 100644 index 0000000000..1f9079c811 --- /dev/null +++ b/tests/dbal/fixtures/migrator.xml @@ -0,0 +1,27 @@ + + + + migration_name + migration_schema_done + migration_data_done + migration_data_state + migration_start_time + migration_end_time + + installed_migration + 1 + 1 + + 1234 + 5678 + +
+ + config_name + config_value + + foo + bar + +
+
diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php new file mode 100644 index 0000000000..b286d44f77 --- /dev/null +++ b/tests/dbal/migration/dummy.php @@ -0,0 +1,26 @@ +db_column_add('phpbb_config', 'extra_column', array('UINT', 0)); + } + + function update_data() + { + $this->db->sql_query('UPDATE phpbb_config SET extra_column = 1'); + } +} diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php new file mode 100644 index 0000000000..84136ffe6d --- /dev/null +++ b/tests/dbal/migration/unfulfillable.php @@ -0,0 +1,26 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml'); + } + + public function setup() + { + parent::setup(); + + $this->db = $this->new_dbal(); + $this->db_tools = new phpbb_db_tools($this->db); + $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE); + } + + public function test_update() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy')); + + // schema + $this->migrator->update(); + $this->assertFalse($this->migrator->finished()); + + // data + $this->migrator->update(); + $this->assertTrue($this->migrator->finished()); + + $this->assertSqlResultEquals( + array(array('extra_column' => '1')), + "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", + 'Dummy migration created extra_column with value 1 in all rows.' + ); + + // cleanup + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } + + public function test_unfulfillable() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy')); + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->finished()); + + $this->assertSqlResultEquals( + array(array('extra_column' => '1')), + "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", + 'Dummy migration was run, even though an unfulfillable migration was found.' + ); + + // cleanup + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } +} -- cgit v1.2.1 From d304b6449db6e7c6f3c9058062aca0c641f023a4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 7 Aug 2011 19:10:38 -0400 Subject: [feature/migrations] Store start and end time of migrations PHPBB3-9737 --- tests/dbal/migrator_test.php | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 1e7d1343fc..dd194d7c05 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -26,7 +26,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml'); } - public function setup() + public function setUp() { parent::setup(); @@ -35,6 +35,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE); } + public function tearDown() + { + // cleanup + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + } + public function test_update() { $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy')); @@ -43,6 +49,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator->update(); $this->assertFalse($this->migrator->finished()); + $this->assertSqlResultEquals( + array(array('success' => '1')), + "SELECT 1 as success + FROM phpbb_migrations + WHERE migration_name = 'phpbb_dbal_migration_dummy' + AND migration_start_time >= " . (time() - 1) . " + AND migration_start_time <= " . (time() + 1), + 'Start time set correctly' + ); + // data $this->migrator->update(); $this->assertTrue($this->migrator->finished()); @@ -53,8 +69,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'Dummy migration created extra_column with value 1 in all rows.' ); - // cleanup - $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + $this->assertSqlResultEquals( + array(array('success' => '1')), + "SELECT 1 as success + FROM phpbb_migrations + WHERE migration_name = 'phpbb_dbal_migration_dummy' + AND migration_start_time <= migration_end_time + AND migration_end_time >= " . (time() - 1) . " + AND migration_end_time <= " . (time() + 1), + 'End time set correctly' + ); } public function test_unfulfillable() @@ -73,8 +97,5 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", 'Dummy migration was run, even though an unfulfillable migration was found.' ); - - // cleanup - $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); } } -- cgit v1.2.1 From 8645321f40d0b13de6201688c69f9f05bc649dcf Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 12:26:44 -0700 Subject: [feature/migrations] Return schema changes in database update style array Returning the set of schema changes allows potentially aggregating to generate the overall install schema automatically from a set of migrations PHPBB3-9737 --- tests/dbal/migration/dummy.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index b286d44f77..0567b50740 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -16,7 +16,13 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration function update_schema() { - $this->db_column_add('phpbb_config', 'extra_column', array('UINT', 0)); + return array( + 'add_columns' => array( + 'phpbb_config' => array( + 'extra_column' => array('UINT', 0), + ), + ), + ); } function update_data() -- cgit v1.2.1 From c802f2a66c577781036b7bfd6d6689159028c3a6 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 25 Oct 2012 13:02:56 -0700 Subject: [feature/migrations] Standard vars for migrations and run sql with feedback PHPBB3-9737 --- tests/dbal/migrator_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index dd194d7c05..898a197dfd 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -32,7 +32,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->db_tools = new phpbb_db_tools($this->db); - $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, MIGRATIONS_TABLE); + $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, 'phpbb_', MIGRATIONS_TABLE, 'phpBB/', '.php'); } public function tearDown() -- cgit v1.2.1 From 41de95bc11c0b64eafa294f03432f619d3d712d5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 11 Nov 2012 12:12:05 +0100 Subject: [feature/migrations] Process migration steps and move to PHP5 code --- tests/dbal/migration/dummy.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index 0567b50740..942c499bb5 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -27,6 +27,13 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration function update_data() { - $this->db->sql_query('UPDATE phpbb_config SET extra_column = 1'); + return array( + array('if', array(true, array('custom', array(array($this, 'set_extra_column'))))), + ); + } + + public function set_extra_column() + { + $this->sql_query('UPDATE phpbb_config SET extra_column = 1'); } } -- cgit v1.2.1 From 5c91e2569cb3a400acd20bf06cc0e609dd63a778 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 8 Jan 2013 22:09:14 -0600 Subject: [feature/migrations] Migrations now somewhat works PHPBB3-9737 --- tests/dbal/fixtures/migrator_module.xml | 42 +++++++++ tests/dbal/fixtures/migrator_permission.xml | 31 +++++++ tests/dbal/migrator_test.php | 12 ++- tests/dbal/migrator_tool_config_test.php | 97 ++++++++++++++++++++ tests/dbal/migrator_tool_module.php | 128 ++++++++++++++++++++++++++ tests/dbal/migrator_tool_permission.php | 136 ++++++++++++++++++++++++++++ 6 files changed, 443 insertions(+), 3 deletions(-) create mode 100644 tests/dbal/fixtures/migrator_module.xml create mode 100644 tests/dbal/fixtures/migrator_permission.xml create mode 100644 tests/dbal/migrator_tool_config_test.php create mode 100644 tests/dbal/migrator_tool_module.php create mode 100644 tests/dbal/migrator_tool_permission.php (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/migrator_module.xml b/tests/dbal/fixtures/migrator_module.xml new file mode 100644 index 0000000000..32afe7e6f3 --- /dev/null +++ b/tests/dbal/fixtures/migrator_module.xml @@ -0,0 +1,42 @@ + + + + module_id + module_enabled + module_display + module_basename + module_class + parent_id + left_id + right_id + module_langname + module_mode + module_auth + + 1 + 1 + 1 + + acp + 0 + 1 + 4 + ACP_CAT + + + + + 2 + 1 + 1 + acp_test + acp + 1 + 2 + 3 + ACP_MODULE + test + + +
+
diff --git a/tests/dbal/fixtures/migrator_permission.xml b/tests/dbal/fixtures/migrator_permission.xml new file mode 100644 index 0000000000..08cec42a42 --- /dev/null +++ b/tests/dbal/fixtures/migrator_permission.xml @@ -0,0 +1,31 @@ + + + + auth_option_id + auth_option + is_global + is_local + founder_only + + 1 + global + 1 + 0 + 0 + + + 2 + local + 0 + 1 + 0 + + + 3 + both + 1 + 1 + 0 + +
+
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 898a197dfd..463cf9fcec 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; require_once dirname(__FILE__) . '/migration/dummy.php'; @@ -28,11 +28,17 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case public function setUp() { - parent::setup(); + parent::setUp(); $this->db = $this->new_dbal(); $this->db_tools = new phpbb_db_tools($this->db); - $this->migrator = new phpbb_db_migrator($this->db, $this->db_tools, 'phpbb_', MIGRATIONS_TABLE, 'phpBB/', '.php'); + + $this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config'); + + $tools = array( + new phpbb_db_migration_tool_config($this->config), + ); + $this->migrator = new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools); } public function tearDown() diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php new file mode 100644 index 0000000000..27511519ca --- /dev/null +++ b/tests/dbal/migrator_tool_config_test.php @@ -0,0 +1,97 @@ +config = new phpbb_config(array()); + + $this->tool = new phpbb_db_migration_tool_config($this->config); + + parent::setup(); + } + + public function test_add() + { + try + { + $this->tool->add('foo', 'bar'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar', $this->config['foo']); + + try + { + $this->tool->add('foo', 'bar'); + $this->fail('Exception not thrown'); + } + catch (Exception $e) {} + } + + public function test_update() + { + $this->config->set('foo', 'bar'); + try + { + $this->tool->update('foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar2', $this->config['foo']); + } + + public function test_update_if_equals() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->update_if_equals('', 'foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar', $this->config['foo']); + + try + { + $this->tool->update_if_equals('bar', 'foo', 'bar2'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('bar2', $this->config['foo']); + } + + public function test_remove() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->remove('foo'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse(isset($this->config['foo'])); + } +} diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php new file mode 100644 index 0000000000..0b57cbfbcb --- /dev/null +++ b/tests/dbal/migrator_tool_module.php @@ -0,0 +1,128 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml'); + } + + public function setup() + { + // Need global $db, $user for delete_module function in acp_modules + global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; + + parent::setup(); + + // Force add_log function to not be used + $skip_add_log = true; + + $db = $this->db = $this->new_dbal(); + $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null()); + $user = $this->user = new phpbb_user(); + + $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx); + } + + public function exists_data() + { + return array( + // Test the category + array( + '', + 'ACP_CAT', + true, + ), + array( + 0, + 'ACP_CAT', + true, + ), + + // Test the module + array( + '', + 'ACP_MODULE', + false, + ), + array( + false, + 'ACP_MODULE', + true, + ), + array( + 'ACP_CAT', + 'ACP_MODULE', + true, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($parent, $module, $expected) + { + $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module)); + } + + public function test_add() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + + // Should throw an exception when trying to add a module that already exists + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + $this->fail('Exception not thrown'); + } + catch (Exception $e) {} + + try + { + $this->tool->add('acp', ACP_NEW_CAT, array( + 'module_basename' => 'acp_new_module', + 'module_langname' => 'ACP_NEW_MODULE', + 'module_mode' => 'test', + 'module_auth' => '', + )); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE')); + } + + public function test_remove() + { + try + { + $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE')); + } +} diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php new file mode 100644 index 0000000000..2229576cd9 --- /dev/null +++ b/tests/dbal/migrator_tool_permission.php @@ -0,0 +1,136 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml'); + } + + public function setup() + { + // Global $db and $cache are needed in acp/auth.php constructor + global $phpbb_root_path, $phpEx, $db, $cache; + + parent::setup(); + + $db = $this->db = $this->new_dbal(); + $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null()); + $this->auth = new phpbb_auth(); + + $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); + } + + public function exists_data() + { + return array( + array( + 'global', + true, + true, + ), + array( + 'local', + false, + true, + ), + array( + 'both', + true, + true, + ), + array( + 'both', + false, + true, + ), + array( + 'does_not_exist', + true, + false, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($auth_option, $global, $expected) + { + $this->assertEquals($expected, $this->tool->exists($auth_option, $global)); + } + + public function test_add() + { + try + { + $this->tool->add('new', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', true)); + $this->assertEquals(false, $this->tool->exists('new', false)); + + try + { + $this->tool->add('new', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', false)); + + // Should fail (duplicate) + try + { + $this->tool->add('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_remove() + { + try + { + $this->tool->remove('global', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('global', true)); + + try + { + $this->tool->remove('both', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('both', false)); + + // Should fail (does not exist) + try + { + $this->tool->remove('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } +} -- cgit v1.2.1 From 445667a62e80c42b5406c981d1116ef99a23df3b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 16:31:56 -0600 Subject: [feature/migrations] Fix if method (and create a test for it) PHPBB3-9737 --- tests/dbal/migration/dummy.php | 14 +----------- tests/dbal/migration/if.php | 49 ++++++++++++++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 35 ++++++++++++++++++++++++------ 3 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 tests/dbal/migration/if.php (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index 942c499bb5..e542493f9f 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -19,21 +19,9 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration return array( 'add_columns' => array( 'phpbb_config' => array( - 'extra_column' => array('UINT', 0), + 'extra_column' => array('UINT', 1), ), ), ); } - - function update_data() - { - return array( - array('if', array(true, array('custom', array(array($this, 'set_extra_column'))))), - ); - } - - public function set_extra_column() - { - $this->sql_query('UPDATE phpbb_config SET extra_column = 1'); - } } diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php new file mode 100644 index 0000000000..aa9a5dab87 --- /dev/null +++ b/tests/dbal/migration/if.php @@ -0,0 +1,49 @@ +migrator = new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools); } - public function tearDown() - { - // cleanup - $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); - } - public function test_update() { $this->migrator->set_migrations(array('phpbb_dbal_migration_dummy')); @@ -85,6 +80,9 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case AND migration_end_time <= " . (time() + 1), 'End time set correctly' ); + + // cleanup + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); } public function test_unfulfillable() @@ -104,4 +102,29 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'Dummy migration was run, even though an unfulfillable migration was found.' ); } + + public function test_if() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_if')); + + // Don't like this, but I'm not sure there is any other way to do this + global $migrator_test_if_true_failed, $migrator_test_if_false_failed; + $migrator_test_if_true_failed = true; + $migrator_test_if_false_failed = false; + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + if ($migrator_test_if_true_failed) + { + $this->fail('True test failed'); + } + + if ($migrator_test_if_false_failed) + { + $this->fail('False test failed'); + } + } } -- cgit v1.2.1 From 3d4c00619f1c96df7a4c6f8bc1c03eb21abf49d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 9 Jan 2013 18:24:32 -0600 Subject: [feature/migrations] Reverse data functionality If data step fails, attempt to roll back any previous calls from the migration that failed. Fix some failing tests PHPBB3-9737 --- tests/dbal/migrator_tool_config_test.php | 27 +++++++++++++++++++++++++++ tests/dbal/migrator_tool_module.php | 28 +++++++++++++++++++++++++--- tests/dbal/migrator_tool_permission.php | 25 ++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 4 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index 27511519ca..7d582f230b 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -94,4 +94,31 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case } $this->assertFalse(isset($this->config['foo'])); } + + public function test_reverse() + { + $this->config->set('foo', 'bar'); + + try + { + $this->tool->reverse('add', 'foo'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse(isset($this->config['foo'])); + + $this->config->set('foo', 'bar'); + + try + { + $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals('test', $this->config['foo']); + } } diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php index 0b57cbfbcb..6937b6f8c5 100644 --- a/tests/dbal/migrator_tool_module.php +++ b/tests/dbal/migrator_tool_module.php @@ -29,10 +29,10 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $skip_add_log = true; $db = $this->db = $this->new_dbal(); - $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null()); + $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); $user = $this->user = new phpbb_user(); - $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx); + $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); } public function exists_data() @@ -99,7 +99,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case try { - $this->tool->add('acp', ACP_NEW_CAT, array( + $this->tool->add('acp', 'ACP_NEW_CAT', array( 'module_basename' => 'acp_new_module', 'module_langname' => 'ACP_NEW_MODULE', 'module_mode' => 'test', @@ -125,4 +125,26 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case } $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE')); } + + public function test_reverse() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + + try + { + $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + } } diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php index 2229576cd9..438ab2b28e 100644 --- a/tests/dbal/migrator_tool_permission.php +++ b/tests/dbal/migrator_tool_permission.php @@ -26,7 +26,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()); + $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); $this->auth = new phpbb_auth(); $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); @@ -133,4 +133,27 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case } catch (Exception $e) {} } + + public function test_reverse() + { + try + { + $this->tool->reverse('remove', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertTrue($this->tool->exists('global_test', true)); + + try + { + $this->tool->reverse('add', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('global_test', true)); + } } -- cgit v1.2.1 From ddb1eaab6868cfac70b7b202468cab29315b794d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 12:49:13 -0600 Subject: [feature/migrations] Test for calling a step multiple times This is used when a long-running process is needed during an update. For example, iterating over all posts and applying some transformation. This allows the process to be broken apart into multiple shorter steps to prevent hitting the time limit. PHPBB3-9737 --- tests/dbal/migration/recall.php | 43 +++++++++++++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 23 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/dbal/migration/recall.php (limited to 'tests/dbal') diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php new file mode 100644 index 0000000000..18d8b4a6d2 --- /dev/null +++ b/tests/dbal/migration/recall.php @@ -0,0 +1,43 @@ +fail('False test failed'); } } + + public function test_recall() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_recall')); + + global $migrator_test_call_input; + + // Run the schema first + $this->migrator->update(); + + $i = 0; + while (!$this->migrator->finished()) + { + $this->migrator->update(); + + $this->assertSame($i, $migrator_test_call_input); + + $i++; + } + + $this->assertSame(10, $migrator_test_call_input); + } } -- cgit v1.2.1 From 00385aa742da17678f7d147b6d71fa759fcd7e78 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 13:52:11 -0600 Subject: [feature/migrations] Basic reverting test PHPBB3-9737 --- tests/dbal/migration/revert.php | 45 +++++++++++++++++++++ tests/dbal/migration/revert_with_dependency.php | 16 ++++++++ tests/dbal/migrator_test.php | 54 +++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 tests/dbal/migration/revert.php create mode 100644 tests/dbal/migration/revert_with_dependency.php (limited to 'tests/dbal') diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php new file mode 100644 index 0000000000..2bb23e31c2 --- /dev/null +++ b/tests/dbal/migration/revert.php @@ -0,0 +1,45 @@ + array( + 'phpbb_config' => array( + 'bar_column' => array('UINT', 1), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + 'phpbb_config' => array( + 'bar_column', + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('foobartest', 0)), + ); + } +} diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php new file mode 100644 index 0000000000..f6820dbf3f --- /dev/null +++ b/tests/dbal/migration/revert_with_dependency.php @@ -0,0 +1,16 @@ +db_tools->sql_column_remove('phpbb_config', 'extra_column'); } public function test_if() @@ -150,4 +154,54 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertSame(10, $migrator_test_call_input); } + + public function test_revert() + { + // 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', 'phpbb_dbal_migration_revert_with_dependency')); + + $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + + // Install the migration first + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->migration_installed('phpbb_dbal_migration_revert')); + $this->assertTrue($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + + $this->assertSqlResultEquals( + array(array('bar_column' => '1')), + "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", + 'Installing revert migration failed to create bar_column.' + ); + + $this->assertTrue(isset($this->config['foobartest'])); + + while ($this->migrator->migration_installed('phpbb_dbal_migration_revert')) + { + $this->migrator->revert('phpbb_dbal_migration_revert'); + } + + $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + + $this->assertFalse(isset($this->config['foobartest'])); + + try + { + // Should cause an error + $this->assertSqlResultEquals( + false, + "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", + 'Revert did not remove bar_column.' + ); + } + catch (Exception $e) {} + } } -- cgit v1.2.1 From d50500860fe44a78c8f29e0f2382b96da17c0b62 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 15:09:51 -0600 Subject: [feature/migrations] Store depends on in the database (serialized) This is required so that when migrations are reverted we can check through all installed migrations and make sure that all dependencies are handled properly and so that we are only required to load the migrations files that could be dependent on the ones installed. I believe in normal proper use the old way might have worked, but in case something happens and an unrelated migration file is installed, but cannot be loaded, this makes sure we do not stop everything unless we absolutely must (one of those files is dependent on something we want to revert). PHPBB3-9737 --- tests/dbal/fixtures/migrator.xml | 2 ++ tests/dbal/migration/fail.php | 46 ++++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 57 ++++++++++++++++++++++++++++++---------- 3 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 tests/dbal/migration/fail.php (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/migrator.xml b/tests/dbal/fixtures/migrator.xml index 1f9079c811..25be4d4129 100644 --- a/tests/dbal/fixtures/migrator.xml +++ b/tests/dbal/fixtures/migrator.xml @@ -2,6 +2,7 @@ migration_name + migration_depends_onmigration_schema_donemigration_data_donemigration_data_state @@ -9,6 +10,7 @@ migration_end_time installed_migration + 1 1 diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php new file mode 100644 index 0000000000..8b5c521e09 --- /dev/null +++ b/tests/dbal/migration/fail.php @@ -0,0 +1,46 @@ + array( + $this->table_prefix . 'config' => array( + 'test_column' => array('BOOL', 1), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'config' => array( + 'test_column', + ), + ), + ); + } + + function update_data() + { + return array( + array('config.add', array('foobar3', true)), + array('config.update', array('does_not_exist', true)), + ); + } +} diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 84bcb109b2..69db7ca047 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -18,6 +18,7 @@ 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/fail.php'; class phpbb_dbal_migrator_test extends phpbb_database_test_case { @@ -163,8 +164,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency')); - $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert')); - $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency')); // Install the migration first while (!$this->migrator->finished()) @@ -172,8 +173,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator->update(); } - $this->assertTrue($this->migrator->migration_installed('phpbb_dbal_migration_revert')); - $this->assertTrue($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false); + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency') !== false); $this->assertSqlResultEquals( array(array('bar_column' => '1')), @@ -183,25 +184,53 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertTrue(isset($this->config['foobartest'])); - while ($this->migrator->migration_installed('phpbb_dbal_migration_revert')) + while ($this->migrator->migration_state('phpbb_dbal_migration_revert') !== false) { $this->migrator->revert('phpbb_dbal_migration_revert'); } - $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert')); - $this->assertFalse($this->migrator->migration_installed('phpbb_dbal_migration_revert_with_dependency')); + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); + $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert_with_dependency')); $this->assertFalse(isset($this->config['foobartest'])); + $sql = 'SELECT * FROM phpbb_config'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (isset($row['bar_column'])) + { + $this->fail('Revert did not remove test_column.'); + } + } + + public function test_fail() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_fail')); + + $this->assertFalse(isset($this->config['foobar3'])); + try { - // Should cause an error - $this->assertSqlResultEquals( - false, - "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", - 'Revert did not remove bar_column.' - ); + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + } + catch (phpbb_db_migration_exception $e) {} + + // Failure should have caused an automatic roll-back, so this should not exist. + $this->assertFalse(isset($this->config['foobar3'])); + + $sql = 'SELECT * FROM phpbb_config'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if (isset($row['test_column'])) + { + $this->fail('Revert did not remove test_column.'); } - catch (Exception $e) {} } } -- cgit v1.2.1 From 9f38dc67a80b5fc2a8bb0d01825d7655915e3319 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 22:48:31 -0600 Subject: [feature/migrations] Make the test depends_on methods static PHPBB3-11318 --- tests/dbal/migration/dummy.php | 2 +- tests/dbal/migration/fail.php | 5 ----- tests/dbal/migration/if.php | 5 ----- tests/dbal/migration/recall.php | 5 ----- tests/dbal/migration/revert.php | 5 ----- tests/dbal/migration/revert_with_dependency.php | 2 +- tests/dbal/migration/unfulfillable.php | 2 +- 7 files changed, 3 insertions(+), 23 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index e542493f9f..0ac6e733a1 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -9,7 +9,7 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('installed_migration'); } diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php index 8b5c521e09..f88d8169f5 100644 --- a/tests/dbal/migration/fail.php +++ b/tests/dbal/migration/fail.php @@ -9,11 +9,6 @@ class phpbb_dbal_migration_fail extends phpbb_db_migration { - function depends_on() - { - return array(); - } - function update_schema() { return array( diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php index aa9a5dab87..83fe21bd21 100644 --- a/tests/dbal/migration/if.php +++ b/tests/dbal/migration/if.php @@ -9,11 +9,6 @@ class phpbb_dbal_migration_if extends phpbb_db_migration { - function depends_on() - { - return array(); - } - function update_schema() { return array(); diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php index 18d8b4a6d2..6c2f04bf08 100644 --- a/tests/dbal/migration/recall.php +++ b/tests/dbal/migration/recall.php @@ -9,11 +9,6 @@ class phpbb_dbal_migration_recall extends phpbb_db_migration { - function depends_on() - { - return array(); - } - function update_schema() { return array(); diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index 2bb23e31c2..ac01987cd4 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -9,11 +9,6 @@ class phpbb_dbal_migration_revert extends phpbb_db_migration { - function depends_on() - { - return array(); - } - function update_schema() { return array( diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php index f6820dbf3f..ca2c070e8c 100644 --- a/tests/dbal/migration/revert_with_dependency.php +++ b/tests/dbal/migration/revert_with_dependency.php @@ -9,7 +9,7 @@ class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('phpbb_dbal_migration_revert'); } diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php index 84136ffe6d..6d375e6880 100644 --- a/tests/dbal/migration/unfulfillable.php +++ b/tests/dbal/migration/unfulfillable.php @@ -9,7 +9,7 @@ class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration { - function depends_on() + static public function depends_on() { return array('installed_migration', 'phpbb_dbal_migration_dummy', 'non_existant_migration'); } -- cgit v1.2.1 From 26c16559c3496f5496ad6e83e55c40f03edda5bd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 13 Jan 2013 12:39:08 -0600 Subject: [feature/migrations] Function effectively_installed() in migrations Allows you to check if the migration is effectively installed (entirely optionall) This function is intended to help moving to migrations from a previous database updater, where some migrations may have been installed already even though they are not yet listed in the migrations table. PHPBB3-9737 --- tests/dbal/migration/installed.php | 30 ++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 21 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/dbal/migration/installed.php (limited to 'tests/dbal') diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php new file mode 100644 index 0000000000..01829f7a99 --- /dev/null +++ b/tests/dbal/migration/installed.php @@ -0,0 +1,30 @@ +fail('Revert did not remove test_column.'); } } + + public function test_installed() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_installed')); + + global $migrator_test_installed_failed; + $migrator_test_installed_failed = false; + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->migrator->migration_state('phpbb_dbal_migration_installed') !== false); + + if ($migrator_test_installed_failed) + { + $this->fail('Installed test failed'); + } + } } -- cgit v1.2.1 From 8415ae839cf699e043fe24ad91585dc419596ff8 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 11:37:58 -0600 Subject: [ticket/11386] Update tests with new constructors for ext.manager/migrator PHPBB3-11386 --- tests/dbal/migrator_test.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 9460e76f37..6fc08d51f8 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -44,7 +44,26 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $tools = array( new phpbb_db_migration_tool_config($this->config), ); - $this->migrator = new phpbb_db_migrator($this->config, $this->db, $this->db_tools, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', $tools); + + $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $this->db, + $this->config, + 'phpbb_ext', + dirname(__FILE__) . '/../../phpBB/', + '.php', + null + ); + $this->migrator = new phpbb_db_migrator( + $this->config, + $this->db, + $this->db_tools, + $this->extension_manager, + 'phpbb_migrations', + dirname(__FILE__) . '/../../phpBB/', + 'php', + 'phpbb_', $tools + ); } public function test_update() -- cgit v1.2.1 From 91be99822312d9a83ae4f6849eef864dfd47e4a1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 2 Mar 2013 15:17:51 -0600 Subject: [ticket/11386] Fix failing tests from constructor changes PHPBB3-11386 --- tests/dbal/migrator_test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 6fc08d51f8..b447a81cda 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -58,12 +58,13 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->config, $this->db, $this->db_tools, - $this->extension_manager, 'phpbb_migrations', dirname(__FILE__) . '/../../phpBB/', 'php', - 'phpbb_', $tools + 'phpbb_', + $tools ); + $this->migrator->set_extension_manager($this->extension_manager); } public function test_update() -- cgit v1.2.1 From e4f782819968ec44f1dd207dc9de7ec703826d29 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sun, 3 Mar 2013 19:54:22 -0600 Subject: [ticket/11386] Send list of migrations instead of using load_migrations Remove dependency of extension manager for migrator. Keeping load_migrations function for others to use if they desire but requiring the finder be sent to it in order to use it. PHPBB3-11386 --- tests/dbal/migrator_test.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index b447a81cda..89669b85ec 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -45,15 +45,6 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case new phpbb_db_migration_tool_config($this->config), ); - $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), - $this->db, - $this->config, - 'phpbb_ext', - dirname(__FILE__) . '/../../phpBB/', - '.php', - null - ); $this->migrator = new phpbb_db_migrator( $this->config, $this->db, @@ -64,7 +55,16 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'phpbb_', $tools ); - $this->migrator->set_extension_manager($this->extension_manager); + $this->extension_manager = new phpbb_extension_manager( + new phpbb_mock_container_builder(), + $this->db, + $this->config, + $this->migrator, + 'phpbb_ext', + dirname(__FILE__) . '/../../phpBB/', + '.php', + null + ); } public function test_update() -- cgit v1.2.1 From 2cd1c62403c290df13752579258b08ebf007e3fb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Mar 2013 10:19:28 +0100 Subject: [ticket/11443] Add _test suffix to migration test filenames PHPBB3-11443 --- tests/dbal/migrator_tool_module.php | 150 ------------------------- tests/dbal/migrator_tool_module_test.php | 150 +++++++++++++++++++++++++ tests/dbal/migrator_tool_permission.php | 159 --------------------------- tests/dbal/migrator_tool_permission_test.php | 159 +++++++++++++++++++++++++++ 4 files changed, 309 insertions(+), 309 deletions(-) delete mode 100644 tests/dbal/migrator_tool_module.php create mode 100644 tests/dbal/migrator_tool_module_test.php delete mode 100644 tests/dbal/migrator_tool_permission.php create mode 100644 tests/dbal/migrator_tool_permission_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php deleted file mode 100644 index 6937b6f8c5..0000000000 --- a/tests/dbal/migrator_tool_module.php +++ /dev/null @@ -1,150 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml'); - } - - public function setup() - { - // Need global $db, $user for delete_module function in acp_modules - global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; - - parent::setup(); - - // Force add_log function to not be used - $skip_add_log = true; - - $db = $this->db = $this->new_dbal(); - $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); - $user = $this->user = new phpbb_user(); - - $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); - } - - public function exists_data() - { - return array( - // Test the category - array( - '', - 'ACP_CAT', - true, - ), - array( - 0, - 'ACP_CAT', - true, - ), - - // Test the module - array( - '', - 'ACP_MODULE', - false, - ), - array( - false, - 'ACP_MODULE', - true, - ), - array( - 'ACP_CAT', - 'ACP_MODULE', - true, - ), - ); - } - - /** - * @dataProvider exists_data - */ - public function test_exists($parent, $module, $expected) - { - $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module)); - } - - public function test_add() - { - try - { - $this->tool->add('acp', 0, 'ACP_NEW_CAT'); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT')); - - // Should throw an exception when trying to add a module that already exists - try - { - $this->tool->add('acp', 0, 'ACP_NEW_CAT'); - $this->fail('Exception not thrown'); - } - catch (Exception $e) {} - - try - { - $this->tool->add('acp', 'ACP_NEW_CAT', array( - 'module_basename' => 'acp_new_module', - 'module_langname' => 'ACP_NEW_MODULE', - 'module_mode' => 'test', - 'module_auth' => '', - )); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE')); - } - - public function test_remove() - { - try - { - $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE'); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE')); - } - - public function test_reverse() - { - try - { - $this->tool->add('acp', 0, 'ACP_NEW_CAT'); - } - catch (Exception $e) - { - $this->fail($e); - } - - try - { - $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT'); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT')); - } -} diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php new file mode 100644 index 0000000000..6937b6f8c5 --- /dev/null +++ b/tests/dbal/migrator_tool_module_test.php @@ -0,0 +1,150 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml'); + } + + public function setup() + { + // Need global $db, $user for delete_module function in acp_modules + global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; + + parent::setup(); + + // Force add_log function to not be used + $skip_add_log = true; + + $db = $this->db = $this->new_dbal(); + $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); + $user = $this->user = new phpbb_user(); + + $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); + } + + public function exists_data() + { + return array( + // Test the category + array( + '', + 'ACP_CAT', + true, + ), + array( + 0, + 'ACP_CAT', + true, + ), + + // Test the module + array( + '', + 'ACP_MODULE', + false, + ), + array( + false, + 'ACP_MODULE', + true, + ), + array( + 'ACP_CAT', + 'ACP_MODULE', + true, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($parent, $module, $expected) + { + $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module)); + } + + public function test_add() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + + // Should throw an exception when trying to add a module that already exists + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + $this->fail('Exception not thrown'); + } + catch (Exception $e) {} + + try + { + $this->tool->add('acp', 'ACP_NEW_CAT', array( + 'module_basename' => 'acp_new_module', + 'module_langname' => 'ACP_NEW_MODULE', + 'module_mode' => 'test', + 'module_auth' => '', + )); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE')); + } + + public function test_remove() + { + try + { + $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE')); + } + + public function test_reverse() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + + try + { + $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + } +} diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php deleted file mode 100644 index 438ab2b28e..0000000000 --- a/tests/dbal/migrator_tool_permission.php +++ /dev/null @@ -1,159 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml'); - } - - public function setup() - { - // Global $db and $cache are needed in acp/auth.php constructor - global $phpbb_root_path, $phpEx, $db, $cache; - - parent::setup(); - - $db = $this->db = $this->new_dbal(); - $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); - $this->auth = new phpbb_auth(); - - $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); - } - - public function exists_data() - { - return array( - array( - 'global', - true, - true, - ), - array( - 'local', - false, - true, - ), - array( - 'both', - true, - true, - ), - array( - 'both', - false, - true, - ), - array( - 'does_not_exist', - true, - false, - ), - ); - } - - /** - * @dataProvider exists_data - */ - public function test_exists($auth_option, $global, $expected) - { - $this->assertEquals($expected, $this->tool->exists($auth_option, $global)); - } - - public function test_add() - { - try - { - $this->tool->add('new', true); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(true, $this->tool->exists('new', true)); - $this->assertEquals(false, $this->tool->exists('new', false)); - - try - { - $this->tool->add('new', false); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(true, $this->tool->exists('new', false)); - - // Should fail (duplicate) - try - { - $this->tool->add('new', true); - $this->fail('Did not throw exception on duplicate'); - } - catch (Exception $e) {} - } - - public function test_remove() - { - try - { - $this->tool->remove('global', true); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(false, $this->tool->exists('global', true)); - - try - { - $this->tool->remove('both', false); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(false, $this->tool->exists('both', false)); - - // Should fail (does not exist) - try - { - $this->tool->remove('new', true); - $this->fail('Did not throw exception on duplicate'); - } - catch (Exception $e) {} - } - - public function test_reverse() - { - try - { - $this->tool->reverse('remove', 'global_test', true); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertTrue($this->tool->exists('global_test', true)); - - try - { - $this->tool->reverse('add', 'global_test', true); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertFalse($this->tool->exists('global_test', true)); - } -} diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php new file mode 100644 index 0000000000..438ab2b28e --- /dev/null +++ b/tests/dbal/migrator_tool_permission_test.php @@ -0,0 +1,159 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml'); + } + + public function setup() + { + // Global $db and $cache are needed in acp/auth.php constructor + global $phpbb_root_path, $phpEx, $db, $cache; + + parent::setup(); + + $db = $this->db = $this->new_dbal(); + $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); + $this->auth = new phpbb_auth(); + + $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); + } + + public function exists_data() + { + return array( + array( + 'global', + true, + true, + ), + array( + 'local', + false, + true, + ), + array( + 'both', + true, + true, + ), + array( + 'both', + false, + true, + ), + array( + 'does_not_exist', + true, + false, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($auth_option, $global, $expected) + { + $this->assertEquals($expected, $this->tool->exists($auth_option, $global)); + } + + public function test_add() + { + try + { + $this->tool->add('new', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', true)); + $this->assertEquals(false, $this->tool->exists('new', false)); + + try + { + $this->tool->add('new', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', false)); + + // Should fail (duplicate) + try + { + $this->tool->add('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_remove() + { + try + { + $this->tool->remove('global', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('global', true)); + + try + { + $this->tool->remove('both', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('both', false)); + + // Should fail (does not exist) + try + { + $this->tool->remove('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_reverse() + { + try + { + $this->tool->reverse('remove', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertTrue($this->tool->exists('global_test', true)); + + try + { + $this->tool->reverse('add', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('global_test', true)); + } +} -- cgit v1.2.1 From 4168cfd7e6ae6a6bd2c6e16b330b9ea27c9cf4af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 16 Mar 2013 01:24:50 +0100 Subject: [ticket/11443] Fix Migrator Modules Tool by creating a phpbb_log object PHPBB3-11443 --- tests/dbal/migrator_tool_module_test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 6937b6f8c5..3303086b26 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -21,7 +21,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case public function setup() { // Need global $db, $user for delete_module function in acp_modules - global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; + global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user, $phpbb_log; parent::setup(); @@ -32,6 +32,11 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); $user = $this->user = new phpbb_user(); + $cache = new phpbb_mock_cache; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('phpbb_auth'); + $phpbb_log = new phpbb_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'); } -- cgit v1.2.1 From 8dd26dee8349a14abac00db6ad5039d7517bda57 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 11:45:45 +0100 Subject: [ticket/11469] Add some basic unit tests for phpbb_db_sql_insert_buffer PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 176 ++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 tests/dbal/sql_insert_buffer_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php new file mode 100644 index 0000000000..a67ccbe89f --- /dev/null +++ b/tests/dbal/sql_insert_buffer_test.php @@ -0,0 +1,176 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function insert_buffer_data() + { + $db = $this->new_dbal(); + + if ($db->multi_insert) + { + // Test with enabled and disabled multi_insert + return array( + array(true), + array(false), + ); + } + else + { + // Only test with disabled multi_insert, the DB doesn't support it + return array( + array(false), + ); + } + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_and_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + // This call can be buffered + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + if ($db->multi_insert) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + else + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(3, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + // Manually flush + $buffer->flush(); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(3, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_with_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + // This call flushes the values + $buffer->insert(array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + )); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(4, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_all_and_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + $buffer->insert_all(array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + )); + + if ($db->multi_insert) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(4, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + // Manually flush + $buffer->flush(); + } + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(5, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } +} -- cgit v1.2.1 From af9f30cd52fd7b53b17b946a0c646fd72c4a6f4f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 14:09:04 +0100 Subject: [ticket/11469] Use method to check config count, instead of repeating it PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 63 ++++++++++------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index a67ccbe89f..e3ee767937 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -14,6 +14,15 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } + protected function assert_config_count($db, $num_configs) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query($sql); + $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + public function insert_buffer_data() { $db = $this->new_dbal(); @@ -45,11 +54,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); // This call can be buffered $buffer->insert(array( @@ -60,29 +65,17 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case if ($db->multi_insert) { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); } else { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(3, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 3); } // Manually flush $buffer->flush(); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(3, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 3); } /** @@ -95,11 +88,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); $buffer->insert(array( 'config_name' => 'name1', @@ -114,11 +103,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'is_dynamic' => '0', )); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(4, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 4); } /** @@ -131,11 +116,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); $buffer->insert_all(array( array( @@ -157,20 +138,12 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case if ($db->multi_insert) { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(4, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 4); // Manually flush $buffer->flush(); } - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(5, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 5); } } -- cgit v1.2.1 From 9606ccc2021e7e169473d92306e28680e4b9f966 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 20:54:20 +0100 Subject: [ticket/11469] Split tests and skip multi_insert if unavailable PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 139 +++++++++++++++++++++++----------- 1 file changed, 95 insertions(+), 44 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index e3ee767937..bdf3544bbc 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -23,34 +23,38 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public function insert_buffer_data() + public function test_multi_insert_disabled_insert_and_flush() { $db = $this->new_dbal(); + $db->multi_insert = false; - if ($db->multi_insert) - { - // Test with enabled and disabled multi_insert - return array( - array(true), - array(false), - ); - } - else - { - // Only test with disabled multi_insert, the DB doesn't support it - return array( - array(false), - ); - } + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + // This call can be buffered + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + $this->assert_config_count($db, 3); + + // Manually flush + $buffer->flush(); + + $this->assert_config_count($db, 3); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_and_flush($force_multi_insert) + public function test_multi_insert_enabled_insert_and_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -63,14 +67,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'is_dynamic' => '0', )); - if ($db->multi_insert) - { - $this->assert_config_count($db, 2); - } - else - { - $this->assert_config_count($db, 3); - } + $this->assert_config_count($db, 2); // Manually flush $buffer->flush(); @@ -78,13 +75,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 3); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_with_flush($force_multi_insert) + public function test_multi_insert_disabled_insert_with_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + $db->multi_insert = false; $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -106,13 +100,39 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 4); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_all_and_flush($force_multi_insert) + public function test_multi_insert_enabled_insert_with_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + // This call flushes the values + $buffer->insert(array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + )); + + $this->assert_config_count($db, 4); + } + + public function test_multi_insert_disabled_insert_all_and_flush() + { + $db = $this->new_dbal(); + $db->multi_insert = false; $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -136,14 +156,45 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case ), )); - if ($db->multi_insert) - { - $this->assert_config_count($db, 4); + $this->assert_config_count($db, 5); + } + + public function test_multi_insert_enabled_insert_all_and_flush() + { + $db = $this->new_dbal(); - // Manually flush - $buffer->flush(); + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); } + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + $buffer->insert_all(array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + )); + + $this->assert_config_count($db, 4); + + // Manually flush + $buffer->flush(); + $this->assert_config_count($db, 5); } } -- cgit v1.2.1 From 69ad4aab787db4c80c431c412a76d731a1abdf63 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 20:55:08 +0100 Subject: [ticket/11469] Check return values of the functions PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bdf3544bbc..fd92ca9bba 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -33,16 +33,16 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 3); // Manually flush - $buffer->flush(); + $this->assertFalse($buffer->flush()); $this->assert_config_count($db, 3); } @@ -61,16 +61,16 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $buffer->insert(array( + $this->assertFalse($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 2); // Manually flush - $buffer->flush(); + $this->assertTrue($buffer->flush()); $this->assert_config_count($db, 3); } @@ -84,18 +84,18 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); // This call flushes the values - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name2', 'config_value' => 'value2', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 4); } @@ -113,18 +113,18 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert(array( + $this->assertFalse($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); // This call flushes the values - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name2', 'config_value' => 'value2', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 4); } @@ -138,7 +138,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert_all(array( + $this->assertTrue($buffer->insert_all(array( array( 'config_name' => 'name1', 'config_value' => 'value1', @@ -154,7 +154,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'config_value' => 'value3', 'is_dynamic' => '0', ), - )); + ))); $this->assert_config_count($db, 5); } @@ -172,7 +172,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert_all(array( + $this->assertTrue($buffer->insert_all(array( array( 'config_name' => 'name1', 'config_value' => 'value1', @@ -188,12 +188,12 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'config_value' => 'value3', 'is_dynamic' => '0', ), - )); + ))); $this->assert_config_count($db, 4); // Manually flush - $buffer->flush(); + $this->assertTrue($buffer->flush()); $this->assert_config_count($db, 5); } -- cgit v1.2.1 From a534497d82cb9febaa18ee6c858ef68217bc2d14 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:21:29 +0100 Subject: [ticket/11469] Move protected method to end of test file. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index fd92ca9bba..0cf476b14a 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -14,15 +14,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } - protected function assert_config_count($db, $num_configs) - { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query($sql); - $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); - } - public function test_multi_insert_disabled_insert_and_flush() { $db = $this->new_dbal(); @@ -197,4 +188,13 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 5); } + + protected function assert_config_count($db, $num_configs) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query($sql); + $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } } -- cgit v1.2.1 From 873f098b6ccc108dc293054f2cf7cb7231684caa Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:30:23 +0100 Subject: [ticket/11469] Do not repeat array with three rows. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 57 ++++++++++++++--------------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 0cf476b14a..59bfb73d0f 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -129,23 +129,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert_all(array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), - ))); + $this->assertTrue($buffer->insert_all($this->get_three_rows())); $this->assert_config_count($db, 5); } @@ -163,23 +147,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert_all(array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), - ))); + $this->assertTrue($buffer->insert_all($this->get_three_rows())); $this->assert_config_count($db, 4); @@ -197,4 +165,25 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); $db->sql_freeresult($result); } + + protected function get_three_rows() + { + return array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + ); + } } -- cgit v1.2.1 From b88eb3c8e099e1a0634ab84e9e1c215c00410264 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:33:13 +0100 Subject: [ticket/11469] Do not repeat row generation. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 63 ++++++++++------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 59bfb73d0f..650a42c36d 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -24,11 +24,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(1))); $this->assert_config_count($db, 3); @@ -52,11 +48,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $this->assertFalse($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertFalse($buffer->insert($this->get_row(1))); $this->assert_config_count($db, 2); @@ -75,18 +67,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(2))); $this->assert_config_count($db, 4); } @@ -104,18 +88,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertFalse($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertFalse($buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(2))); $this->assert_config_count($db, 4); } @@ -166,24 +142,21 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $db->sql_freeresult($result); } + protected function get_row($rownum) + { + return array( + 'config_name' => "name$rownum", + 'config_value' => "value$rownum", + 'is_dynamic' => '0', + ); + } + protected function get_three_rows() { return array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), + $this->get_row(1), + $this->get_row(2), + $this->get_row(3), ); } } -- cgit v1.2.1 From b48c4d9549acaff8bbe7846b2390267ccd36d39a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:45:10 +0100 Subject: [ticket/11469] Use setUp() to setup DB and a buffer with size 2. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 104 +++++++++++++++------------------- 1 file changed, 47 insertions(+), 57 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 650a42c36d..bc6508b30a 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -9,6 +9,17 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { + protected $db; + protected $buffer; + + public function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2); + } + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); @@ -16,130 +27,109 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_and_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; - - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->db->multi_insert = false; - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // This call can be buffered - $this->assertTrue($buffer->insert($this->get_row(1))); + $this->assertTrue($this->buffer->insert($this->get_row(1))); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); // Manually flush - $this->assertFalse($buffer->flush()); + $this->assertFalse($this->buffer->flush()); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); } public function test_multi_insert_enabled_insert_and_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // This call can be buffered - $this->assertFalse($buffer->insert($this->get_row(1))); + $this->assertFalse($this->buffer->insert($this->get_row(1))); - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // Manually flush - $this->assertTrue($buffer->flush()); + $this->assertTrue($this->buffer->flush()); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); } public function test_multi_insert_disabled_insert_with_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; - - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->db->multi_insert = false; - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertTrue($buffer->insert($this->get_row(1))); + $this->assertTrue($this->buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert($this->get_row(2))); + $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); } public function test_multi_insert_enabled_insert_with_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertFalse($buffer->insert($this->get_row(1))); + $this->assertFalse($this->buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert($this->get_row(2))); + $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); } public function test_multi_insert_disabled_insert_all_and_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; + $this->db->multi_insert = false; - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->assert_config_count(2); - $this->assert_config_count($db, 2); + $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); - $this->assertTrue($buffer->insert_all($this->get_three_rows())); - - $this->assert_config_count($db, 5); + $this->assert_config_count(5); } public function test_multi_insert_enabled_insert_all_and_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertTrue($buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); // Manually flush - $this->assertTrue($buffer->flush()); + $this->assertTrue($this->buffer->flush()); - $this->assert_config_count($db, 5); + $this->assert_config_count(5); } - protected function assert_config_count($db, $num_configs) + protected function assert_config_count($num_configs) { $sql = 'SELECT COUNT(*) AS num_configs FROM phpbb_config'; - $result = $db->sql_query($sql); - $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs')); + $this->db->sql_freeresult($result); } protected function get_row($rownum) -- cgit v1.2.1 From c909d9602b8a8d91d9c6cd72e01c1ddf21dcf593 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:46:39 +0100 Subject: [ticket/11469] Do not repeat assert_config_count(2). Also move to setUp(). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bc6508b30a..4aad852149 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -18,6 +18,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2); + $this->assert_config_count(2); } public function getDataSet() @@ -29,8 +30,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - // This call can be buffered $this->assertTrue($this->buffer->insert($this->get_row(1))); @@ -49,8 +48,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -66,8 +63,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert($this->get_row(1))); // This call flushes the values @@ -83,8 +78,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - $this->assertFalse($this->buffer->insert($this->get_row(1))); // This call flushes the values @@ -97,8 +90,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); $this->assert_config_count(5); @@ -111,8 +102,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); $this->assert_config_count(4); -- cgit v1.2.1 From eacd0f3e7d200924a1d98d1ce34a454eda707dd4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:48:48 +0100 Subject: [ticket/11469] Fix spacing in getDataSet(). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 4aad852149..bd03fb9c05 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -23,7 +23,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } public function test_multi_insert_disabled_insert_and_flush() -- cgit v1.2.1 From 6f946e2188d08bdc939e56143bff9e663c0b6931 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:53:03 +0100 Subject: [ticket/11469] Refactor get_three_rows() into get_rows($n). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bd03fb9c05..f06df26b0c 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -90,7 +90,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); $this->assert_config_count(5); } @@ -102,7 +102,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); $this->assert_config_count(4); @@ -130,12 +130,13 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case ); } - protected function get_three_rows() + protected function get_rows($n) { - return array( - $this->get_row(1), - $this->get_row(2), - $this->get_row(3), - ); + $result = array(); + for ($i = 0; $i < $n; ++$i) + { + $result[] = $this->get_row($i); + } + return $result; } } -- cgit v1.2.1 From a04fe625a86c0b1fcc037687afec39c659fbd830 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:55:26 +0100 Subject: [ticket/11469] Do not repeat markTestSkipped() message. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index f06df26b0c..9357278a62 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -43,10 +43,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_and_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -73,10 +70,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_with_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -97,10 +91,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_all_and_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); @@ -121,6 +112,14 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->db->sql_freeresult($result); } + protected function check_multi_insert_support() + { + if (!$this->db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } + } + protected function get_row($rownum) { return array( -- cgit v1.2.1 From e022a7e8f602de67472e4ea5b6ecb6280f4054e4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Mar 2013 00:03:48 +0100 Subject: [ticket/11469] Remove comments. Method names should be good enough now. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 9357278a62..04ef6a3d52 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -29,77 +29,50 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_and_flush() { $this->db->multi_insert = false; - - // This call can be buffered $this->assertTrue($this->buffer->insert($this->get_row(1))); - $this->assert_config_count(3); - - // Manually flush $this->assertFalse($this->buffer->flush()); - $this->assert_config_count(3); } public function test_multi_insert_enabled_insert_and_flush() { $this->check_multi_insert_support(); - - // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); - $this->assert_config_count(2); - - // Manually flush $this->assertTrue($this->buffer->flush()); - $this->assert_config_count(3); } public function test_multi_insert_disabled_insert_with_flush() { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert($this->get_row(1))); - - // This call flushes the values $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count(4); } public function test_multi_insert_enabled_insert_with_flush() { $this->check_multi_insert_support(); - $this->assertFalse($this->buffer->insert($this->get_row(1))); - - // This call flushes the values $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count(4); } public function test_multi_insert_disabled_insert_all_and_flush() { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); - $this->assert_config_count(5); } public function test_multi_insert_enabled_insert_all_and_flush() { $this->check_multi_insert_support(); - $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); - $this->assert_config_count(4); - - // Manually flush $this->assertTrue($this->buffer->flush()); - $this->assert_config_count(5); } -- cgit v1.2.1 From e3a6935de6185bde189e53452fca024ef9474c1b Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Mar 2013 00:20:24 +0100 Subject: [ticket/11469] Add more table status assertions. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 04ef6a3d52..45339a6b50 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -48,6 +48,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; $this->assertTrue($this->buffer->insert($this->get_row(1))); + $this->assert_config_count(3); $this->assertTrue($this->buffer->insert($this->get_row(2))); $this->assert_config_count(4); } @@ -56,6 +57,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->check_multi_insert_support(); $this->assertFalse($this->buffer->insert($this->get_row(1))); + $this->assert_config_count(2); $this->assertTrue($this->buffer->insert($this->get_row(2))); $this->assert_config_count(4); } -- cgit v1.2.1 From 423b310e2acbbc72814a4278a4cccf2900114f85 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Apr 2013 18:43:19 +0200 Subject: [ticket/11362] Extension manager depends on filesystem PHPBB3-11362 --- tests/dbal/migrator_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 89669b85ec..745d260b38 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -60,6 +60,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->db, $this->config, $this->migrator, + new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', '.php', -- cgit v1.2.1 From 845832820ba89a0f33e264a34639a05045783397 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 01:48:31 +0200 Subject: [ticket/11501] Assert the variables instead of fail() with the condition PHPBB3-11501 --- tests/dbal/migrator_test.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 89669b85ec..0d7fc2f839 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -144,15 +144,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator->update(); } - if ($migrator_test_if_true_failed) - { - $this->fail('True test failed'); - } - - if ($migrator_test_if_false_failed) - { - $this->fail('False test failed'); - } + $this->assertFalse($migrator_test_if_true_failed, 'True test failed'); + $this->assertFalse($migrator_test_if_false_failed, 'False test failed'); } public function test_recall() -- cgit v1.2.1 From df518ac131bb022aa14c207e0c1408751dd9e1ef Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 24 Apr 2013 17:27:24 -0500 Subject: [ticket/11335] (tests) Make php_ext 'php' not '.php' PHPBB3-11335 --- tests/dbal/migrator_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index ae4099e6f8..6390d6a715 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -63,7 +63,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', - '.php', + 'php', null ); } -- cgit v1.2.1 From 60e32728393d4258f92f7893f8275889278a995f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 1 May 2013 14:09:08 -0500 Subject: [ticket/11415] Remove migrator dependency from extension manager PHPBB3-11415 --- tests/dbal/migrator_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 6390d6a715..5fc05f2119 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -55,8 +55,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'phpbb_', $tools ); + + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $this->db, $this->config, $this->migrator, -- cgit v1.2.1 From 1b34ddb330d1a666185947ec2325732466f9ce4e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 3 May 2013 09:02:50 -0500 Subject: [ticket/11415] Fix ext.manager constructor in tests PHPBB3-11415 --- tests/dbal/migrator_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 5fc05f2119..1e40c9c6d6 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -63,7 +63,6 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, - $this->migrator, new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', -- cgit v1.2.1 From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- tests/dbal/migrator_test.php | 2 -- tests/dbal/migrator_tool_config_test.php | 3 --- tests/dbal/migrator_tool_module_test.php | 2 -- tests/dbal/migrator_tool_permission_test.php | 2 -- 4 files changed, 9 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 1e40c9c6d6..07eb666e93 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -8,8 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migrator.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/migration.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; require_once dirname(__FILE__) . '/migration/dummy.php'; diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index 7d582f230b..b82d1ef48d 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -7,9 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/config.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; - class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case { public function setup() diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 3303086b26..828fb76c65 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -8,8 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/module.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case { diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 438ab2b28e..79d9db66da 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -8,8 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/tool/permission.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/migration/exception.php'; class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case { -- cgit v1.2.1 From 057d860d07fe829104aa938338830787415bc1c6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 14 Jul 2013 00:56:37 -0400 Subject: [ticket/11696] Rename db_tools.php so it can be autoloaded PHPBB3-11696 --- tests/dbal/auto_increment_test.php | 1 - tests/dbal/db_tools_test.php | 1 - tests/dbal/migrator_test.php | 2 -- 3 files changed, 4 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index e87fc1c6bd..077bfad933 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; class phpbb_dbal_auto_increment_test extends phpbb_database_test_case { diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index c20e46011f..7bdbc696e7 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -8,7 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; class phpbb_dbal_db_tools_test extends phpbb_database_test_case { diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 07eb666e93..9e55e4dd35 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -8,8 +8,6 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; - require_once dirname(__FILE__) . '/migration/dummy.php'; require_once dirname(__FILE__) . '/migration/unfulfillable.php'; require_once dirname(__FILE__) . '/migration/if.php'; -- cgit v1.2.1 From f30b87519e9ead41525e1979cbce874e8a84e2b8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 9 Sep 2013 17:28:56 -0500 Subject: [ticket/11832] Inject dependencies for phpbb_get_web_root_path (also moving) Function moved from phpbb_get_web_root_path to filesystem::get_web_root_path PHPBB3-11832 --- tests/dbal/migrator_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 9e55e4dd35..4be1fbe176 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -59,7 +59,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, - new phpbb_filesystem(), + new phpbb_filesystem(dirname(__FILE__) . '/../../phpBB/'), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', -- cgit v1.2.1 From 21624e79fc512fd86177080010bb7d26c71ce3cb Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 13 Sep 2013 10:04:35 -0500 Subject: [ticket/11832] Fix constructions of phpbb_filesystem PHPBB3-11832 --- tests/dbal/migrator_test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 4be1fbe176..5f0818d568 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -59,7 +59,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, - new phpbb_filesystem(dirname(__FILE__) . '/../../phpBB/'), + new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + dirname(__FILE__) . '/../../phpBB/' + ), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', -- cgit v1.2.1 From b4a374dc73eda55db1c67b87bd65a73f79411ef5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 13 Sep 2013 10:58:03 -0500 Subject: [ticket/11832] Fix INCLUDE(JS/CSS) PHPBB3-11832 --- tests/dbal/migrator_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 5f0818d568..d722439b3f 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -63,7 +63,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case new phpbb_symfony_request( new phpbb_mock_request() ), - dirname(__FILE__) . '/../../phpBB/' + dirname(__FILE__) . '/../../phpBB/', + 'php' ), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', -- cgit v1.2.1 From b95fdacdd378877d277e261465da73deb06e50da Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:01:09 +0200 Subject: [ticket/11700] Move all recent code to namespaces PHPBB3-11700 --- tests/dbal/auto_increment_test.php | 2 +- tests/dbal/case_test.php | 12 +++++------ tests/dbal/concatenate_test.php | 4 ++-- tests/dbal/db_tools_test.php | 6 +++--- tests/dbal/migration/dummy.php | 4 ++-- tests/dbal/migration/fail.php | 2 +- tests/dbal/migration/if.php | 2 +- tests/dbal/migration/installed.php | 2 +- tests/dbal/migration/recall.php | 2 +- tests/dbal/migration/revert.php | 6 +++--- tests/dbal/migration/revert_with_dependency.php | 2 +- tests/dbal/migration/unfulfillable.php | 2 +- tests/dbal/migrator_test.php | 28 ++++++++++++------------- tests/dbal/migrator_tool_config_test.php | 4 ++-- tests/dbal/migrator_tool_module_test.php | 10 ++++----- tests/dbal/migrator_tool_permission_test.php | 6 +++--- tests/dbal/schema_test.php | 4 ++-- tests/dbal/sql_insert_buffer_test.php | 4 ++-- tests/dbal/write_test.php | 18 ++++++++-------- 19 files changed, 60 insertions(+), 60 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index 077bfad933..2196292e83 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -26,7 +26,7 @@ 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); + $this->tools = new \phpbb\db\tools($this->db); $this->table_data = array( 'COLUMNS' => array( diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index 57a1729a39..edab3525a1 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -19,13 +19,13 @@ class phpbb_dbal_case_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num - FROM phpbb_config'; + FROM \phpbb\config\config'; $result = $db->sql_query_limit($sql, 1); $this->assertEquals(1, (int) $db->sql_fetchfield('test_num')); $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num - FROM phpbb_config'; + FROM \phpbb\config\config'; $result = $db->sql_query_limit($sql, 1); $this->assertEquals(2, (int) $db->sql_fetchfield('test_num')); @@ -36,13 +36,13 @@ class phpbb_dbal_case_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string - FROM phpbb_config'; + FROM \phpbb\config\config'; $result = $db->sql_query_limit($sql, 1); $this->assertEquals('foo', $db->sql_fetchfield('test_string')); $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string - FROM phpbb_config'; + FROM \phpbb\config\config'; $result = $db->sql_query_limit($sql, 1); $this->assertEquals('bar', $db->sql_fetchfield('test_string')); @@ -53,14 +53,14 @@ class phpbb_dbal_case_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string - FROM phpbb_config + FROM \phpbb\config\config WHERE config_name = 'config1'"; $result = $db->sql_query_limit($sql, 1); $this->assertEquals('config1', $db->sql_fetchfield('test_string')); $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string - FROM phpbb_config + FROM \phpbb\config\config WHERE config_value = 'bar'"; $result = $db->sql_query_limit($sql, 1); diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php index 0891fa58a0..818bde7d23 100644 --- a/tests/dbal/concatenate_test.php +++ b/tests/dbal/concatenate_test.php @@ -19,7 +19,7 @@ class phpbb_dbal_concatenate_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string - FROM phpbb_config'; + FROM \phpbb\config\config'; $result = $db->sql_query($sql); $db->sql_return_on_error(false); @@ -43,7 +43,7 @@ class phpbb_dbal_concatenate_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string - FROM phpbb_config'; + FROM \phpbb\config\config'; $result = $db->sql_query($sql); $db->sql_return_on_error(false); diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 7bdbc696e7..e25335165a 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -26,7 +26,7 @@ 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); + $this->tools = new \phpbb\db\tools($this->db); $this->table_data = array( 'COLUMNS' => array( @@ -254,7 +254,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case public function test_peform_schema_changes_drop_tables() { - $db_tools = $this->getMock('phpbb_db_tools', array( + $db_tools = $this->getMock('\phpbb\db\tools', array( 'sql_table_exists', 'sql_table_drop', ), array(&$this->db)); @@ -280,7 +280,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case public function test_peform_schema_changes_drop_columns() { - $db_tools = $this->getMock('phpbb_db_tools', array( + $db_tools = $this->getMock('\phpbb\db\tools', array( 'sql_column_exists', 'sql_column_remove', ), array(&$this->db)); diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index 0ac6e733a1..3f48f22252 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_dummy extends phpbb_db_migration +class phpbb_dbal_migration_dummy extends \phpbb\db\migration\migration { static public function depends_on() { @@ -18,7 +18,7 @@ class phpbb_dbal_migration_dummy extends phpbb_db_migration { return array( 'add_columns' => array( - 'phpbb_config' => array( + '\phpbb\config\config' => array( 'extra_column' => array('UINT', 1), ), ), diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php index f88d8169f5..d90972720d 100644 --- a/tests/dbal/migration/fail.php +++ b/tests/dbal/migration/fail.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_fail extends phpbb_db_migration +class phpbb_dbal_migration_fail extends \phpbb\db\migration\migration { function update_schema() { diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php index 83fe21bd21..bbbda60ea3 100644 --- a/tests/dbal/migration/if.php +++ b/tests/dbal/migration/if.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_if extends phpbb_db_migration +class phpbb_dbal_migration_if extends \phpbb\db\migration\migration { function update_schema() { diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php index 01829f7a99..4b86896d9c 100644 --- a/tests/dbal/migration/installed.php +++ b/tests/dbal/migration/installed.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_installed extends phpbb_db_migration +class phpbb_dbal_migration_installed extends \phpbb\db\migration\migration { function effectively_installed() { diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php index 6c2f04bf08..041d12ad27 100644 --- a/tests/dbal/migration/recall.php +++ b/tests/dbal/migration/recall.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_recall extends phpbb_db_migration +class phpbb_dbal_migration_recall extends \phpbb\db\migration\migration { function update_schema() { diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index ac01987cd4..c46dfca30d 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -7,13 +7,13 @@ * */ -class phpbb_dbal_migration_revert extends phpbb_db_migration +class phpbb_dbal_migration_revert extends \phpbb\db\migration\migration { function update_schema() { return array( 'add_columns' => array( - 'phpbb_config' => array( + '\phpbb\config\config' => array( 'bar_column' => array('UINT', 1), ), ), @@ -24,7 +24,7 @@ class phpbb_dbal_migration_revert extends phpbb_db_migration { return array( 'drop_columns' => array( - 'phpbb_config' => array( + '\phpbb\config\config' => array( 'bar_column', ), ), diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php index ca2c070e8c..0b09fb784d 100644 --- a/tests/dbal/migration/revert_with_dependency.php +++ b/tests/dbal/migration/revert_with_dependency.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_revert_with_dependency extends phpbb_db_migration +class phpbb_dbal_migration_revert_with_dependency extends \phpbb\db\migration\migration { static public function depends_on() { diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php index 6d375e6880..a1cdef9a23 100644 --- a/tests/dbal/migration/unfulfillable.php +++ b/tests/dbal/migration/unfulfillable.php @@ -7,7 +7,7 @@ * */ -class phpbb_dbal_migration_unfulfillable extends phpbb_db_migration +class phpbb_dbal_migration_unfulfillable extends \phpbb\db\migration\migration { static public function depends_on() { diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 9e55e4dd35..d336854a1c 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -33,15 +33,15 @@ 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); + $this->db_tools = new \phpbb\db\tools($this->db); - $this->config = new phpbb_config_db($this->db, new phpbb_mock_cache, 'phpbb_config'); + $this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, '\phpbb\config\config'); $tools = array( - new phpbb_db_migration_tool_config($this->config), + new \phpbb\db\migration\tool\config($this->config), ); - $this->migrator = new phpbb_db_migrator( + $this->migrator = new \phpbb\db\migrator( $this->config, $this->db, $this->db_tools, @@ -55,11 +55,11 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); - $this->extension_manager = new phpbb_extension_manager( + $this->extension_manager = new \phpbb\extension\manager( $container, $this->db, $this->config, - new phpbb_filesystem(), + new \phpbb\filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', @@ -91,7 +91,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('extra_column' => '1')), - "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", + "SELECT extra_column FROM \phpbb\config\config WHERE config_name = 'foo'", 'Dummy migration created extra_column with value 1 in all rows.' ); @@ -107,7 +107,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case ); // cleanup - $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + $this->db_tools->sql_column_remove('\phpbb\config\config', 'extra_column'); } public function test_unfulfillable() @@ -123,11 +123,11 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('extra_column' => '1')), - "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", + "SELECT extra_column FROM \phpbb\config\config WHERE config_name = 'foo'", 'Dummy migration was run, even though an unfulfillable migration was found.' ); - $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); + $this->db_tools->sql_column_remove('\phpbb\config\config', 'extra_column'); } public function test_if() @@ -192,7 +192,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('bar_column' => '1')), - "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", + "SELECT bar_column FROM \phpbb\config\config WHERE config_name = 'foo'", 'Installing revert migration failed to create bar_column.' ); @@ -208,7 +208,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertFalse(isset($this->config['foobartest'])); - $sql = 'SELECT * FROM phpbb_config'; + $sql = 'SELECT * FROM \phpbb\config\config'; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); @@ -232,12 +232,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator->update(); } } - catch (phpbb_db_migration_exception $e) {} + catch (\phpbb\db\migration\exception $e) {} // Failure should have caused an automatic roll-back, so this should not exist. $this->assertFalse(isset($this->config['foobar3'])); - $sql = 'SELECT * FROM phpbb_config'; + $sql = 'SELECT * FROM \phpbb\config\config'; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index b82d1ef48d..a8d8966839 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -11,9 +11,9 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case { public function setup() { - $this->config = new phpbb_config(array()); + $this->config = new \phpbb\config\config(array()); - $this->tool = new phpbb_db_migration_tool_config($this->config); + $this->tool = new \phpbb\db\migration\tool\config($this->config); parent::setup(); } diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 828fb76c65..3c23891348 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -27,15 +27,15 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $skip_add_log = true; $db = $this->db = $this->new_dbal(); - $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); - $user = $this->user = new phpbb_user(); + $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(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $auth = $this->getMock('phpbb_auth'); - $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $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'); + $this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); } public function exists_data() diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 79d9db66da..1090b4726a 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -24,10 +24,10 @@ 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(array()), $this->db, $phpbb_root_path, $phpEx); - $this->auth = new phpbb_auth(); + $cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), 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); + $this->tool = new \phpbb\db\migration\tool\permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); } public function exists_data() diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php index 2a332fddba..a09daa0f76 100644 --- a/tests/dbal/schema_test.php +++ b/tests/dbal/schema_test.php @@ -21,13 +21,13 @@ class phpbb_dbal_schema_test extends phpbb_database_test_case $db = $this->new_dbal(); $value = str_repeat("\xC3\x84", 255); - $sql = "INSERT INTO phpbb_config + $sql = "INSERT INTO \phpbb\config\config (config_name, config_value) VALUES ('name', '$value')"; $result = $db->sql_query($sql); $sql = "SELECT config_value - FROM phpbb_config + FROM \phpbb\config\config WHERE config_name = 'name'"; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 45339a6b50..976495d195 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -17,7 +17,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2); + $this->buffer = new \phpbb\db\sql_insert_buffer($this->db, '\phpbb\config\config', 2); $this->assert_config_count(2); } @@ -81,7 +81,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case protected function assert_config_count($num_configs) { $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; + FROM \phpbb\config\config'; $result = $this->db->sql_query($sql); $this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs')); $this->db->sql_freeresult($result); diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php index 987161a831..c0f0c271d2 100644 --- a/tests/dbal/write_test.php +++ b/tests/dbal/write_test.php @@ -39,11 +39,11 @@ class phpbb_dbal_write_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = 'INSERT INTO phpbb_config ' . $db->sql_build_array('INSERT', $sql_ary); + $sql = 'INSERT INTO \phpbb\config\config ' . $db->sql_build_array('INSERT', $sql_ary); $result = $db->sql_query($sql); $sql = "SELECT * - FROM phpbb_config + FROM \phpbb\config\config WHERE config_name = '" . $sql_ary['config_name'] . "'"; $result = $db->sql_query_limit($sql, 1); @@ -56,12 +56,12 @@ class phpbb_dbal_write_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = "DELETE FROM phpbb_config + $sql = "DELETE FROM \phpbb\config\config WHERE config_name = 'config1'"; $result = $db->sql_query($sql); $sql = 'SELECT * - FROM phpbb_config'; + FROM \phpbb\config\config'; $result = $db->sql_query($sql); $rows = $db->sql_fetchrowset($result); @@ -76,7 +76,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case $db = $this->new_dbal(); // empty the table - $sql = 'DELETE FROM phpbb_config'; + $sql = 'DELETE FROM \phpbb\config\config'; $db->sql_query($sql); $batch_ary = array( @@ -92,10 +92,10 @@ class phpbb_dbal_write_test extends phpbb_database_test_case ), ); - $result = $db->sql_multi_insert('phpbb_config', $batch_ary); + $result = $db->sql_multi_insert('\phpbb\config\config', $batch_ary); $sql = 'SELECT * - FROM phpbb_config + FROM \phpbb\config\config ORDER BY config_name ASC'; $result = $db->sql_query($sql); @@ -155,12 +155,12 @@ class phpbb_dbal_write_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = 'UPDATE phpbb_config + $sql = 'UPDATE \phpbb\config\config SET ' . $db->sql_build_array('UPDATE', $sql_ary) . $where; $result = $db->sql_query($sql); $sql = 'SELECT * - FROM phpbb_config + FROM \phpbb\config\config ORDER BY config_name ASC'; $result = $db->sql_query($sql); -- cgit v1.2.1 From 97012dd85151018e003aa8abf793ad04206a5627 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:52:07 +0200 Subject: [ticket/11700] Fix dbal tests after config namespace mishap PHPBB3-11700 --- tests/dbal/case_test.php | 12 ++++++------ tests/dbal/concatenate_test.php | 4 ++-- tests/dbal/migration/dummy.php | 2 +- tests/dbal/migration/revert.php | 4 ++-- tests/dbal/migrator_test.php | 16 ++++++++-------- tests/dbal/schema_test.php | 4 ++-- tests/dbal/sql_insert_buffer_test.php | 4 ++-- tests/dbal/write_test.php | 20 ++++++++++---------- 8 files changed, 33 insertions(+), 33 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index edab3525a1..57a1729a39 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -19,13 +19,13 @@ class phpbb_dbal_case_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT ' . $db->sql_case('1 = 1', '1', '2') . ' AS test_num - FROM \phpbb\config\config'; + FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); $this->assertEquals(1, (int) $db->sql_fetchfield('test_num')); $sql = 'SELECT ' . $db->sql_case('1 = 0', '1', '2') . ' AS test_num - FROM \phpbb\config\config'; + FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); $this->assertEquals(2, (int) $db->sql_fetchfield('test_num')); @@ -36,13 +36,13 @@ class phpbb_dbal_case_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT ' . $db->sql_case('1 = 1', "'foo'", "'bar'") . ' AS test_string - FROM \phpbb\config\config'; + FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); $this->assertEquals('foo', $db->sql_fetchfield('test_string')); $sql = 'SELECT ' . $db->sql_case('1 = 0', "'foo'", "'bar'") . ' AS test_string - FROM \phpbb\config\config'; + FROM phpbb_config'; $result = $db->sql_query_limit($sql, 1); $this->assertEquals('bar', $db->sql_fetchfield('test_string')); @@ -53,14 +53,14 @@ class phpbb_dbal_case_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string - FROM \phpbb\config\config + FROM phpbb_config WHERE config_name = 'config1'"; $result = $db->sql_query_limit($sql, 1); $this->assertEquals('config1', $db->sql_fetchfield('test_string')); $sql = 'SELECT ' . $db->sql_case("config_name = 'config1'", 'config_name', 'config_value') . " AS test_string - FROM \phpbb\config\config + FROM phpbb_config WHERE config_value = 'bar'"; $result = $db->sql_query_limit($sql, 1); diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php index 818bde7d23..0891fa58a0 100644 --- a/tests/dbal/concatenate_test.php +++ b/tests/dbal/concatenate_test.php @@ -19,7 +19,7 @@ class phpbb_dbal_concatenate_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', "'" . $db->sql_escape('append') . "'") . ' AS string - FROM \phpbb\config\config'; + FROM phpbb_config'; $result = $db->sql_query($sql); $db->sql_return_on_error(false); @@ -43,7 +43,7 @@ class phpbb_dbal_concatenate_test extends phpbb_database_test_case $db = $this->new_dbal(); $sql = 'SELECT config_name, ' . $db->sql_concatenate('config_name', 'config_value') . ' AS string - FROM \phpbb\config\config'; + FROM phpbb_config'; $result = $db->sql_query($sql); $db->sql_return_on_error(false); diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index 3f48f22252..041c529855 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -18,7 +18,7 @@ class phpbb_dbal_migration_dummy extends \phpbb\db\migration\migration { return array( 'add_columns' => array( - '\phpbb\config\config' => array( + 'phpbb_config' => array( 'extra_column' => array('UINT', 1), ), ), diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index c46dfca30d..1882b20492 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -13,7 +13,7 @@ class phpbb_dbal_migration_revert extends \phpbb\db\migration\migration { return array( 'add_columns' => array( - '\phpbb\config\config' => array( + 'phpbb_config' => array( 'bar_column' => array('UINT', 1), ), ), @@ -24,7 +24,7 @@ class phpbb_dbal_migration_revert extends \phpbb\db\migration\migration { return array( 'drop_columns' => array( - '\phpbb\config\config' => array( + 'phpbb_config' => array( 'bar_column', ), ), diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index d336854a1c..6679ae407b 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -35,7 +35,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->db_tools = new \phpbb\db\tools($this->db); - $this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, '\phpbb\config\config'); + $this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config'); $tools = array( new \phpbb\db\migration\tool\config($this->config), @@ -91,7 +91,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('extra_column' => '1')), - "SELECT extra_column FROM \phpbb\config\config WHERE config_name = 'foo'", + "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", 'Dummy migration created extra_column with value 1 in all rows.' ); @@ -107,7 +107,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case ); // cleanup - $this->db_tools->sql_column_remove('\phpbb\config\config', 'extra_column'); + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); } public function test_unfulfillable() @@ -123,11 +123,11 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('extra_column' => '1')), - "SELECT extra_column FROM \phpbb\config\config WHERE config_name = 'foo'", + "SELECT extra_column FROM phpbb_config WHERE config_name = 'foo'", 'Dummy migration was run, even though an unfulfillable migration was found.' ); - $this->db_tools->sql_column_remove('\phpbb\config\config', 'extra_column'); + $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); } public function test_if() @@ -192,7 +192,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('bar_column' => '1')), - "SELECT bar_column FROM \phpbb\config\config WHERE config_name = 'foo'", + "SELECT bar_column FROM phpbb_config WHERE config_name = 'foo'", 'Installing revert migration failed to create bar_column.' ); @@ -208,7 +208,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertFalse(isset($this->config['foobartest'])); - $sql = 'SELECT * FROM \phpbb\config\config'; + $sql = 'SELECT * FROM phpbb_config'; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); @@ -237,7 +237,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case // Failure should have caused an automatic roll-back, so this should not exist. $this->assertFalse(isset($this->config['foobar3'])); - $sql = 'SELECT * FROM \phpbb\config\config'; + $sql = 'SELECT * FROM phpbb_config'; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php index a09daa0f76..2a332fddba 100644 --- a/tests/dbal/schema_test.php +++ b/tests/dbal/schema_test.php @@ -21,13 +21,13 @@ class phpbb_dbal_schema_test extends phpbb_database_test_case $db = $this->new_dbal(); $value = str_repeat("\xC3\x84", 255); - $sql = "INSERT INTO \phpbb\config\config + $sql = "INSERT INTO phpbb_config (config_name, config_value) VALUES ('name', '$value')"; $result = $db->sql_query($sql); $sql = "SELECT config_value - FROM \phpbb\config\config + FROM phpbb_config WHERE config_name = 'name'"; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 976495d195..a70eea4f7e 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -17,7 +17,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->buffer = new \phpbb\db\sql_insert_buffer($this->db, '\phpbb\config\config', 2); + $this->buffer = new \phpbb\db\sql_insert_buffer($this->db, 'phpbb_config', 2); $this->assert_config_count(2); } @@ -81,7 +81,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case protected function assert_config_count($num_configs) { $sql = 'SELECT COUNT(*) AS num_configs - FROM \phpbb\config\config'; + FROM phpbb_config'; $result = $this->db->sql_query($sql); $this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs')); $this->db->sql_freeresult($result); diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php index c0f0c271d2..c069d9a796 100644 --- a/tests/dbal/write_test.php +++ b/tests/dbal/write_test.php @@ -39,11 +39,11 @@ class phpbb_dbal_write_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = 'INSERT INTO \phpbb\config\config ' . $db->sql_build_array('INSERT', $sql_ary); + $sql = 'INSERT INTO phpbb_config ' . $db->sql_build_array('INSERT', $sql_ary); $result = $db->sql_query($sql); $sql = "SELECT * - FROM \phpbb\config\config + FROM phpbb_config WHERE config_name = '" . $sql_ary['config_name'] . "'"; $result = $db->sql_query_limit($sql, 1); @@ -56,15 +56,15 @@ class phpbb_dbal_write_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = "DELETE FROM \phpbb\config\config + $sql = "DELETE FROM phpbb_config WHERE config_name = 'config1'"; $result = $db->sql_query($sql); $sql = 'SELECT * - FROM \phpbb\config\config'; + FROM phpbb_config'; $result = $db->sql_query($sql); $rows = $db->sql_fetchrowset($result); - + $this->assertEquals(1, sizeof($rows)); $this->assertEquals('config2', $rows[0]['config_name']); @@ -76,7 +76,7 @@ class phpbb_dbal_write_test extends phpbb_database_test_case $db = $this->new_dbal(); // empty the table - $sql = 'DELETE FROM \phpbb\config\config'; + $sql = 'DELETE FROM phpbb_config'; $db->sql_query($sql); $batch_ary = array( @@ -92,10 +92,10 @@ class phpbb_dbal_write_test extends phpbb_database_test_case ), ); - $result = $db->sql_multi_insert('\phpbb\config\config', $batch_ary); + $result = $db->sql_multi_insert('phpbb_config', $batch_ary); $sql = 'SELECT * - FROM \phpbb\config\config + FROM phpbb_config ORDER BY config_name ASC'; $result = $db->sql_query($sql); @@ -155,12 +155,12 @@ class phpbb_dbal_write_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $sql = 'UPDATE \phpbb\config\config + $sql = 'UPDATE phpbb_config SET ' . $db->sql_build_array('UPDATE', $sql_ary) . $where; $result = $db->sql_query($sql); $sql = 'SELECT * - FROM \phpbb\config\config + FROM phpbb_config ORDER BY config_name ASC'; $result = $db->sql_query($sql); -- cgit v1.2.1 From 9d8ac2b0ceb24dd14df61d083505941afb1b52c4 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 17 Sep 2013 17:12:41 +0200 Subject: [ticket/11700] Fix unit tests after develop merge PHPBB3-11700 --- tests/dbal/migrator_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 6481e09ead..ef5d167fc2 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -60,7 +60,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->db, $this->config, new phpbb\filesystem( - new phpbb\symfony\request( + new phpbb\symfony_request( new phpbb_mock_request() ), dirname(__FILE__) . '/../../phpBB/', -- cgit v1.2.1 From 7525c49d454e1ff4a156709ea9ecc1dc0b28dd6e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 26 Sep 2013 15:34:44 +0200 Subject: [ticket/11852] Split filesystem and path_helper into 2 classes PHPBB3-11852 --- tests/dbal/migrator_test.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index ef5d167fc2..c6b4c289d3 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -59,13 +59,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, - new phpbb\filesystem( - new phpbb\symfony_request( - new phpbb_mock_request() - ), - dirname(__FILE__) . '/../../phpBB/', - 'php' - ), + new phpbb\filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', -- cgit v1.2.1 From a175b091b9066478900d4a1a92c3e67f33cd9b33 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 Nov 2013 18:12:50 +0100 Subject: [ticket/11995] Add unit test for reverting config.remove PHPBB3-11995 --- tests/dbal/migrator_tool_config_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index a8d8966839..d007e36da1 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -94,6 +94,7 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case public function test_reverse() { + // add $this->config->set('foo', 'bar'); try @@ -106,6 +107,21 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case } $this->assertFalse(isset($this->config['foo'])); + // remove + $this->config->delete('foo'); + + try + { + $this->tool->reverse('remove', 'foo'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertTrue(isset($this->config['foo'])); + $this->assertEquals('', $this->config['foo']); + + // update_if_equals $this->config->set('foo', 'bar'); try -- cgit v1.2.1 From e8a3028ea6505942f6f192105b75dabc177dae44 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 2 Nov 2013 19:26:45 +0100 Subject: [ticket/11995] Remove exceptions and split reverse into different tests PHPBB3-11995 --- tests/dbal/migrator_tool_config_test.php | 99 ++++++++------------------------ 1 file changed, 24 insertions(+), 75 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index d007e36da1..807399385c 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -20,35 +20,24 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case public function test_add() { - try - { - $this->tool->add('foo', 'bar'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->add('foo', 'bar'); $this->assertEquals('bar', $this->config['foo']); + } - try - { - $this->tool->add('foo', 'bar'); - $this->fail('Exception not thrown'); - } - catch (Exception $e) {} + public function test_add_twice() + { + $this->tool->add('foo', 'bar'); + $this->assertEquals('bar', $this->config['foo']); + + $this->tool->add('foo', 'bar2'); + $this->assertEquals('bar', $this->config['foo']); } public function test_update() { $this->config->set('foo', 'bar'); - try - { - $this->tool->update('foo', 'bar2'); - } - catch (Exception $e) - { - $this->fail($e); - } + + $this->tool->update('foo', 'bar2'); $this->assertEquals('bar2', $this->config['foo']); } @@ -56,24 +45,10 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case { $this->config->set('foo', 'bar'); - try - { - $this->tool->update_if_equals('', 'foo', 'bar2'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->update_if_equals('', 'foo', 'bar2'); $this->assertEquals('bar', $this->config['foo']); - try - { - $this->tool->update_if_equals('bar', 'foo', 'bar2'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->update_if_equals('bar', 'foo', 'bar2'); $this->assertEquals('bar2', $this->config['foo']); } @@ -81,57 +56,31 @@ class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case { $this->config->set('foo', 'bar'); - try - { - $this->tool->remove('foo'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->remove('foo'); $this->assertFalse(isset($this->config['foo'])); } - public function test_reverse() + public function test_reverse_add() { - // add $this->config->set('foo', 'bar'); - try - { - $this->tool->reverse('add', 'foo'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->reverse('add', 'foo'); $this->assertFalse(isset($this->config['foo'])); + } - // remove + public function test_reverse_remove() + { $this->config->delete('foo'); - try - { - $this->tool->reverse('remove', 'foo'); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertTrue(isset($this->config['foo'])); + $this->tool->reverse('remove', 'foo'); $this->assertEquals('', $this->config['foo']); + } - // update_if_equals + public function test_reverse_update_if_equals() + { $this->config->set('foo', 'bar'); - try - { - $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar'); - } - catch (Exception $e) - { - $this->fail($e); - } + $this->tool->reverse('update_if_equals', 'test', 'foo', 'bar'); $this->assertEquals('test', $this->config['foo']); } } -- cgit v1.2.1 From 2c878ead311b8b71cabb4070ce848d5b84470ce8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 3 Feb 2014 15:06:43 -0600 Subject: [ticket/11880] Break up schema changes in the migrator PHPBB3-11880 --- tests/dbal/migration/schema.php | 33 +++++++++++++++++++++++++++++++++ tests/dbal/migrator_test.php | 20 ++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/dbal/migration/schema.php (limited to 'tests/dbal') diff --git a/tests/dbal/migration/schema.php b/tests/dbal/migration/schema.php new file mode 100644 index 0000000000..46cf66eaec --- /dev/null +++ b/tests/dbal/migration/schema.php @@ -0,0 +1,33 @@ + array( + $this->table_prefix . 'config' => array( + 'test_column1' => array('BOOL', 1), + ), + ), + ); + } + + function revert_schema() + { + return array( + 'drop_columns' => array( + $this->table_prefix . 'config' => array( + 'test_column1', + ), + ), + ); + } +} diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index c6b4c289d3..9a6f33523c 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -16,6 +16,7 @@ require_once dirname(__FILE__) . '/migration/revert.php'; require_once dirname(__FILE__) . '/migration/revert_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 { @@ -267,4 +268,23 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->fail('Installed test failed'); } } + + public function test_schema() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_schema')); + + while (!$this->migrator->finished()) + { + $this->migrator->update(); + } + + $this->assertTrue($this->db_tools->sql_column_exists('phpbb_config', 'test_column1')); + + while ($this->migrator->migration_state('phpbb_dbal_migration_schema')) + { + $this->migrator->revert('phpbb_dbal_migration_schema'); + } + + $this->assertFalse($this->db_tools->sql_column_exists('phpbb_config', 'test_column1')); + } } -- cgit v1.2.1 From 38eb6b0e135293d51cc100937a6072b32e214c34 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 5 Feb 2014 09:57:36 -0600 Subject: [ticket/11880] Move get_schema_steps function to a migrator helper class PHPBB3-11880 --- tests/dbal/migrator_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 9a6f33523c..c075f19825 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -50,7 +50,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case dirname(__FILE__) . '/../../phpBB/', 'php', 'phpbb_', - $tools + $tools, + new \phpbb\db\migration\helper() ); $container = new phpbb_mock_container_builder(); -- cgit v1.2.1 From bbada27ee9e797c7f6ce997152bc1efb8c8f125d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 2 Feb 2014 21:45:59 +0100 Subject: [ticket/12115] Also port user interests to profile fields PHPBB3-12115 --- tests/dbal/fixtures/massmail_crossjoin.xml | 8 -------- tests/dbal/fixtures/three_users.xml | 8 -------- tests/dbal/write_sequence_test.php | 2 -- 3 files changed, 18 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/massmail_crossjoin.xml b/tests/dbal/fixtures/massmail_crossjoin.xml index ef0a2b7149..1050ba067e 100644 --- a/tests/dbal/fixtures/massmail_crossjoin.xml +++ b/tests/dbal/fixtures/massmail_crossjoin.xml @@ -14,16 +14,12 @@ username_clean user_permissions user_sig - user_occ - user_interests 1 mass email mass email - - 2 @@ -31,8 +27,6 @@ banned - - 3 @@ -40,8 +34,6 @@ not in group - -
diff --git a/tests/dbal/fixtures/three_users.xml b/tests/dbal/fixtures/three_users.xml index a50e3e8634..a601e539e1 100644 --- a/tests/dbal/fixtures/three_users.xml +++ b/tests/dbal/fixtures/three_users.xml @@ -5,31 +5,23 @@ username_cleanuser_permissionsuser_sig - user_occ - user_interests 1 barfoo - - 2 foobar - - 3 bertie - -
diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php index f382a971a5..5fe0fe8de9 100644 --- a/tests/dbal/write_sequence_test.php +++ b/tests/dbal/write_sequence_test.php @@ -42,8 +42,6 @@ class phpbb_dbal_write_sequence_test extends phpbb_database_test_case 'username_clean' => $username, 'user_permissions' => '', 'user_sig' => '', - 'user_occ' => '', - 'user_interests' => '', )); $db->sql_query($sql); -- cgit v1.2.1 From e8f8dcf0eaf53c4d7e175a6b90ae181794718184 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 7 Feb 2014 20:49:13 +0100 Subject: [ticket/12170] Assign schema keys in migration helper with data_depth 1 The migration helper currently drops any keys with schema changes that have the data_depth 1. This change will correctly assign the keys to the steps array without dropping the keys that might contain important info like the actual table that should be created. PHPBB3-12170 --- tests/dbal/migration/schema.php | 11 +++++++++++ tests/dbal/migrator_test.php | 2 ++ 2 files changed, 13 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/schema.php b/tests/dbal/migration/schema.php index 46cf66eaec..98407eb1bd 100644 --- a/tests/dbal/migration/schema.php +++ b/tests/dbal/migration/schema.php @@ -17,6 +17,14 @@ class phpbb_dbal_migration_schema extends \phpbb\db\migration\migration 'test_column1' => array('BOOL', 1), ), ), + 'add_tables' => array( + $this->table_prefix . 'foobar' => array( + 'COLUMNS' => array( + 'module_id' => array('UINT:3', NULL, 'auto_increment'), + ), + 'PRIMARY_KEY' => 'module_id', + ), + ), ); } @@ -28,6 +36,9 @@ class phpbb_dbal_migration_schema extends \phpbb\db\migration\migration 'test_column1', ), ), + 'drop_tables' => array( + $this->table_prefix . 'foobar', + ), ); } } diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index c075f19825..f22f5f5b30 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -280,6 +280,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case } $this->assertTrue($this->db_tools->sql_column_exists('phpbb_config', 'test_column1')); + $this->assertTrue($this->db_tools->sql_table_exists('phpbb_foobar')); while ($this->migrator->migration_state('phpbb_dbal_migration_schema')) { @@ -287,5 +288,6 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case } $this->assertFalse($this->db_tools->sql_column_exists('phpbb_config', 'test_column1')); + $this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar')); } } -- cgit v1.2.1 From 0a586258a21e36e45f39fa170d7365f8d879769b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 3 Apr 2014 15:42:36 +0200 Subject: [ticket/12349] Update license header in several new files PHPBB3-12349 --- tests/dbal/migration/dummy.php | 2 +- tests/dbal/migration/fail.php | 2 +- tests/dbal/migration/if.php | 2 +- tests/dbal/migration/installed.php | 2 +- tests/dbal/migration/recall.php | 2 +- tests/dbal/migration/revert.php | 2 +- tests/dbal/migration/revert_with_dependency.php | 2 +- tests/dbal/migration/schema.php | 2 +- tests/dbal/migration/unfulfillable.php | 2 +- tests/dbal/migrator_test.php | 2 +- tests/dbal/migrator_tool_config_test.php | 2 +- tests/dbal/migrator_tool_module_test.php | 2 +- tests/dbal/migrator_tool_permission_test.php | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index 041c529855..b68a3673c1 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php index d90972720d..b0702a469a 100644 --- a/tests/dbal/migration/fail.php +++ b/tests/dbal/migration/fail.php @@ -3,7 +3,7 @@ * * @package migration * @copyright (c) 2012 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php index bbbda60ea3..883d93c6e4 100644 --- a/tests/dbal/migration/if.php +++ b/tests/dbal/migration/if.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php index 4b86896d9c..cc4e81aff6 100644 --- a/tests/dbal/migration/installed.php +++ b/tests/dbal/migration/installed.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php index 041d12ad27..af5e9243cf 100644 --- a/tests/dbal/migration/recall.php +++ b/tests/dbal/migration/recall.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index 1882b20492..c2520f4d8a 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php index 0b09fb784d..ece16eb67c 100644 --- a/tests/dbal/migration/revert_with_dependency.php +++ b/tests/dbal/migration/revert_with_dependency.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migration/schema.php b/tests/dbal/migration/schema.php index 98407eb1bd..efe6891aaa 100644 --- a/tests/dbal/migration/schema.php +++ b/tests/dbal/migration/schema.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2014 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php index a1cdef9a23..125629d27c 100644 --- a/tests/dbal/migration/unfulfillable.php +++ b/tests/dbal/migration/unfulfillable.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index f22f5f5b30..c18c49b2a0 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index 807399385c..12644e4a23 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 3c23891348..c3358ef944 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 1090b4726a..4016cbcf20 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -3,7 +3,7 @@ * * @package testing * @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From a48f1abf6693eaee3343abd4f4a7e6412ecc10d9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 14 Apr 2014 16:29:21 +0200 Subject: [ticket/12012] Add a unit test for changing the column type PHPBB3-12012 --- tests/dbal/db_tools_test.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index e25335165a..0715b09ea3 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -11,7 +11,9 @@ 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 */ protected $tools; protected $table_exists; protected $table_data; @@ -207,6 +209,32 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'column_does_not_exist')); } + public function test_column_change_with_index() + { + // Create column + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); + $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012', array('DECIMAL', 0))); + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); + + // Create index over the column + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012', array('c_bug_12012', 'c_bool'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); + + // Change type from int to string + $this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12012', array('VCHAR:100', ''))); + + // Remove the index + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); + $this->assertTrue($this->tools->sql_index_drop('prefix_table_name', 'i_bug_12012')); + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); + + // Remove the column + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_bug_12012')); + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); + } + public function test_column_remove() { $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size')); @@ -252,7 +280,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertFalse($this->tools->sql_table_exists('prefix_test_table')); } - public function test_peform_schema_changes_drop_tables() + public function test_perform_schema_changes_drop_tables() { $db_tools = $this->getMock('\phpbb\db\tools', array( 'sql_table_exists', @@ -278,7 +306,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case )); } - public function test_peform_schema_changes_drop_columns() + public function test_perform_schema_changes_drop_columns() { $db_tools = $this->getMock('\phpbb\db\tools', array( 'sql_column_exists', -- cgit v1.2.1 From 540384890258a22860d655086521c968b30bcbea Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 14 Apr 2014 17:21:27 +0200 Subject: [ticket/12012] Add a unit test for removing a column with indexes PHPBB3-12012 --- tests/dbal/db_tools_test.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 0715b09ea3..df8f22083b 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -244,6 +244,28 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_int_size')); } + public function test_column_remove_with_index() + { + // Create column + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); + $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012_2', array('UINT', 4))); + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); + + // Create index over the column + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_2')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012_2', array('c_bug_12012_2', 'c_bool'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_2')); + + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_3')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012_3', array('c_bug_12012_2'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_3')); + + // Remove the column + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_bug_12012_2')); + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); + } + public function test_column_remove_primary() { $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_id')); -- cgit v1.2.1 From 28176b0746807449d984823caed10b504dcd7305 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sat, 26 Apr 2014 12:12:51 +0200 Subject: [ticket/12432] Adding unit test PHPBB3-12432 --- tests/dbal/migration/revert.php | 8 ++++++++ tests/dbal/migrator_test.php | 9 +++++++++ 2 files changed, 17 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index c2520f4d8a..1c98710ffb 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -35,6 +35,14 @@ class phpbb_dbal_migration_revert extends \phpbb\db\migration\migration { return array( array('config.add', array('foobartest', 0)), + array('custom', array(array(&$this, 'my_custom_function'))), ); } + + function my_custom_function() + { + global $migrator_test_revert_counter; + + $migrator_test_revert_counter += 1; + } } diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index c18c49b2a0..d1e12e5b2e 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -174,10 +174,14 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case public function test_revert() { + global $migrator_test_revert_counter; + // 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(); + $migrator_test_revert_counter = 0; + $this->migrator->set_migrations(array('phpbb_dbal_migration_revert', 'phpbb_dbal_migration_revert_with_dependency')); $this->assertFalse($this->migrator->migration_state('phpbb_dbal_migration_revert')); @@ -219,6 +223,11 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case { $this->fail('Revert did not remove test_column.'); } + + if ($migrator_test_revert_counter != 1) + { + $this->fail('Revert did not recall the customs functions.'); + } } public function test_fail() -- cgit v1.2.1 From ea15b879f127f3d121d8e78ae01457b43b702e58 Mon Sep 17 00:00:00 2001 From: Nicofuma Date: Sat, 26 Apr 2014 18:54:47 +0200 Subject: [ticket/12432] Correcting the assertion PHPBB3-12432 --- tests/dbal/migrator_test.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index d1e12e5b2e..cc3e92071f 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -224,10 +224,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->fail('Revert did not remove test_column.'); } - if ($migrator_test_revert_counter != 1) - { - $this->fail('Revert did not recall the customs functions.'); - } + $this->assertEquals(1, $migrator_test_revert_counter, 'Revert did call custom function again'); } public function test_fail() -- cgit v1.2.1 From 05839f85994c1281936d2dd64215c068e55b6d54 Mon Sep 17 00:00:00 2001 From: PayBas Date: Fri, 23 May 2014 22:24:57 +0200 Subject: [ticket/12561] Added test for "after" PHPBB3-12561 --- tests/dbal/migration/dummy_order.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/dbal/migration/dummy_order.php (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy_order.php b/tests/dbal/migration/dummy_order.php new file mode 100644 index 0000000000..011ac7c1e9 --- /dev/null +++ b/tests/dbal/migration/dummy_order.php @@ -0,0 +1,31 @@ + array( + $this->table_prefix . 'column_order_test' => array( + 'COLUMNS' => array( + 'foobar1' => array('BOOL', 0), + 'foobar3' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('foobar1'), + ), + ), + 'add_columns' => array( + $this->table_prefix . 'column_order_test' => array( + 'foobar2' => array('BOOL', 0, 'after' => 'foobar1'), + ), + ), + ); + } +} -- cgit v1.2.1 From 3cabe5fd792fced4120de02cfef66900b49516c4 Mon Sep 17 00:00:00 2001 From: PayBas Date: Mon, 26 May 2014 20:47:19 +0200 Subject: [ticket/12561] Added tests for "after last", "after missing" and "empty" Also removed tabs PHPBB3-12561 --- tests/dbal/migration/dummy_order.php | 49 ++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy_order.php b/tests/dbal/migration/dummy_order.php index 011ac7c1e9..af047eb416 100644 --- a/tests/dbal/migration/dummy_order.php +++ b/tests/dbal/migration/dummy_order.php @@ -13,7 +13,7 @@ class phpbb_dbal_migration_dummy_order extends \phpbb\db\migration\migration { return array( 'add_tables' => array( - $this->table_prefix . 'column_order_test' => array( + $this->table_prefix . 'column_order_test1' => array( 'COLUMNS' => array( 'foobar1' => array('BOOL', 0), 'foobar3' => array('BOOL', 0), @@ -22,10 +22,55 @@ class phpbb_dbal_migration_dummy_order extends \phpbb\db\migration\migration ), ), 'add_columns' => array( - $this->table_prefix . 'column_order_test' => array( + $this->table_prefix . 'column_order_test1' => array( 'foobar2' => array('BOOL', 0, 'after' => 'foobar1'), ), ), + + 'add_tables' => array( + $this->table_prefix . 'column_order_test2' => array( + 'COLUMNS' => array( + 'foobar1' => array('BOOL', 0), + 'foobar3' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('foobar1'), + ), + ), + 'add_columns' => array( + $this->table_prefix . 'column_order_test2' => array( + 'foobar4' => array('BOOL', 0, 'after' => 'foobar3'), + ), + ), + + 'add_tables' => array( + $this->table_prefix . 'column_order_test3' => array( + 'COLUMNS' => array( + 'foobar1' => array('BOOL', 0), + 'foobar3' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('foobar1'), + ), + ), + 'add_columns' => array( + $this->table_prefix . 'column_order_test3' => array( + 'foobar5' => array('BOOL', 0, 'after' => 'non-existing'), + ), + ), + + 'add_tables' => array( + $this->table_prefix . 'column_order_test4' => array( + 'COLUMNS' => array( + 'foobar1' => array('BOOL', 0), + 'foobar3' => array('BOOL', 0), + ), + 'PRIMARY_KEY' => array('foobar1'), + ), + ), + 'add_columns' => array( + $this->table_prefix . 'column_order_test4' => array( + 'foobar5' => array('BOOL', 0, 'after' => ''), + ), + ), ); } } -- cgit v1.2.1 From 15516bd07853cbda585f1716ce1b614d43cf9d9a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 23 May 2014 16:10:07 +0200 Subject: [ticket/12570] Add a unit test to show broken sql_affectedrows() PHPBB3-12570 --- tests/dbal/sql_affected_rows_test.php | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/dbal/sql_affected_rows_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/sql_affected_rows_test.php b/tests/dbal/sql_affected_rows_test.php new file mode 100644 index 0000000000..df008bab9a --- /dev/null +++ b/tests/dbal/sql_affected_rows_test.php @@ -0,0 +1,73 @@ +db = $this->new_dbal(); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + public function test_select() + { + $sql = 'SELECT * + FROM ' . CONFIG_TABLE; + $this->db->sql_query($sql); + + $this->assertEquals(2, $this->db->sql_affectedrows()); + } + + public function test_update() + { + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = 'bertie'"; + $this->db->sql_query($sql); + + $this->assertEquals(2, $this->db->sql_affectedrows()); + } + + public function test_update_all_matched_unequal_updated() + { + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = 'foo'"; + $this->db->sql_query($sql); + + $this->assertEquals(2, $this->db->sql_affectedrows()); + } + + public function test_update_some_matched_unequal_updated() + { + $sql = 'UPDATE ' . CONFIG_TABLE . " + SET config_value = 'foo' + WHERE config_value = 'foo'"; + $this->db->sql_query($sql); + + $this->assertEquals(1, $this->db->sql_affectedrows()); + } + + public function test_insert() + { + $sql = 'INSERT INTO ' . CONFIG_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'config_name' => 'bertie', + 'config_value' => 'rules', + )); + $this->db->sql_query($sql); + + $this->assertEquals(1, $this->db->sql_affectedrows()); + } +} -- cgit v1.2.1 From 275e56ce70b194ed6712ba30707494607dbdc1cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 23 May 2014 18:04:40 +0200 Subject: [ticket/12570] Remove test for affected rows after SELECT It's not supposed to work PHPBB3-12570 --- tests/dbal/sql_affected_rows_test.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/sql_affected_rows_test.php b/tests/dbal/sql_affected_rows_test.php index df008bab9a..860b8bf237 100644 --- a/tests/dbal/sql_affected_rows_test.php +++ b/tests/dbal/sql_affected_rows_test.php @@ -23,15 +23,6 @@ class phpbb_dbal_sql_affected_rows_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } - public function test_select() - { - $sql = 'SELECT * - FROM ' . CONFIG_TABLE; - $this->db->sql_query($sql); - - $this->assertEquals(2, $this->db->sql_affectedrows()); - } - public function test_update() { $sql = 'UPDATE ' . CONFIG_TABLE . " @@ -50,7 +41,7 @@ class phpbb_dbal_sql_affected_rows_test extends phpbb_database_test_case $this->assertEquals(2, $this->db->sql_affectedrows()); } - public function test_update_some_matched_unequal_updated() + public function test_update_same_value_matched_unequal_updated() { $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foo' -- cgit v1.2.1 From 9f37d414be1cc13377b9af1777220577c7af645c Mon Sep 17 00:00:00 2001 From: PayBas Date: Tue, 27 May 2014 00:41:11 +0200 Subject: [ticket/12561] Reworked tests by nickvergessen PHPBB3-12561 --- tests/dbal/migration/dummy_order.php | 50 ---------------------------------- tests/dbal/migration/dummy_order_0.php | 22 +++++++++++++++ tests/dbal/migration/dummy_order_1.php | 22 +++++++++++++++ tests/dbal/migration/dummy_order_2.php | 22 +++++++++++++++ tests/dbal/migration/dummy_order_3.php | 22 +++++++++++++++ tests/dbal/migration/dummy_order_4.php | 22 +++++++++++++++ tests/dbal/migration/dummy_order_5.php | 23 ++++++++++++++++ 7 files changed, 133 insertions(+), 50 deletions(-) create mode 100644 tests/dbal/migration/dummy_order_0.php create mode 100644 tests/dbal/migration/dummy_order_1.php create mode 100644 tests/dbal/migration/dummy_order_2.php create mode 100644 tests/dbal/migration/dummy_order_3.php create mode 100644 tests/dbal/migration/dummy_order_4.php create mode 100644 tests/dbal/migration/dummy_order_5.php (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy_order.php b/tests/dbal/migration/dummy_order.php index af047eb416..b8590f5074 100644 --- a/tests/dbal/migration/dummy_order.php +++ b/tests/dbal/migration/dummy_order.php @@ -21,56 +21,6 @@ class phpbb_dbal_migration_dummy_order extends \phpbb\db\migration\migration 'PRIMARY_KEY' => array('foobar1'), ), ), - 'add_columns' => array( - $this->table_prefix . 'column_order_test1' => array( - 'foobar2' => array('BOOL', 0, 'after' => 'foobar1'), - ), - ), - - 'add_tables' => array( - $this->table_prefix . 'column_order_test2' => array( - 'COLUMNS' => array( - 'foobar1' => array('BOOL', 0), - 'foobar3' => array('BOOL', 0), - ), - 'PRIMARY_KEY' => array('foobar1'), - ), - ), - 'add_columns' => array( - $this->table_prefix . 'column_order_test2' => array( - 'foobar4' => array('BOOL', 0, 'after' => 'foobar3'), - ), - ), - - 'add_tables' => array( - $this->table_prefix . 'column_order_test3' => array( - 'COLUMNS' => array( - 'foobar1' => array('BOOL', 0), - 'foobar3' => array('BOOL', 0), - ), - 'PRIMARY_KEY' => array('foobar1'), - ), - ), - 'add_columns' => array( - $this->table_prefix . 'column_order_test3' => array( - 'foobar5' => array('BOOL', 0, 'after' => 'non-existing'), - ), - ), - - 'add_tables' => array( - $this->table_prefix . 'column_order_test4' => array( - 'COLUMNS' => array( - 'foobar1' => array('BOOL', 0), - 'foobar3' => array('BOOL', 0), - ), - 'PRIMARY_KEY' => array('foobar1'), - ), - ), - 'add_columns' => array( - $this->table_prefix . 'column_order_test4' => array( - 'foobar5' => array('BOOL', 0, 'after' => ''), - ), - ), ); } } diff --git a/tests/dbal/migration/dummy_order_0.php b/tests/dbal/migration/dummy_order_0.php new file mode 100644 index 0000000000..e45bb0ad44 --- /dev/null +++ b/tests/dbal/migration/dummy_order_0.php @@ -0,0 +1,22 @@ + array( + $this->table_prefix . 'column_order_test1' => array( + 'foobar2' => array('BOOL', 0, 'after' => 'foobar1'), + ), + ), + ); + } +} diff --git a/tests/dbal/migration/dummy_order_1.php b/tests/dbal/migration/dummy_order_1.php new file mode 100644 index 0000000000..73f043af5d --- /dev/null +++ b/tests/dbal/migration/dummy_order_1.php @@ -0,0 +1,22 @@ + array( + $this->table_prefix . 'column_order_test1' => array( + 'foobar4' => array('BOOL', 0, 'after' => 'foobar3'), + ), + ), + ); + } +} diff --git a/tests/dbal/migration/dummy_order_2.php b/tests/dbal/migration/dummy_order_2.php new file mode 100644 index 0000000000..1483b98050 --- /dev/null +++ b/tests/dbal/migration/dummy_order_2.php @@ -0,0 +1,22 @@ + array( + $this->table_prefix . 'column_order_test1' => array( + 'foobar5' => array('BOOL', 0, 'after' => 'non-existing'), + ), + ), + ); + } +} diff --git a/tests/dbal/migration/dummy_order_3.php b/tests/dbal/migration/dummy_order_3.php new file mode 100644 index 0000000000..79c542e088 --- /dev/null +++ b/tests/dbal/migration/dummy_order_3.php @@ -0,0 +1,22 @@ + array( + $this->table_prefix . 'column_order_test1' => array( + 'foobar6' => array('BOOL', 0, 'after' => ''), + ), + ), + ); + } +} diff --git a/tests/dbal/migration/dummy_order_4.php b/tests/dbal/migration/dummy_order_4.php new file mode 100644 index 0000000000..229a120ecf --- /dev/null +++ b/tests/dbal/migration/dummy_order_4.php @@ -0,0 +1,22 @@ + array( + $this->table_prefix . 'column_order_test1' => array( + 'foobar7' => array('BOOL', 0), + ), + ), + ); + } +} diff --git a/tests/dbal/migration/dummy_order_5.php b/tests/dbal/migration/dummy_order_5.php new file mode 100644 index 0000000000..04d755009d --- /dev/null +++ b/tests/dbal/migration/dummy_order_5.php @@ -0,0 +1,23 @@ + array( + $this->table_prefix . 'column_order_test1' => array( + 'foobar8' => array('BOOL', 0, 'after' => 'foobar3'), + 'foobar9' => array('BOOL', 0, 'after' => 'foobar3'), + ), + ), + ); + } +} -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- tests/dbal/auto_increment_test.php | 10 +++++++--- tests/dbal/case_test.php | 10 +++++++--- tests/dbal/concatenate_test.php | 10 +++++++--- tests/dbal/connect_test.php | 10 +++++++--- tests/dbal/cross_join_test.php | 10 +++++++--- tests/dbal/db_tools_test.php | 10 +++++++--- tests/dbal/migration/dummy.php | 10 +++++++--- tests/dbal/migration/fail.php | 10 +++++++--- tests/dbal/migration/if.php | 10 +++++++--- tests/dbal/migration/installed.php | 10 +++++++--- tests/dbal/migration/recall.php | 10 +++++++--- tests/dbal/migration/revert.php | 10 +++++++--- tests/dbal/migration/revert_with_dependency.php | 10 +++++++--- tests/dbal/migration/schema.php | 10 +++++++--- tests/dbal/migration/unfulfillable.php | 10 +++++++--- tests/dbal/migrator_test.php | 10 +++++++--- tests/dbal/migrator_tool_config_test.php | 10 +++++++--- tests/dbal/migrator_tool_module_test.php | 10 +++++++--- tests/dbal/migrator_tool_permission_test.php | 10 +++++++--- tests/dbal/order_lower_test.php | 10 +++++++--- tests/dbal/schema_test.php | 10 +++++++--- tests/dbal/select_test.php | 10 +++++++--- tests/dbal/sql_insert_buffer_test.php | 10 +++++++--- tests/dbal/write_sequence_test.php | 10 +++++++--- tests/dbal/write_test.php | 10 +++++++--- 25 files changed, 175 insertions(+), 75 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php index 2196292e83..1ed8ea29e3 100644 --- a/tests/dbal/auto_increment_test.php +++ b/tests/dbal/auto_increment_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/case_test.php b/tests/dbal/case_test.php index 57a1729a39..5f1c7d61fa 100644 --- a/tests/dbal/case_test.php +++ b/tests/dbal/case_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/concatenate_test.php b/tests/dbal/concatenate_test.php index 0891fa58a0..00e7e107aa 100644 --- a/tests/dbal/concatenate_test.php +++ b/tests/dbal/concatenate_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/connect_test.php b/tests/dbal/connect_test.php index 1e352d6b03..1ae34bd2b6 100644 --- a/tests/dbal/connect_test.php +++ b/tests/dbal/connect_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/cross_join_test.php b/tests/dbal/cross_join_test.php index 6c6b8a8449..7ba937ccc6 100644 --- a/tests/dbal/cross_join_test.php +++ b/tests/dbal/cross_join_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index df8f22083b..320eac3bf3 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/dummy.php b/tests/dbal/migration/dummy.php index b68a3673c1..d564754892 100644 --- a/tests/dbal/migration/dummy.php +++ b/tests/dbal/migration/dummy.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/fail.php b/tests/dbal/migration/fail.php index b0702a469a..a7a8a41694 100644 --- a/tests/dbal/migration/fail.php +++ b/tests/dbal/migration/fail.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php index 883d93c6e4..98a66526ed 100644 --- a/tests/dbal/migration/if.php +++ b/tests/dbal/migration/if.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/installed.php b/tests/dbal/migration/installed.php index cc4e81aff6..83edaae23a 100644 --- a/tests/dbal/migration/installed.php +++ b/tests/dbal/migration/installed.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php index af5e9243cf..c0333b084d 100644 --- a/tests/dbal/migration/recall.php +++ b/tests/dbal/migration/recall.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/revert.php b/tests/dbal/migration/revert.php index 1c98710ffb..7da65a83f1 100644 --- a/tests/dbal/migration/revert.php +++ b/tests/dbal/migration/revert.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/revert_with_dependency.php b/tests/dbal/migration/revert_with_dependency.php index ece16eb67c..43e9a4aa42 100644 --- a/tests/dbal/migration/revert_with_dependency.php +++ b/tests/dbal/migration/revert_with_dependency.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/schema.php b/tests/dbal/migration/schema.php index efe6891aaa..38663bcc16 100644 --- a/tests/dbal/migration/schema.php +++ b/tests/dbal/migration/schema.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/unfulfillable.php b/tests/dbal/migration/unfulfillable.php index 125629d27c..11c87a6b85 100644 --- a/tests/dbal/migration/unfulfillable.php +++ b/tests/dbal/migration/unfulfillable.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index cc3e92071f..381fe16115 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php index 12644e4a23..13e0c13e3c 100644 --- a/tests/dbal/migrator_tool_config_test.php +++ b/tests/dbal/migrator_tool_config_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index c3358ef944..aeb69e27ac 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 4016cbcf20..4453fbf123 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index d826765681..e7cc6c4a4d 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/schema_test.php b/tests/dbal/schema_test.php index 2a332fddba..f13c7ce032 100644 --- a/tests/dbal/schema_test.php +++ b/tests/dbal/schema_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index c8cfad04e0..7cac4d6a3b 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index a70eea4f7e..2f9ed0008f 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php index 5fe0fe8de9..a1b589c578 100644 --- a/tests/dbal/write_sequence_test.php +++ b/tests/dbal/write_sequence_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/write_test.php b/tests/dbal/write_test.php index c069d9a796..2426f2b0be 100644 --- a/tests/dbal/write_test.php +++ b/tests/dbal/write_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From 55e1f02151adbe9d66a2d87c00c4f1959739aa36 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Wed, 28 May 2014 01:05:46 +0200 Subject: [ticket/12594] Replace phpBB Group with phpBB Limited PHPBB3-12594 --- tests/dbal/fixtures/styles.xml | 6 +++--- tests/dbal/order_lower_test.php | 6 +++--- tests/dbal/sql_affected_rows_test.php | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/styles.xml b/tests/dbal/fixtures/styles.xml index dcbe39d3b0..d51dcd0320 100644 --- a/tests/dbal/fixtures/styles.xml +++ b/tests/dbal/fixtures/styles.xml @@ -12,7 +12,7 @@ 1 prosilver - &copy; phpBB Group + &copy; phpBB Limited 1 prosilver kNg= @@ -22,7 +22,7 @@ 2 prosilver2 - &copy; phpBB Group + &copy; phpBB Limited 0 prosilver2 kNg= @@ -32,7 +32,7 @@ 3 Prosilver1 - &copy; phpBB Group + &copy; phpBB Limited 0 prosilver1 kNg= diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index e7cc6c4a4d..b7a69c7c5d 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -40,7 +40,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case array( 'style_id' => 1, 'style_name' => 'prosilver', - 'style_copyright' => '© phpBB Group', + 'style_copyright' => '© phpBB Limited', 'style_active' => 1, 'style_path' => 'prosilver', 'bbcode_bitfield' => 'kNg=', @@ -50,7 +50,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case array( 'style_id' => 3, 'style_name' => 'Prosilver1', - 'style_copyright' => '© phpBB Group', + 'style_copyright' => '© phpBB Limited', 'style_active' => 0, 'style_path' => 'prosilver1', 'bbcode_bitfield' => 'kNg=', @@ -60,7 +60,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case array( 'style_id' => 2, 'style_name' => 'prosilver2', - 'style_copyright' => '© phpBB Group', + 'style_copyright' => '© phpBB Limited', 'style_active' => 0, 'style_path' => 'prosilver2', 'bbcode_bitfield' => 'kNg=', diff --git a/tests/dbal/sql_affected_rows_test.php b/tests/dbal/sql_affected_rows_test.php index 860b8bf237..07d7318358 100644 --- a/tests/dbal/sql_affected_rows_test.php +++ b/tests/dbal/sql_affected_rows_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From 7f00c38c50dbd6689f80afaf324c1ee81173d15a Mon Sep 17 00:00:00 2001 From: n-aleha Date: Mon, 12 May 2014 02:31:52 +0300 Subject: [ticket/11467] Add user object to extension manager for tests PHPBB3-11467 --- tests/dbal/migrator_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 381fe16115..4a1d15aea4 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -60,12 +60,14 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); + $user = new \phpbb\user(); $this->extension_manager = new \phpbb\extension\manager( $container, $this->db, $this->config, new phpbb\filesystem(), + $user, 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', -- cgit v1.2.1 From 634824e8885bcc1a89a2fc2400962eb6019c67b8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 30 May 2014 14:44:08 +0200 Subject: [ticket/12594] Fix file headers of new files PHPBB3-12594 --- tests/dbal/migration/dummy_order.php | 10 +++++++--- tests/dbal/migration/dummy_order_0.php | 10 +++++++--- tests/dbal/migration/dummy_order_1.php | 10 +++++++--- tests/dbal/migration/dummy_order_2.php | 10 +++++++--- tests/dbal/migration/dummy_order_3.php | 10 +++++++--- tests/dbal/migration/dummy_order_4.php | 10 +++++++--- tests/dbal/migration/dummy_order_5.php | 10 +++++++--- 7 files changed, 49 insertions(+), 21 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/dummy_order.php b/tests/dbal/migration/dummy_order.php index b8590f5074..5ab8f5d129 100644 --- a/tests/dbal/migration/dummy_order.php +++ b/tests/dbal/migration/dummy_order.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/dummy_order_0.php b/tests/dbal/migration/dummy_order_0.php index e45bb0ad44..4caea76704 100644 --- a/tests/dbal/migration/dummy_order_0.php +++ b/tests/dbal/migration/dummy_order_0.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/dummy_order_1.php b/tests/dbal/migration/dummy_order_1.php index 73f043af5d..ea512765fa 100644 --- a/tests/dbal/migration/dummy_order_1.php +++ b/tests/dbal/migration/dummy_order_1.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/dummy_order_2.php b/tests/dbal/migration/dummy_order_2.php index 1483b98050..a7669b1ac8 100644 --- a/tests/dbal/migration/dummy_order_2.php +++ b/tests/dbal/migration/dummy_order_2.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/dummy_order_3.php b/tests/dbal/migration/dummy_order_3.php index 79c542e088..501db09b7e 100644 --- a/tests/dbal/migration/dummy_order_3.php +++ b/tests/dbal/migration/dummy_order_3.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/dummy_order_4.php b/tests/dbal/migration/dummy_order_4.php index 229a120ecf..77bb5a24b3 100644 --- a/tests/dbal/migration/dummy_order_4.php +++ b/tests/dbal/migration/dummy_order_4.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ diff --git a/tests/dbal/migration/dummy_order_5.php b/tests/dbal/migration/dummy_order_5.php index 04d755009d..8f92392a8b 100644 --- a/tests/dbal/migration/dummy_order_5.php +++ b/tests/dbal/migration/dummy_order_5.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1 From e6a8df7f7ea2036ae9943368ad1ea2cee7cd5655 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sun, 15 Jun 2014 14:18:39 -0500 Subject: [ticket/12643] Tests dropping similarly named columns PHPBB3-12643 --- tests/dbal/db_tools_test.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 320eac3bf3..7cf05a34d4 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -248,6 +248,17 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_int_size')); } + public function test_column_remove_similar_name() + { + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar')); + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar_size')); + + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_vchar')); + + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_vchar')); + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_vchar_size')); + } + public function test_column_remove_with_index() { // Create column -- cgit v1.2.1 From 754e36e378e9d5d744fcfd6d447bd1e48d2052c3 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sun, 15 Jun 2014 14:52:05 -0500 Subject: [ticket/12643] Properly handle changing columns on tables with constraints PHPBB3-12643 --- tests/dbal/db_tools_test.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 7cf05a34d4..f3c6888c8d 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -239,6 +239,24 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); } + public function test_column_change_with_composite_primary() + { + // Remove the old primary key + $this->assertTrue($this->tools->sql_column_remove('prefix_table_name', 'c_id')); + $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_id', array('UINT', 0))); + + // Create a composite key + $this->assertTrue($this->tools->sql_create_primary_key('prefix_table_name', array('c_id', 'c_uint'))); + + // Create column + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12643')); + $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12643', array('DECIMAL', 0))); + $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12643')); + + // Change type from int to string + $this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12643', array('VCHAR:100', ''))); + } + public function test_column_remove() { $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_int_size')); -- cgit v1.2.1 From 95ab4b3e931521ce3c56068478311f0c04f713cc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 25 Jun 2014 13:40:32 +0200 Subject: [ticket/12448] Allow null as default value for columns PHPBB3-12448 --- tests/dbal/db_tools_test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index f3c6888c8d..6cc2f8ec0f 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -46,6 +46,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case 'c_bool' => array('BOOL', 1), 'c_vchar' => array('VCHAR', 'foo'), 'c_vchar_size' => array('VCHAR:4', 'foo'), + 'c_vchar_null' => array('VCHAR', null), 'c_char_size' => array('CHAR:4', 'foo'), 'c_xstext' => array('XSTEXT', 'foo'), 'c_stext' => array('STEXT', 'foo'), @@ -111,6 +112,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case 'c_bool' => 0, 'c_vchar' => '', 'c_vchar_size' => '', + 'c_vchar_null' => null, 'c_char_size' => 'abcd', 'c_xstext' => '', 'c_stext' => '', @@ -144,6 +146,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case array('c_bool', 0), array('c_vchar', str_repeat('a', 255)), array('c_vchar_size', str_repeat('a', 4)), + array('c_vchar_null', str_repeat('a', 4)), array('c_char_size', str_repeat('a', 4)), array('c_xstext', str_repeat('a', 1000)), array('c_stext', str_repeat('a', 3000)), -- cgit v1.2.1 From ff6e026a403a622bd1aa498bff396a737735faed Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 26 Jun 2014 17:17:35 +0200 Subject: [ticket/12446] Unnecessary db connect inphpbb_bootstrap_enabled_exts PHPBB3-12446 --- tests/dbal/order_lower_test.php | 2 +- tests/dbal/select_test.php | 4 ++-- tests/dbal/sql_insert_buffer_test.php | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index b7a69c7c5d..b101d28c7d 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -22,7 +22,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case { $db = $this->new_dbal(); - if (strpos($db->sql_layer, 'mysql') === 0 && version_compare($db->sql_server_info(true, false), '5.6', '>=')) + if (strpos($db->get_sql_layer(), 'mysql') === 0 && version_compare($db->sql_server_info(true, false), '5.6', '>=')) { $this->markTestSkipped('MySQL 5.6 fails to order things correctly. See also: http://tracker.phpbb.com/browse/PHPBB3-11571 http://bugs.mysql.com/bug.php?id=69005'); } diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index 7cac4d6a3b..e480716a49 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -219,8 +219,8 @@ class phpbb_dbal_select_test extends phpbb_database_test_case { $db = $this->new_dbal(); - $like_expression = str_replace('*', $db->any_char, $like_expression); - $like_expression = str_replace('#', $db->one_char, $like_expression); + $like_expression = str_replace('*', $db->get_any_char(), $like_expression); + $like_expression = str_replace('#', $db->get_one_char(), $like_expression); $where = ($like_expression) ? 'username_clean ' . $db->sql_like_expression($like_expression) : ''; $result = $db->sql_query('SELECT username_clean diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 2f9ed0008f..eae0abceba 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -32,7 +32,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_and_flush() { - $this->db->multi_insert = false; + $this->db->set_multi_insert(false); $this->assertTrue($this->buffer->insert($this->get_row(1))); $this->assert_config_count(3); $this->assertFalse($this->buffer->flush()); @@ -50,7 +50,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_with_flush() { - $this->db->multi_insert = false; + $this->db->set_multi_insert(false); $this->assertTrue($this->buffer->insert($this->get_row(1))); $this->assert_config_count(3); $this->assertTrue($this->buffer->insert($this->get_row(2))); @@ -68,7 +68,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_all_and_flush() { - $this->db->multi_insert = false; + $this->db->set_multi_insert(false); $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); $this->assert_config_count(5); } @@ -93,7 +93,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case protected function check_multi_insert_support() { - if (!$this->db->multi_insert) + if (!$this->db->get_multi_insert()) { $this->markTestSkipped('Database does not support multi_insert'); } -- cgit v1.2.1 From 606d82f7dd03da2646333c9ca868071b3e47a970 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 5 Jul 2014 00:57:34 -0700 Subject: [ticket/12812] Add a migrator tool for config_text database changes PHPBB3-12812 --- tests/dbal/fixtures/migrator_config_text.xml | 7 +++ tests/dbal/migrator_tool_config_text_test.php | 79 +++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tests/dbal/fixtures/migrator_config_text.xml create mode 100644 tests/dbal/migrator_tool_config_text_test.php (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/migrator_config_text.xml b/tests/dbal/fixtures/migrator_config_text.xml new file mode 100644 index 0000000000..ba8e1fcfcc --- /dev/null +++ b/tests/dbal/fixtures/migrator_config_text.xml @@ -0,0 +1,7 @@ + + + + config_name + config_value +
+
diff --git a/tests/dbal/migrator_tool_config_text_test.php b/tests/dbal/migrator_tool_config_text_test.php new file mode 100644 index 0000000000..b530bb92dd --- /dev/null +++ b/tests/dbal/migrator_tool_config_text_test.php @@ -0,0 +1,79 @@ + +* @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_migrator_tool_config_text_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_config_text.xml'); + } + + public function setup() + { + global $db; + + parent::setup(); + + $db = $this->db = $this->new_dbal(); + $this->config_text = new \phpbb\config\db_text($this->db, 'phpbb_config_text'); + + $this->tool = new \phpbb\db\migration\tool\config_text($this->config_text); + } + + public function test_add() + { + $this->tool->add('foo', 'bar'); + $this->assertEquals('bar', $this->config_text->get('foo')); + } + + public function test_add_twice() + { + $this->tool->add('foo', 'bar'); + $this->assertEquals('bar', $this->config_text->get('foo')); + + $this->tool->add('foo', 'bar2'); + $this->assertEquals('bar', $this->config_text->get('foo')); + } + + public function test_update() + { + $this->config_text->set('foo', 'bar'); + + $this->tool->update('foo', 'bar2'); + $this->assertEquals('bar2', $this->config_text->get('foo')); + } + + public function test_remove() + { + $this->config_text->set('foo', 'bar'); + + $this->tool->remove('foo'); + $this->assertTrue(is_null($this->config_text->get('foo'))); + } + + public function test_reverse_add() + { + $this->config_text->set('foo', 'bar'); + + $this->tool->reverse('add', 'foo'); + $this->assertTrue(is_null($this->config_text->get('foo'))); + } + + public function test_reverse_remove() + { + $this->config_text->delete('foo'); + + $this->tool->reverse('remove', 'foo'); + $this->assertEquals('', $this->config_text->get('foo')); + } +} -- cgit v1.2.1 From 9dfce860e7b13985897aba0b785d4d6257cf5d4c Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 5 Jul 2014 08:26:01 -0700 Subject: [ticket/12812] Improve migrator config_text tool tests PHPBB3-12812 --- tests/dbal/migrator_tool_config_text_test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_config_text_test.php b/tests/dbal/migrator_tool_config_text_test.php index b530bb92dd..7f9c076fe0 100644 --- a/tests/dbal/migrator_tool_config_text_test.php +++ b/tests/dbal/migrator_tool_config_text_test.php @@ -71,9 +71,7 @@ class phpbb_dbal_migrator_tool_config_text_test extends phpbb_database_test_case public function test_reverse_remove() { - $this->config_text->delete('foo'); - $this->tool->reverse('remove', 'foo'); - $this->assertEquals('', $this->config_text->get('foo')); + $this->assertSame('', $this->config_text->get('foo')); } } -- cgit v1.2.1 From 5527044a00c7bdff1a3a6edfabdbe7583935bbaa Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 6 Jul 2014 08:13:20 -0700 Subject: [ticket/12812] Improve migrator config_text tool tests PHPBB3-12812 --- tests/dbal/migrator_tool_config_text_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_config_text_test.php b/tests/dbal/migrator_tool_config_text_test.php index 7f9c076fe0..f832105e00 100644 --- a/tests/dbal/migrator_tool_config_text_test.php +++ b/tests/dbal/migrator_tool_config_text_test.php @@ -58,7 +58,7 @@ class phpbb_dbal_migrator_tool_config_text_test extends phpbb_database_test_case $this->config_text->set('foo', 'bar'); $this->tool->remove('foo'); - $this->assertTrue(is_null($this->config_text->get('foo'))); + $this->assertNull($this->config_text->get('foo')); } public function test_reverse_add() @@ -66,7 +66,7 @@ class phpbb_dbal_migrator_tool_config_text_test extends phpbb_database_test_case $this->config_text->set('foo', 'bar'); $this->tool->reverse('add', 'foo'); - $this->assertTrue(is_null($this->config_text->get('foo'))); + $this->assertNull($this->config_text->get('foo')); } public function test_reverse_remove() -- cgit v1.2.1 From 5ef7510fb3c7dac8ef6e74c37c97e0efb59a4799 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 7 Jul 2014 12:50:18 -0700 Subject: [ticket/12812] Remove unused global $db from tests PHPBB3-12812 --- tests/dbal/migrator_tool_config_text_test.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_config_text_test.php b/tests/dbal/migrator_tool_config_text_test.php index f832105e00..b271c2d62e 100644 --- a/tests/dbal/migrator_tool_config_text_test.php +++ b/tests/dbal/migrator_tool_config_text_test.php @@ -20,11 +20,9 @@ class phpbb_dbal_migrator_tool_config_text_test extends phpbb_database_test_case public function setup() { - global $db; - parent::setup(); - $db = $this->db = $this->new_dbal(); + $this->db = $this->new_dbal(); $this->config_text = new \phpbb\config\db_text($this->db, 'phpbb_config_text'); $this->tool = new \phpbb\db\migration\tool\config_text($this->config_text); -- cgit v1.2.1 From 6b60153ab4ac036bcd4eaaa90806d9898fc1e9a2 Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Fri, 8 Aug 2014 15:06:12 +0200 Subject: [ticket/12671] Possibility to use NOT LIKE expression PHPBB3-12671 --- tests/dbal/select_test.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index e480716a49..ce07d7d0fb 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -233,6 +233,48 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } + public function not_like_expression_data() + { + // * = any_char; # = one_char + return array( + array('barfoo', array(array('username_clean' => 'bertie'), + array('username_clean' => 'foobar'))), + array('bar', array(array('username_clean' => 'bertie'),)), + array('bar*', array(array('username_clean' => 'bertie'), + array('username_clean' => 'foobar'))), + array('*bar*', array(array('username_clean' => 'bertie'))), + array('b*r', array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('b*e', array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('#b*e', array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array('b####e', array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + ); + } + + /** + * @dataProvider not_like_expression_data + */ + public function test_not_like_expression($like_expression, $expected) + { + $db = $this->new_dbal(); + + $like_expression = str_replace('*', $db->get_any_char(), $like_expression); + $like_expression = str_replace('#', $db->get_one_char(), $like_expression); + $where = ($like_expression) ? 'username_clean ' . $db->sql_not_like_expression($like_expression) : ''; + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + ' . (($where) ? ' WHERE ' . $where : '') . ' + ORDER BY user_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } + public function in_set_data() { return array( -- cgit v1.2.1 From 01943adbf72e137b9dfbda3ac85120c21a30fab8 Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Fri, 8 Aug 2014 18:32:17 +0200 Subject: [ticket/12671] Possibility to use NOT LIKE expression PHPBB3-12671 --- tests/dbal/select_test.php | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index ce07d7d0fb..50ac5eb4d5 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -237,20 +237,32 @@ class phpbb_dbal_select_test extends phpbb_database_test_case { // * = any_char; # = one_char return array( - array('barfoo', array(array('username_clean' => 'bertie'), - array('username_clean' => 'foobar'))), - array('bar', array(array('username_clean' => 'bertie'),)), - array('bar*', array(array('username_clean' => 'bertie'), - array('username_clean' => 'foobar'))), + array('barfoo', array( + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie')) + ), + array('bar', array(array('username_clean' => 'bertie'))), + array('bar*', array( + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie')) + ), array('*bar*', array(array('username_clean' => 'bertie'))), - array('b*r', array(array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar'))), - array('b*e', array(array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar'))), - array('#b*e', array(array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar'))), - array('b####e', array(array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar'))), + array('b*r', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar')) + ), + array('b*e', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar')) + ), + array('#b*e', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar')) + ), + array('b####e', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar')) + ), ); } -- cgit v1.2.1 From 4e4ea681be7939ba70db492331164ed024adae8e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 9 Aug 2014 08:33:15 +0200 Subject: [ticket/12710] Fix "ORA-00972: identifier is too long [972]" on oracle PHPBB3-12710 --- tests/dbal/db_tools_test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 6cc2f8ec0f..51f9daacfb 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -288,13 +288,13 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); // Create index over the column - $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_2')); - $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012_2', array('c_bug_12012_2', 'c_bool'))); - $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_2')); + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_2')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_2', array('c_bug_12012_2', 'c_bool'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_2')); - $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_3')); - $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012_3', array('c_bug_12012_2'))); - $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_3')); + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_3')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_3', array('c_bug_12012_2'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_3')); // Remove the column $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); -- cgit v1.2.1 From 4c06467777547d72a6ea936d024d85cae701189b Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Sat, 9 Aug 2014 12:26:11 +0200 Subject: [ticket/12671] Possibility to use NOT LIKE expression PHPBB3-12671 --- tests/dbal/select_test.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index 50ac5eb4d5..b7074552ba 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -239,9 +239,13 @@ class phpbb_dbal_select_test extends phpbb_database_test_case return array( array('barfoo', array( array('username_clean' => 'foobar'), - array('username_clean' => 'bertie')) - ), - array('bar', array(array('username_clean' => 'bertie'))), + array('username_clean' => 'bertie') + )), + array('bar', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'), + )), array('bar*', array( array('username_clean' => 'foobar'), array('username_clean' => 'bertie')) @@ -249,20 +253,22 @@ class phpbb_dbal_select_test extends phpbb_database_test_case array('*bar*', array(array('username_clean' => 'bertie'))), array('b*r', array( array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar')) - ), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie') + )), array('b*e', array( array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar')) - ), + array('username_clean' => 'foobar') + )), array('#b*e', array( array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar')) - ), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie') + )), array('b####e', array( array('username_clean' => 'barfoo'), - array('username_clean' => 'foobar')) - ), + array('username_clean' => 'foobar') + )), ); } -- cgit v1.2.1 From 8d99b4afe1557a6ec0e760c4876bb06a3b9991d3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 10 Aug 2014 13:40:27 +0200 Subject: [ticket/12932] Fix tests and calls to create_datetime PHPBB3-12932 --- tests/dbal/migrator_test.php | 2 +- tests/dbal/migrator_tool_module_test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 4a1d15aea4..10a9444d63 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -60,7 +60,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); - $user = new \phpbb\user(); + $user = new \phpbb\user('\phpbb\datetime'); $this->extension_manager = new \phpbb\extension\manager( $container, diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index aeb69e27ac..08c3e979b8 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -32,7 +32,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $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(); + $user = $this->user = new \phpbb\user('\phpbb\user'); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); -- cgit v1.2.1 From 46a9fe93d797bf7d56fd9b1e204f3c0459270122 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 14 Sep 2014 00:32:34 +0200 Subject: [ticket/13064] Validate the migrations provided to migrator::set_migrations() PHPBB3-13064 --- tests/dbal/migrator_test.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 10a9444d63..05e60a510b 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -118,9 +118,17 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); } - public function test_unfulfillable() + /** + * @expectedException \phpbb\db\migration\exception + */ + public function test_unfulfillable_exception() { $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy')); + } + + public function test_unfulfillable() + { + $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy'), false); while (!$this->migrator->finished()) { -- cgit v1.2.1 From 7729ae4ad0bb09256709af37f2998a0949fbad01 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Sep 2014 21:24:33 +0200 Subject: [ticket/13064] Revert "[ticket/13064] Validate the migrations provided to ..." This reverts commit 46a9fe93d797bf7d56fd9b1e204f3c0459270122. PHPBB3-13064 --- tests/dbal/migrator_test.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 05e60a510b..10a9444d63 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -118,17 +118,9 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->db_tools->sql_column_remove('phpbb_config', 'extra_column'); } - /** - * @expectedException \phpbb\db\migration\exception - */ - public function test_unfulfillable_exception() - { - $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy')); - } - public function test_unfulfillable() { - $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy'), false); + $this->migrator->set_migrations(array('phpbb_dbal_migration_unfulfillable', 'phpbb_dbal_migration_dummy')); while (!$this->migrator->finished()) { -- cgit v1.2.1 From 4df125625c7df93a5c3727a3cfd9517df4ba0ba6 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 14 Jan 2015 11:37:10 +0100 Subject: [ticket/13489] Fix tests PHPBB3-13489 --- tests/dbal/migrator_test.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 10a9444d63..4c4306888c 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -46,7 +46,10 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case new \phpbb\db\migration\tool\config($this->config), ); + $container = new phpbb_mock_container_builder(); + $this->migrator = new \phpbb\db\migrator( + $container, $this->config, $this->db, $this->db_tools, @@ -57,9 +60,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $tools, new \phpbb\db\migration\helper() ); - - $container = new phpbb_mock_container_builder(); - $container->set('migrator', $migrator); + $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( -- cgit v1.2.1 From eb4594d8ee6a662f6e268a8d802c8a7110cd55c7 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 22 Jan 2015 23:17:59 +0100 Subject: [ticket/13282] Add unit test for adding integer column with default null PHPBB3-13282 --- tests/dbal/db_tools_test.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 51f9daacfb..5832b966d8 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -415,4 +415,11 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->tools->sql_create_unique_index('prefix_table_name', 'i_uniq_ts_id', array('c_timestamp', 'c_id')); $this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', 'i_uniq_ts_id')); } + + public function test_create_int_default_null() + { + $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_13282')); + $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')); + } } -- cgit v1.2.1 From c221571963b5252c3343b6db3ace552e52104056 Mon Sep 17 00:00:00 2001 From: rxu Date: Sat, 6 Jun 2015 14:54:56 +0700 Subject: [ticket/13779] Add permission set tests PHPBB3-13779 --- tests/dbal/fixtures/migrator_permission.xml | 134 +++++++++++++++++++++++++++ tests/dbal/migrator_tool_permission_test.php | 62 +++++++++++++ 2 files changed, 196 insertions(+) (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/migrator_permission.xml b/tests/dbal/fixtures/migrator_permission.xml index 08cec42a42..c07956fa85 100644 --- a/tests/dbal/fixtures/migrator_permission.xml +++ b/tests/dbal/fixtures/migrator_permission.xml @@ -27,5 +27,139 @@ 1 0
+ + 4 + a_test + 1 + 0 + 0 + + + 5 + m_test + 1 + 0 + 0 + + + 6 + u_test + 1 + 0 + 0 + + + + + group_id + group_name + group_desc + + 2 + REGISTERED + + + + 4 + GLOBAL_MODERATORS + + + + 5 + ADMINISTRATORS + + +
+ + + group_id + auth_role_id + forum_id + + 2 + 5 + 0 + + + 4 + 5 + 0 + + + 4 + 10 + 0 + + + 5 + 1 + 0 + + + 5 + 5 + 0 + +
+ + + role_id + role_name + role_type + role_description + + 1 + ROLE_ADMIN_STANDARD + a_ + + + + 5 + ROLE_USER_FULL + u_ + + + + 10 + ROLE_MOD_FULL + m_ + + +
+ + + role_id + auth_option_id + auth_setting + + 1 + 4 + 0 + + + 1 + 5 + 0 + + + 1 + 6 + 0 + + + 6 + 6 + 0 + + + 10 + 5 + 0 + + + 10 + 6 + 0 +
diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php index 4453fbf123..2d673864f7 100644 --- a/tests/dbal/migrator_tool_permission_test.php +++ b/tests/dbal/migrator_tool_permission_test.php @@ -15,6 +15,12 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case { + public $group_ids = array( + 'REGISTERED' => 2, + 'GLOBAL_MODERATORS' => 4, + 'ADMINISTRATORS' => 5, + ); + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml'); @@ -158,4 +164,60 @@ 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() + { + return array( + array( + 'ADMINISTRATORS', + 'a_test', + 'group', + true, + ), + array( + 'GLOBAL_MODERATORS', + 'm_test', + 'group', + true, + ), + array( + 'REGISTERED', + 'u_test', + 'group', + true, + ), + ); + } + + /** + * @dataProvider test_permission_set_data + */ + public function test_permission_set($group_name, $auth_option, $type, $has_permission) + { + $this->tool->permission_set($group_name, $auth_option, $type, $has_permission); + $administrators_perm = $this->auth->acl_group_raw_data($this->group_ids['ADMINISTRATORS'], $auth_option); + $global_moderators_perm = $this->auth->acl_group_raw_data($this->group_ids['GLOBAL_MODERATORS'], $auth_option); + $registered_users_perm = $this->auth->acl_group_raw_data($this->group_ids['REGISTERED'], $auth_option); + + switch($group_name) + { + case 'GLOBAL_MODERATORS': + $this->assertEquals(false, empty($administrators_perm), 'm_test is not empty for Administrators'); + $this->assertEquals(false, empty($global_moderators_perm), 'm_test is not empty for Global moderators'); + $this->assertEquals(true, empty($registered_users_perm), 'm_test empty for Registered users'); + break; + + case 'ADMINISTRATORS': + $this->assertEquals(false, empty($administrators_perm), 'a_test is not empty for Administrators'); + $this->assertEquals(true, empty($global_moderators_perm), 'a_test is empty for Global moderators'); + $this->assertEquals(true, empty($registered_users_perm), 'a_test is empty for Registered users'); + break; + + case 'REGISTERED': + $this->assertEquals(false, empty($administrators_perm), 'u_test is not empty for Administrators'); + $this->assertEquals(false, empty($global_moderators_perm), 'u_test is not empty for Global moderators'); + $this->assertEquals(false, empty($registered_users_perm), 'u_test is not empty for Registered users'); + break; + } + } } -- cgit v1.2.1 From 8cf2790d5577f7e2398d5017216d3c5540cb0eb0 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 24 Jul 2016 00:24:32 +0700 Subject: [ticket/14703] Add test for the case multiple parent module_langname found PHPBB3-14703 --- tests/dbal/fixtures/migrator_module.xml | 54 +++++++++++++++++++++++++++++++- tests/dbal/migrator_tool_module_test.php | 34 ++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/migrator_module.xml b/tests/dbal/fixtures/migrator_module.xml index 32afe7e6f3..e172d7a145 100644 --- a/tests/dbal/fixtures/migrator_module.xml +++ b/tests/dbal/fixtures/migrator_module.xml @@ -20,7 +20,7 @@ acp 0 1 - 4 + 6 ACP_CAT @@ -38,5 +38,57 @@ test
+ + 3 + 1 + 1 + + acp + 1 + 4 + 5 + ACP_FORUM_BASED_PERMISSIONS + + + + + 4 + 1 + 1 + + acp + 0 + 7 + 12 + ACP_CAT_FORUMS + + + + + 5 + 1 + 1 + + acp + 4 + 8 + 11 + ACP_FORUM_BASED_PERMISSIONS + + + + + 6 + 1 + 1 + + acp + 5 + 9 + 10 + ACP_FORUM_BASED_PERMISSIONS_CHILD_1 + + + diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 08c3e979b8..bf4ae0b1ee 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -118,6 +118,40 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $this->fail($e); } $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE')); + + // 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) {} + + // Test adding module when plural parent module_langname exists + // PHPBB3-14703 + // Adding success + 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' => '', + 'after' => 'ACP_FORUM_BASED_PERMISSIONS_CHILD_1', + )); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 'ACP_FORUM_BASED_PERMISSIONS', 'ACP_NEW_PERMISSIONS_MODULE')); } public function test_remove() -- cgit v1.2.1 From c12d67cd900514f9752d7bb73928870dbab0a0ce Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Thu, 11 Aug 2016 18:11:39 +0200 Subject: [ticket/14742] Add test for (not) reverting if PHPBB3-14742 --- tests/dbal/migration/if.php | 4 ++-- tests/dbal/migrator_test.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php index 98a66526ed..481250ea77 100644 --- a/tests/dbal/migration/if.php +++ b/tests/dbal/migration/if.php @@ -36,13 +36,13 @@ class phpbb_dbal_migration_if extends \phpbb\db\migration\migration { global $migrator_test_if_true_failed; - $migrator_test_if_true_failed = false; + $migrator_test_if_true_failed = !$migrator_test_if_true_failed; } function test_false() { global $migrator_test_if_false_failed; - $migrator_test_if_false_failed = true; + $migrator_test_if_false_failed = !$migrator_test_if_false_failed; } } diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 4c4306888c..798200eef1 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -156,6 +156,14 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->assertFalse($migrator_test_if_true_failed, 'True test failed'); $this->assertFalse($migrator_test_if_false_failed, 'False test failed'); + + while ($this->migrator->migration_state('phpbb_dbal_migration_if') !== false) + { + $this->migrator->revert('phpbb_dbal_migration_if'); + } + + $this->assertFalse($migrator_test_if_true_failed, 'True test after revert failed'); + $this->assertFalse($migrator_test_if_false_failed, 'False test after revert failed'); } public function test_recall() -- cgit v1.2.1 From 557f85e7fc3dc299859e846a8f406f0e19aaf465 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 28 Aug 2016 21:36:49 +0700 Subject: [ticket/14703] Improve exception testing PHPBB3-14703 --- tests/dbal/migrator_tool_module_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index bf4ae0b1ee..49dff8b929 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -132,7 +132,11 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case )); $this->fail('Exception not thrown'); } - catch (Exception $e) {} + 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 -- cgit v1.2.1 From 51ef1ae346c08863d188e723ba41720e744a2fbd Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 23 Oct 2016 22:44:47 +0700 Subject: [ticket/14831] Add more tests, better name for $e placeholder PHPBB3-14831 --- tests/dbal/migrator_tool_module_test.php | 59 +++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'tests/dbal') diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 49dff8b929..462b521f1a 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -42,10 +42,10 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $this->tool = new \phpbb\db\migration\tool\module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); } - public function exists_data() + public function exists_data_acp() { return array( - // Test the category + // Test the existing category array( '', 'ACP_CAT', @@ -57,7 +57,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case true, ), - // Test the module + // Test the existing module array( '', 'ACP_MODULE', @@ -73,11 +73,23 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case 'ACP_MODULE', true, ), + + // Test for non-existant modules + array( + '', + 'ACP_NON_EXISTANT_CAT', + false, + ), + array( + 'ACP_CAT', + 'ACP_NON_EXISTANT_MODULE', + false, + ), ); } /** - * @dataProvider exists_data + * @dataProvider exists_data_acp */ public function test_exists($parent, $module, $expected) { @@ -156,6 +168,45 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $this->fail($e); } $this->assertEquals(true, $this->tool->exists('acp', 'ACP_FORUM_BASED_PERMISSIONS', 'ACP_NEW_PERMISSIONS_MODULE')); + + // Test adding UCP modules + // Test adding new UCP category + try + { + $this->tool->add('ucp', 0, 'UCP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('ucp', 0, 'UCP_NEW_CAT')); + + // Test adding new UCP subcategory + try + { + $this->tool->add('ucp', 'UCP_NEW_CAT', 'UCP_NEW_SUBCAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('ucp', 'UCP_NEW_CAT', 'UCP_NEW_SUBCAT')); + + // Test adding new UCP module + try + { + $this->tool->add('ucp', 'UCP_NEW_SUBCAT', array( + 'module_basename' => 'ucp_new_module', + 'module_langname' => 'UCP_NEW_MODULE', + 'module_mode' => 'ucp_test', + 'module_auth' => '', + )); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('ucp', 'UCP_NEW_SUBCAT', 'UCP_NEW_MODULE')); } public function test_remove() -- cgit v1.2.1 From 849cd74700bc1425245ae9a8c5ec5f126d7a61ff Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 23 Oct 2016 23:33:03 +0700 Subject: [ticket/14831] Add more tests against UCP modules PHPBB3-14831 --- tests/dbal/fixtures/migrator_module.xml | 39 ++++++++++++++++++++ tests/dbal/migrator_tool_module_test.php | 61 +++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) (limited to 'tests/dbal') diff --git a/tests/dbal/fixtures/migrator_module.xml b/tests/dbal/fixtures/migrator_module.xml index e172d7a145..e85c43ee25 100644 --- a/tests/dbal/fixtures/migrator_module.xml +++ b/tests/dbal/fixtures/migrator_module.xml @@ -90,5 +90,44 @@
+ + 7 + 1 + 1 + + ucp + 0 + 13 + 18 + UCP_MAIN_CAT + + + + + 8 + 1 + 1 + ucp_subcat + ucp + 7 + 14 + 17 + UCP_SUBCATEGORY + ucp_test + + + + 9 + 1 + 1 + ucp_module + ucp + 8 + 15 + 16 + UCP_MODULE + ucp_module_test + + diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 462b521f1a..bbe543f347 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -91,11 +91,70 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case /** * @dataProvider exists_data_acp */ - public function test_exists($parent, $module, $expected) + public function test_exists_acp($parent, $module, $expected) { $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module)); } + public function exists_data_ucp() + { + return array( + // Test the existing category + array( + '', + 'UCP_MAIN_CAT', + true, + ), + array( + 0, + 'UCP_MAIN_CAT', + true, + ), + + // Test the existing module + array( + '', + 'UCP_SUBCATEGORY', + false, + ), + array( + false, + 'UCP_SUBCATEGORY', + true, + ), + array( + 'UCP_MAIN_CAT', + 'UCP_SUBCATEGORY', + true, + ), + array( + 'UCP_SUBCATEGORY', + 'UCP_MODULE', + true, + ), + + // Test for non-existant modules + array( + '', + 'UCP_NON_EXISTANT_CAT', + false, + ), + array( + 'UCP_MAIN_CAT', + 'UCP_NON_EXISTANT_MODULE', + false, + ), + ); + } + + /** + * @dataProvider exists_data_ucp + */ + public function test_exists_ucp($parent, $module, $expected) + { + $this->assertEquals($expected, $this->tool->exists('ucp', $parent, $module)); + } + public function test_add() { try -- cgit v1.2.1