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') 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') 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