From 59ef2c8fce0be3cc2f0ce1caf8a514725d03c790 Mon Sep 17 00:00:00 2001 From: rxu Date: Sun, 6 Jul 2025 14:53:13 +0700 Subject: [PATCH] [ticket/17507] Add remove_jabber migration test PHPBB-17507 --- .../fixtures/migration_remove_jabber.xml | 284 ++++++++++++++++++ .../remove_jabber_migration_test.php | 184 ++++++++++++ 2 files changed, 468 insertions(+) create mode 100644 tests/migrations/fixtures/migration_remove_jabber.xml create mode 100644 tests/migrations/remove_jabber_migration_test.php diff --git a/tests/migrations/fixtures/migration_remove_jabber.xml b/tests/migrations/fixtures/migration_remove_jabber.xml new file mode 100644 index 0000000000..452c7fb40b --- /dev/null +++ b/tests/migrations/fixtures/migration_remove_jabber.xml @@ -0,0 +1,284 @@ + + + + migration_name + migration_depends_on + migration_schema_done + migration_data_done + migration_data_state + migration_start_time + migration_end_time +
+ + config_name + config_value + + jab_enable + 1 + + + jab_host + + + + jab_package_size + 0 + + + jab_password + + + + jab_port + + + + jab_use_ssl + + + + jab_username + user + + + jab_verify_peer + 0 + + + jab_verify_peer_name + 0 + + + jab_allow_self_signed + 0 + +
+ + 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 + 76 + ACP_CAT_GENERAL + + + + + 4 + 1 + 1 + + acp + 0 + 48 + 59 + ACP_CLIENT_COMMUNICATION + + + + + 75 + 1 + 1 + acp_jabber + acp + 4 + 53 + 54 + ACP_JABBER_SETTINGS + settings + acl_a_jabber + +
+ + auth_option_id + auth_option + is_global + is_local + founder_only + + 70 + a_jabber + 1 + 0 + 0 + + + 121 + u_sendim + 1 + 0 + 0 + +
+ + group_id + forum_id + auth_option_id + auth_role_id + auth_setting +
+ + role_id + auth_option_id + auth_setting + + 4 + 70 + 1 + + + 5 + 121 + 1 + + + 6 + 121 + 1 + +
+ + user_id + forum_id + auth_option_id + auth_role_id + auth_setting +
+ + id + item_type + item_id + user_id + method + notify + + 1 + notification.type.post + 0 + 2 + notification.method.jabber + 1 + + + 2 + notification.type.post + 0 + 3 + notification.method.jabber + 1 + + + 3 + notification.type.post + 0 + 4 + notification.method.jabber + 1 + + + 4 + notification.type.post + 0 + 5 + notification.method.jabber + 1 + + + 5 + notification.type.post + 0 + 6 + notification.method.jabber + 1 + + + 6 + notification.type.post + 0 + 7 + notification.method.jabber + 1 + + + 7 + notification.type.post + 0 + 8 + notification.method.jabber + 1 + + + 8 + notification.type.forum + 0 + 2 + notification.method.jabber + 1 + + + 9 + notification.type.forum + 0 + 3 + notification.method.jabber + 1 + + + 10 + notification.type.forum + 0 + 4 + notification.method.jabber + 1 + + + 11 + notification.type.forum + 0 + 5 + notification.method.jabber + 1 + + + 12 + notification.type.forum + 0 + 6 + notification.method.jabber + 1 + + + 13 + notification.type.forum + 0 + 7 + notification.method.jabber + 1 + + + 14 + notification.type.forum + 0 + 8 + notification.method.jabber + 1 + +
+ +
diff --git a/tests/migrations/remove_jabber_migration_test.php b/tests/migrations/remove_jabber_migration_test.php new file mode 100644 index 0000000000..c18b6ca754 --- /dev/null +++ b/tests/migrations/remove_jabber_migration_test.php @@ -0,0 +1,184 @@ + +* @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_migrations_remove_jabber_migration_test extends phpbb_database_test_case +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \Doctrine\DBAL\Connection */ + protected $doctrine_db; + + /** @var \phpbb\db\tools\tools_interface */ + protected $db_tools; + + /** @var \phpbb\db\migrator */ + protected $migrator; + + /** @var \phpbb\config\config */ + protected $config; + + /** @var \phpbb\extension\manager */ + protected $extension_manager; + + public function getDataSet() + { + return $this->createXMLDataSet(__DIR__.'/fixtures/migration_remove_jabber.xml'); + } + + protected function setUp(): void + { + global $cache, $db, $phpbb_log, $phpbb_root_path, $phpEx, $skip_add_log, $table_prefix, $user; + + parent::setUp(); + + // Disable the logs + $skip_add_log = true; + + $db = $this->db = $this->new_dbal(); + $this->doctrine_db = $this->new_doctrine_dbal(); + $factory = new \phpbb\db\tools\factory(); + $this->db_tools = $factory->get($this->doctrine_db); + $this->db_tools->set_table_prefix($table_prefix); + $this->cache = new phpbb_mock_cache(); + $this->auth = new \phpbb\auth\auth(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $cache = $this->cache_service = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), new \phpbb\config\config(array()), $this->db, $phpbb_dispatcher, $phpbb_root_path, $phpEx); + + $this->config = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); + $this->config->initialise($this->cache); + + $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); + $lang = new \phpbb\language\language($lang_loader); + $user = $this->user = new \phpbb\user($lang, '\phpbb\datetime'); + + $phpbb_log = new \phpbb\log\log($this->db, $this->user, $this->auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + + $container = new phpbb_mock_container_builder(); + $container->set('event_dispatcher', $phpbb_dispatcher); + + $finder_factory = $this->createMock('\phpbb\finder\factory'); + $this->extension_manager = new \phpbb\extension\manager( + $container, + $this->db, + $this->config, + $finder_factory, + 'phpbb_ext', + __DIR__ . '/../../phpBB/', + null + ); + + $module_manager = new \phpbb\module\module_manager($this->cache, $this->db, $this->extension_manager, 'phpbb_modules', $phpbb_root_path, $phpEx); + + $tools = array( + new \phpbb\db\migration\tool\config($this->config), + new \phpbb\db\migration\tool\module($this->db, $this->user, $module_manager, 'phpbb_modules'), + new \phpbb\db\migration\tool\permission($this->db, $this->cache_service, $this->auth, $phpbb_root_path, $phpEx), + ); + + $this->migrator = new \phpbb\db\migrator( + $container, + $this->config, + $this->db, + $this->db_tools, + 'phpbb_migrations', + __DIR__ . '/../../phpBB/', + 'php', + 'phpbb_', + self::get_core_tables(), + $tools, + new \phpbb\db\migration\helper() + ); + $container->set('migrator', $this->migrator); + + $remove_jabber_migration = $this->migrator->get_migration('\phpbb\db\migration\data\v400\remove_jabber'); + $depends = $remove_jabber_migration->depends_on(); + $this->migrator->populate_migrations($depends); + } + + public function test_remove_jabber_migration() + { + $sql = "SELECT id FROM phpbb_user_notifications + WHERE method = 'notification.method.jabber'"; + $result = $this->db->sql_query($sql); + $rowset = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + $this->assertEquals(14, count($rowset)); + + $sql = "SELECT config_name FROM phpbb_config + WHERE config_name = 'jab_enable'"; + $this->assertNotFalse($this->db->sql_query($sql)); + + $sql = "SELECT auth_option FROM phpbb_acl_options + WHERE auth_option = 'a_jabber'"; + $this->assertNotFalse($this->db->sql_query($sql)); + + $this->migrator->set_migrations(['\phpbb\db\migration\data\v400\remove_jabber']); + + while (!$this->migrator->finished()) + { + try + { + $this->migrator->update(); + } + catch (\phpbb\db\migration\exception $e) + { + $this->fail('Applying migration error: ' . $e->__toString()); + } + } + + $sql = "SELECT id FROM phpbb_user_notifications + WHERE method = 'notification.method.jabber'"; + $this->db->sql_query($sql); + $this->assertFalse($this->db->sql_fetchfield('id')); + + $sql = "SELECT id FROM phpbb_user_notifications + WHERE method = 'notification.method.email'"; + $result = $this->db->sql_query($sql); + $rowset = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + $this->assertEquals(14, count($rowset)); + + $sql = "SELECT config_name FROM phpbb_config + WHERE config_name = 'jab_enable'"; + $this->db->sql_query($sql); + $this->assertFalse($this->db->sql_fetchfield('config_name')); + + $sql = "SELECT auth_option FROM phpbb_acl_options + WHERE auth_option = 'a_jabber'"; + $this->db->sql_query($sql); + $this->assertFalse($this->db->sql_fetchfield('auth_option')); + + while ($this->migrator->migration_state('\phpbb\db\migration\data\v400\remove_jabber')) + { + try + { + $this->migrator->revert('\phpbb\db\migration\data\v400\remove_jabber'); + } + catch (\phpbb\db\migration\exception $e) + { + $this->fail('Reverting migration error: ' . $e->__toString()); + } + } + + $sql = "SELECT config_name FROM phpbb_config + WHERE config_name = 'jab_enable'"; + $this->db->sql_query($sql); + $this->assertEquals('jab_enable', $this->db->sql_fetchfield('config_name')); + + $sql = "SELECT auth_option FROM phpbb_acl_options + WHERE auth_option = 'a_jabber'"; + $this->db->sql_query($sql); + $this->assertEquals('a_jabber', $this->db->sql_fetchfield('auth_option')); + } +}