From f131e31bc781b14a47dd1b4ba919b7bf4322e309 Mon Sep 17 00:00:00 2001 From: rxu Date: Thu, 25 Sep 2025 21:21:44 +0700 Subject: [PATCH] [ticket/17543] Optimize installing extensions Make several functions static to be able to use in *BeforeClass() methods. PHPBB-17543 --- tests/functional/acp_permissions_test.php | 1 + tests/functional/download_test.php | 2 - .../functional/extension_controller_test.php | 25 +- tests/functional/extension_module_test.php | 22 +- .../extension_template_event_order_test.php | 28 +- tests/functional/feed_test.php | 2 - tests/functional/metadata_manager_test.php | 18 +- tests/functional/prune_shadow_topic_test.php | 5 - tests/functional/subforum_test.php | 1 - tests/functional/ucp_groups_test.php | 6 - tests/functional/user_password_reset_test.php | 11 - tests/functional/viewforum_paging_test.php | 4 - .../functional/visibility_disapprove_test.php | 4 - .../functional/visibility_reapprove_test.php | 4 - .../functional/visibility_softdelete_test.php | 4 - .../visibility_unapproved_posts_test.php | 4 - .../phpbb_functional_test_case.php | 291 +++++++++--------- 17 files changed, 177 insertions(+), 255 deletions(-) diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index fb092a7ff1..355dd1a21d 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -98,6 +98,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case // XXX globals for \phpbb\auth\auth, refactor it later global $db, $cache; $db = $this->get_db(); + $cache = new phpbb_mock_null_cache; $auth = new \phpbb\auth\auth; diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php index df2a7cbb26..ec67e9e42a 100644 --- a/tests/functional/download_test.php +++ b/tests/functional/download_test.php @@ -225,8 +225,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case public function load_ids($data) { - $this->db = $this->get_db(); - if (!empty($data['forums'])) { array_walk($data['forums'], function(&$value, $key) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 451565c186..b5ccbf2bcf 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -22,26 +22,26 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c './', ); - static public function setUpBeforeClass(): void + public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); self::$helper = new phpbb_test_case_helpers(__CLASS__); self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures); + + self::install_ext('foo/bar'); + self::install_ext('foo/foo'); } - static public function tearDownAfterClass(): void + public static function tearDownAfterClass(): void { parent::tearDownAfterClass(); + self::uninstall_ext('foo/bar'); + self::uninstall_ext('foo/foo'); self::$helper->restore_original_ext_dir(); } - protected static function setup_extensions() - { - return self::$tests_count == self::$tests_number ? ['foo/bar', 'foo/foo'] : []; - } - protected function setUp(): void { parent::setUp(); @@ -49,17 +49,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $this->purge_cache(); } - protected function tearDown(): void - { - if (self::$tests_count == 1) - { - $this->uninstall_ext('foo/bar'); - $this->uninstall_ext('foo/foo'); - } - - parent::tearDown(); - } - /** * Check a controller for extension foo/bar. */ diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index cc7f5b1605..9f7f44fb9d 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -23,36 +23,24 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case './', ); - static public function setUpBeforeClass(): void + public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); self::$helper = new phpbb_test_case_helpers(__CLASS__); self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures); + + self::install_ext('foo/bar'); } - static public function tearDownAfterClass(): void + public static function tearDownAfterClass(): void { parent::tearDownAfterClass(); + self::uninstall_ext('foo/bar'); self::$helper->restore_original_ext_dir(); } - protected function tearDown(): void - { - if (self::$tests_count == 1) - { - $this->uninstall_ext('foo/bar'); - } - - parent::tearDown(); - } - - protected static function setup_extensions() - { - return self::$tests_count == self::$tests_number ? ['foo/bar'] : []; - } - public function test_acp() { $this->add_lang('common'); diff --git a/tests/functional/extension_template_event_order_test.php b/tests/functional/extension_template_event_order_test.php index 596f46ca3e..c32e9442b8 100644 --- a/tests/functional/extension_template_event_order_test.php +++ b/tests/functional/extension_template_event_order_test.php @@ -16,24 +16,29 @@ */ class phpbb_functional_extension_template_event_order_test extends phpbb_functional_test_case { - static private $helper; + private static $helper; - static protected $fixtures = [ + protected static $fixtures = [ './', ]; - static public function setUpBeforeClass(): void + public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); self::$helper = new phpbb_test_case_helpers(__CLASS__); self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures); + + self::install_ext('foo/bar'); + self::install_ext('foo/foo'); } - static public function tearDownAfterClass(): void + public static function tearDownAfterClass(): void { parent::tearDownAfterClass(); + self::uninstall_ext('foo/bar'); + self::uninstall_ext('foo/foo'); self::$helper->restore_original_ext_dir(); } @@ -44,21 +49,6 @@ class phpbb_functional_extension_template_event_order_test extends phpbb_functio $this->purge_cache(); } - protected function tearDown(): void - { - if (self::$tests_count == 1) - { - $this->uninstall_ext('foo/bar'); - $this->uninstall_ext('foo/foo'); - } - - parent::tearDown(); - } - - protected static function setup_extensions() - { - return self::$tests_count == self::$tests_number ? ['foo/bar', 'foo/foo'] : []; - } /** * Check extensions template event listener prioritizing diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php index a225cf3f56..16f4f2f779 100644 --- a/tests/functional/feed_test.php +++ b/tests/functional/feed_test.php @@ -1450,8 +1450,6 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case protected function load_ids($data) { - $this->db = $this->get_db(); - if (!empty($data['forums'])) { $sql = 'SELECT * diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index f74252d7df..9744bf08a7 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -22,28 +22,21 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case './', ); - protected function tearDown(): void - { - if (self::$tests_count == 1) - { - $this->uninstall_ext('foo/bar'); - } - - parent::tearDown(); - } - public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); self::$helper = new phpbb_test_case_helpers(__CLASS__); self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures); + + self::install_ext('foo/bar'); } public static function tearDownAfterClass(): void { parent::tearDownAfterClass(); + self::uninstall_ext('foo/bar'); self::$helper->restore_original_ext_dir(); } @@ -56,11 +49,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $this->add_lang('acp/extensions'); } - protected static function setup_extensions() - { - return self::$tests_count == self::$tests_number ? ['foo/bar'] : []; - } - public function test_extensions_list() { $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); diff --git a/tests/functional/prune_shadow_topic_test.php b/tests/functional/prune_shadow_topic_test.php index 366ddf0af6..125c3b90b9 100644 --- a/tests/functional/prune_shadow_topic_test.php +++ b/tests/functional/prune_shadow_topic_test.php @@ -121,7 +121,6 @@ class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_cas 'forum_topics_softdeleted' => 0, ), 'after moving'); - $this->db = $this->get_db(); // Date topic 3 days back $sql = 'UPDATE phpbb_topics SET topic_last_post_time = ' . (time() - 60*60*24*3) . ' @@ -153,8 +152,6 @@ class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_cas public function assert_forum_details($forum_id, $details, $additional_error_message = '') { - $this->db = $this->get_db(); - $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' FROM phpbb_forums WHERE forum_id = ' . (int) $forum_id; @@ -167,8 +164,6 @@ class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_cas public function load_ids($data) { - $this->db = $this->get_db(); - if (!empty($data['forums'])) { $sql = 'SELECT * diff --git a/tests/functional/subforum_test.php b/tests/functional/subforum_test.php index 493c2053da..91a7e77754 100644 --- a/tests/functional/subforum_test.php +++ b/tests/functional/subforum_test.php @@ -91,7 +91,6 @@ class phpbb_functional_subforum_test extends phpbb_functional_test_case protected function get_forum_id($forum_name) { - $this->db = $this->get_db(); $forum_id = 0; $sql = 'SELECT * diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index 387ae827e4..6e18d610ce 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -18,8 +18,6 @@ require_once __DIR__ . '/common_groups_test_case.php'; */ class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test_case { - protected $db; - protected function get_url() { return 'ucp.php?i=groups&mode=manage&action=edit'; @@ -27,10 +25,6 @@ class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_te protected function get_teampage_settings() { - if (!isset($this->db)) - { - $this->db = $this->get_db(); - } $sql = 'SELECT g.group_legend AS group_legend, t.teampage_position AS group_teampage FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . TEAMPAGE_TABLE . ' t diff --git a/tests/functional/user_password_reset_test.php b/tests/functional/user_password_reset_test.php index 09c833fe03..b9f1ad4fd6 100644 --- a/tests/functional/user_password_reset_test.php +++ b/tests/functional/user_password_reset_test.php @@ -153,17 +153,6 @@ class phpbb_functional_user_password_reset_test extends phpbb_functional_test_ca $crawler = self::submit($form, array('username' => self::TEST_USER, 'password' => self::TEST_USER)); $this->assertStringNotContainsString($this->lang('LOGIN'), $crawler->filter('.navbar')->text()); - $cookies = self::$cookieJar->all(); - - // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie - foreach ($cookies as $cookie) - { - if (substr($cookie->getName(), -4) == '_sid') - { - $this->sid = $cookie->getValue(); - } - } - $this->logout(); $crawler = self::request('GET', 'ucp.php'); diff --git a/tests/functional/viewforum_paging_test.php b/tests/functional/viewforum_paging_test.php index 2ba29cecc6..0a2cd38b3a 100644 --- a/tests/functional/viewforum_paging_test.php +++ b/tests/functional/viewforum_paging_test.php @@ -163,8 +163,6 @@ class viewforum_paging_test extends phpbb_functional_test_case protected function assert_forum_details($forum_id, $details, $additional_error_message = '') { - $this->db = $this->get_db(); - $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' FROM phpbb_forums WHERE forum_id = ' . (int) $forum_id; @@ -203,8 +201,6 @@ class viewforum_paging_test extends phpbb_functional_test_case */ protected function load_ids($data) { - $this->db = $this->get_db(); - if (!empty($data['forums'])) { $sql = 'SELECT * diff --git a/tests/functional/visibility_disapprove_test.php b/tests/functional/visibility_disapprove_test.php index f853491414..95b371ac4f 100644 --- a/tests/functional/visibility_disapprove_test.php +++ b/tests/functional/visibility_disapprove_test.php @@ -243,8 +243,6 @@ class phpbb_functional_visibility_disapprove_test extends phpbb_functional_test_ protected function assert_forum_details($forum_id, $details, $additional_error_message = '') { - $this->db = $this->get_db(); - $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' FROM phpbb_forums WHERE forum_id = ' . (int) $forum_id; @@ -257,8 +255,6 @@ class phpbb_functional_visibility_disapprove_test extends phpbb_functional_test_ protected function load_ids($data) { - $this->db = $this->get_db(); - if (!empty($data['forums'])) { $sql = 'SELECT * diff --git a/tests/functional/visibility_reapprove_test.php b/tests/functional/visibility_reapprove_test.php index c9da0942b4..af0f553c0a 100644 --- a/tests/functional/visibility_reapprove_test.php +++ b/tests/functional/visibility_reapprove_test.php @@ -339,8 +339,6 @@ class phpbb_functional_visibility_reapprove_test extends phpbb_functional_test_c protected function assert_forum_details($forum_id, $details, $additional_error_message = '') { - $this->db = $this->get_db(); - $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' FROM phpbb_forums WHERE forum_id = ' . (int) $forum_id; @@ -353,8 +351,6 @@ class phpbb_functional_visibility_reapprove_test extends phpbb_functional_test_c protected function load_ids($data) { - $this->db = $this->get_db(); - if (!empty($data['forums'])) { $sql = 'SELECT * diff --git a/tests/functional/visibility_softdelete_test.php b/tests/functional/visibility_softdelete_test.php index 0275ea42ca..9e8d29ab62 100644 --- a/tests/functional/visibility_softdelete_test.php +++ b/tests/functional/visibility_softdelete_test.php @@ -783,8 +783,6 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ public function assert_forum_details($forum_id, $details, $additional_error_message = '') { - $this->db = $this->get_db(); - $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' FROM phpbb_forums WHERE forum_id = ' . (int) $forum_id; @@ -797,8 +795,6 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_ public function load_ids($data) { - $this->db = $this->get_db(); - if (!empty($data['forums'])) { $sql = 'SELECT * diff --git a/tests/functional/visibility_unapproved_posts_test.php b/tests/functional/visibility_unapproved_posts_test.php index 7c14b10a90..2d01937981 100644 --- a/tests/functional/visibility_unapproved_posts_test.php +++ b/tests/functional/visibility_unapproved_posts_test.php @@ -256,8 +256,6 @@ class phpbb_functional_visibility_unapproved_posts_test extends phpbb_functional protected function assert_forum_details($forum_id, $details, $additional_error_message = '') { - $this->db = $this->get_db(); - $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' FROM phpbb_forums WHERE forum_id = ' . (int) $forum_id; @@ -270,8 +268,6 @@ class phpbb_functional_visibility_unapproved_posts_test extends phpbb_functional protected function load_ids($data) { - $this->db = $this->get_db(); - if (!empty($data['forums'])) { $sql = 'SELECT forum_id, forum_name diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5b3ec5c667..980f397a2a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -30,7 +30,6 @@ class phpbb_functional_test_case extends phpbb_test_case protected static $install_success = false; protected $cache = null; - protected $db = null; protected $db_doctrine = null; protected $extension_manager = null; @@ -38,20 +37,39 @@ class phpbb_functional_test_case extends phpbb_test_case * Session ID for current test's session (each test makes its own) * @var string */ - protected $sid; + protected static $session_id; /** * Language array used by phpBB * @var array */ - protected $lang = array(); + protected static $lang_ary = []; protected static $config = array(); protected static $already_installed = false; - protected static $tests_count = 0; - protected static $tests_number = 0; + protected static $db_connection = null; - static public function setUpBeforeClass(): void + public function __get($property) + { + if ($property === 'sid') + { + return self::$session_id ??= null; + } + + if ($property === 'db') + { + return self::$db_connection ??= null; + } + + if ($property === 'lang') + { + return self::$lang_ary; + } + + return null; + } + + public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); @@ -76,11 +94,15 @@ class phpbb_functional_test_case extends phpbb_test_case self::$already_installed = true; } - self::$tests_number = self::$tests_count = count(array_filter(get_class_methods(static::class), function($val) - { - return str_starts_with($val, 'test_'); - }) - ); + global $cache; + $cache = new phpbb_mock_null_cache; + self::get_db(); + + // Special flag for testing without possibility to run into lock scenario. + // Unset entry and add it back if lock behavior for posting should be tested. + // Unset ci_tests_no_lock_posting from config + $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value) VALUES ('ci_tests_no_lock_posting', '1')"; + self::$db_connection->sql_query($sql); } /** @@ -116,52 +138,32 @@ class phpbb_functional_test_case extends phpbb_test_case // Clear the language array so that things // that were added in other tests are gone - $this->lang = array(); - $this->add_lang('common'); - - $this->get_db(); - - // Special flag for testing without possibility to run into lock scenario. - // Unset entry and add it back if lock behavior for posting should be tested. - // Unset ci_tests_no_lock_posting from config - $this->db->sql_return_on_error(true); - $sql = 'INSERT INTO ' . CONFIG_TABLE . " (config_name, config_value) VALUES ('ci_tests_no_lock_posting', '1')"; - $this->db->sql_query($sql); - $this->db->sql_return_on_error(false); + self::$lang_ary = []; + self::add_lang('common'); foreach (static::setup_extensions() as $extension) { - $this->purge_cache(); - - $sql = 'SELECT ext_active - FROM ' . EXT_TABLE . " - WHERE ext_name = '" . $this->db->sql_escape($extension). "'"; - $result = $this->db->sql_query($sql); - $status = (bool) $this->db->sql_fetchfield('ext_active'); - $this->db->sql_freeresult($result); - - if (!$status) - { - $this->install_ext($extension); - } + self::install_ext($extension); } } - protected function tearDown(): void + public static function tearDownAfterClass(): void { - parent::tearDown(); + parent::tearDownAfterClass(); - self::$tests_count--; + global $cache; + $cache = new phpbb_mock_null_cache; - if (self::$tests_count === 0 && $this->db instanceof \phpbb\db\driver\driver_interface) + if (self::$db_connection instanceof \phpbb\db\driver\driver_interface) { // Unset ci_tests_no_lock_posting from config $sql = 'DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'ci_tests_no_lock_posting'"; - $this->db->sql_query($sql); + self::$db_connection->sql_query($sql); // Close the database connections again this test - $this->db->sql_close(); + self::$db_connection->sql_close(); + self::$db_connection = null; } } @@ -174,7 +176,7 @@ class phpbb_functional_test_case extends phpbb_test_case * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ - static public function request($method, $path, $form_data = array(), $assert_response_html = true) + public static function request($method, $path, $form_data = array(), $assert_response_html = true) { $crawler = self::$client->request($method, self::$root_url . $path, $form_data); @@ -194,7 +196,7 @@ class phpbb_functional_test_case extends phpbb_test_case * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ - static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_html = true) + public static function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_html = true) { // Remove files from form if no file was submitted // See: https://github.com/symfony/symfony/issues/49014 @@ -221,7 +223,7 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return string HTML page */ - static public function get_content() + public static function get_content() { return (string) self::$client->getResponse()->getContent(); } @@ -236,17 +238,18 @@ class phpbb_functional_test_case extends phpbb_test_case /** * @return \phpbb\db\driver\driver_interface */ - protected function get_db() + protected static function get_db() { global $phpbb_root_path, $phpEx; // so we don't reopen an open connection - if (!($this->db instanceof \phpbb\db\driver\driver_interface)) + if (!(self::$db_connection instanceof \phpbb\db\driver\driver_interface)) { $dbms = self::$config['dbms']; - $this->db = new $dbms(); - $this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport'], true); + self::$db_connection = new $dbms(); + self::$db_connection->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport'], true); } - return $this->db; + + return self::$db_connection; } protected function get_db_doctrine() @@ -608,58 +611,69 @@ class phpbb_functional_test_case extends phpbb_test_case } } - public function install_ext($extension) + public static function install_ext($extension) { - $this->add_lang('acp/extensions'); + self::get_db(); + $sql = 'SELECT ext_active + FROM ' . EXT_TABLE . " + WHERE ext_name = '" . self::$db_connection->sql_escape($extension). "'"; + $result = self::$db_connection->sql_query($sql); + $status = (bool) self::$db_connection->sql_fetchfield('ext_active'); + self::$db_connection->sql_freeresult($result); - if ($this->get_logged_in_user()) + if (!$status) { - $this->logout(); - } - $this->login(); - $this->admin_login(); + self::add_lang('acp/extensions'); - $ext_path = str_replace('/', '%2F', $extension); + if (self::get_logged_in_user()) + { + self::logout(); + } + self::login(); + self::admin_login(); - $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid); - $this->assertGreaterThan(1, $crawler->filter('div.main fieldset.submit-buttons input')->count()); + $ext_path = str_replace('/', '%2F', $extension); - $form = $crawler->selectButton($this->lang('EXTENSION_ENABLE'))->form(); - $crawler = self::submit($form); + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=' . $ext_path . '&sid=' . self::$session_id); + self::assertGreaterThan(1, $crawler->filter('div.main fieldset.submit-buttons input')->count()); - $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); + $form = $crawler->selectButton(self::lang('EXTENSION_ENABLE'))->form(); + $crawler = self::submit($form); - // Wait for extension to be fully enabled - while (count($meta_refresh)) - { - preg_match('#url=.+/(adm+.+)#', $meta_refresh->attr('content'), $match); - $url = $match[1]; - $crawler = self::request('POST', $url); $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); + + // Wait for extension to be fully enabled + while (count($meta_refresh)) + { + preg_match('#url=.+/(adm+.+)#', $meta_refresh->attr('content'), $match); + $url = $match[1]; + $crawler = self::request('POST', $url); + $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); + } + + self::assertContainsLang('EXTENSION_ENABLE_SUCCESS', $crawler->filter('div.successbox')->text()); + + self::logout(); } - - $this->assertContainsLang('EXTENSION_ENABLE_SUCCESS', $crawler->filter('div.successbox')->text()); - - $this->logout(); } - public function disable_ext($extension) + public static function disable_ext($extension) { - $this->add_lang('acp/extensions'); + self::add_lang('acp/extensions'); - if ($this->get_logged_in_user()) + if (self::get_logged_in_user()) { - $this->logout(); + self::logout(); } - $this->login(); - $this->admin_login(); + self::login(); + self::admin_login(); $ext_path = str_replace('/', '%2F', $extension); - $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=' . $ext_path . '&sid=' . $this->sid); - $this->assertGreaterThan(1, $crawler->filter('div.main fieldset.submit-buttons input')->count()); + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=' . $ext_path . '&sid=' . self::$session_id); + self::assertGreaterThan(1, $crawler->filter('div.main fieldset.submit-buttons input')->count()); - $form = $crawler->selectButton($this->lang('EXTENSION_DISABLE'))->form(); + $form = $crawler->selectButton(self::lang('EXTENSION_DISABLE'))->form(); $crawler = self::submit($form); $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); @@ -673,28 +687,28 @@ class phpbb_functional_test_case extends phpbb_test_case $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); } - $this->assertContainsLang('EXTENSION_DISABLE_SUCCESS', $crawler->filter('div.successbox')->text()); + self::assertContainsLang('EXTENSION_DISABLE_SUCCESS', $crawler->filter('div.successbox')->text()); - $this->logout(); + self::logout(); } - public function delete_ext_data($extension) + public static function delete_ext_data($extension) { - $this->add_lang('acp/extensions'); + self::add_lang('acp/extensions'); - if ($this->get_logged_in_user()) + if (self::get_logged_in_user()) { - $this->logout(); + self::logout(); } - $this->login(); - $this->admin_login(); + self::login(); + self::admin_login(); $ext_path = str_replace('/', '%2F', $extension); - $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=' . $ext_path . '&sid=' . $this->sid); - $this->assertGreaterThan(1, $crawler->filter('div.main fieldset.submit-buttons input')->count()); + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=delete_data_pre&ext_name=' . $ext_path . '&sid=' . self::$session_id); + self::assertGreaterThan(1, $crawler->filter('div.main fieldset.submit-buttons input')->count()); - $form = $crawler->selectButton($this->lang('EXTENSION_DELETE_DATA'))->form(); + $form = $crawler->selectButton(self::lang('EXTENSION_DELETE_DATA'))->form(); $crawler = self::submit($form); $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); @@ -708,15 +722,15 @@ class phpbb_functional_test_case extends phpbb_test_case $meta_refresh = $crawler->filter('meta[http-equiv="refresh"]'); } - $this->assertContainsLang('EXTENSION_DELETE_DATA_SUCCESS', $crawler->filter('div.successbox')->text()); + self::assertContainsLang('EXTENSION_DELETE_DATA_SUCCESS', $crawler->filter('div.successbox')->text()); - $this->logout(); + self::logout(); } - public function uninstall_ext($extension) + public static function uninstall_ext($extension) { - $this->disable_ext($extension); - $this->delete_ext_data($extension); + self::disable_ext($extension); + self::delete_ext_data($extension); } private static function recreate_database($config) @@ -904,7 +918,6 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected function get_group_id($group_name) { - $this->get_db(); $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " WHERE group_name = '" . $this->db->sql_escape($group_name) . "'"; @@ -1017,21 +1030,21 @@ class phpbb_functional_test_case extends phpbb_test_case return group_user_add($group_id, false, $usernames, $group_name, $default, $leader); } - protected function login($username = 'admin', $autologin = false) + protected static function login($username = 'admin', $autologin = false) { - $this->add_lang('ucp'); + self::add_lang('ucp'); $crawler = self::request('GET', 'ucp.php?mode=login'); - $button = $crawler->selectButton($this->lang('LOGIN')); - $this->assertGreaterThan(0, $button->count(), 'No login button found'); + $button = $crawler->selectButton(self::lang('LOGIN')); + self::assertGreaterThan(0, $button->count(), 'No login button found'); - $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + $form = $crawler->selectButton(self::lang('LOGIN'))->form(); if ($autologin) { $form['autologin']->tick(); } $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); - $this->assertStringNotContainsString($this->lang('LOGIN'), $crawler->filter('.navbar')->text()); + self::assertStringNotContainsString(self::lang('LOGIN'), $crawler->filter('.navbar')->text()); $cookies = self::$cookieJar->all(); @@ -1040,50 +1053,50 @@ class phpbb_functional_test_case extends phpbb_test_case { if (substr($cookie->getName(), -4) == '_sid') { - $this->sid = $cookie->getValue(); + self::$session_id = $cookie->getValue(); } } } - protected function logout() + protected static function logout() { - $this->add_lang('ucp'); + self::add_lang('ucp'); $crawler = self::request('GET', 'index.php'); - $logout_link = $crawler->filter('a[title="' . $this->lang('LOGOUT') . '"]')->attr('href'); + $logout_link = $crawler->filter('a[title="' . self::lang('LOGOUT') . '"]')->attr('href'); self::request('GET', $logout_link); $crawler = self::request('GET', $logout_link); - $this->assertStringContainsString($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); - unset($this->sid); + self::assertStringContainsString(self::lang('REGISTER'), $crawler->filter('.navbar')->text()); + self::$session_id = null; } /** * Login to the ACP * You must run login() before calling this. */ - protected function admin_login($username = 'admin') + protected static function admin_login($username = 'admin') { - $this->add_lang('acp/common'); + self::add_lang('acp/common'); // Requires login first! - if (empty($this->sid)) + if (empty(self::$session_id)) { - $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); + self::fail('$this->sid is empty. Make sure you call login() before admin_login()'); return; } - $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid); - $this->assertStringContainsString($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); + $crawler = self::request('GET', 'adm/index.php?sid=' . self::$session_id); + self::assertStringContainsString(self::lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); - $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + $form = $crawler->selectButton(self::lang('LOGIN'))->form(); foreach ($form->getValues() as $field => $value) { if (strpos($field, 'password_') === 0) { $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); - $this->assertStringContainsString($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); + self::assertStringContainsString(self::lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); $cookies = self::$cookieJar->all(); @@ -1092,7 +1105,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (substr($cookie->getName(), -4) == '_sid') { - $this->sid = $cookie->getValue(); + self::$session_id = $cookie->getValue(); } } @@ -1101,13 +1114,13 @@ class phpbb_functional_test_case extends phpbb_test_case } } - protected function add_lang($lang_file) + protected static function add_lang($lang_file) { if (is_array($lang_file)) { foreach ($lang_file as $file) { - $this->add_lang($file); + self::add_lang($file); } return; @@ -1115,23 +1128,23 @@ class phpbb_functional_test_case extends phpbb_test_case $lang_path = __DIR__ . "/../../phpBB/language/en/$lang_file.php"; - $lang = array(); + $lang = []; if (file_exists($lang_path)) { include($lang_path); } - $this->lang = array_merge($this->lang, $lang); + self::$lang_ary = array_merge(self::$lang_ary, $lang); } - protected function add_lang_ext($ext_name, $lang_file) + protected static function add_lang_ext($ext_name, $lang_file) { if (is_array($lang_file)) { foreach ($lang_file as $file) { - $this->add_lang_ext($ext_name, $file); + self::add_lang_ext($ext_name, $file); } return; @@ -1139,27 +1152,27 @@ class phpbb_functional_test_case extends phpbb_test_case $lang_path = __DIR__ . "/../../phpBB/ext/{$ext_name}/language/en/$lang_file.php"; - $lang = array(); + $lang = []; if (file_exists($lang_path)) { include($lang_path); } - $this->lang = array_merge($this->lang, $lang); + self::$lang_ary = array_merge(self::$lang_ary, $lang); } - protected function lang() + protected static function lang() { $args = func_get_args(); $key = $args[0]; - if (empty($this->lang[$key])) + if (empty(self::$lang_ary[$key])) { throw new RuntimeException('Language key "' . $key . '" could not be found.'); } - $args[0] = $this->lang[$key]; + $args[0] = self::$lang_ary[$key]; return call_user_func_array('sprintf', $args); } @@ -1171,9 +1184,9 @@ class phpbb_functional_test_case extends phpbb_test_case * @param string $haystack Search this * @param string $message Optional failure message */ - public function assertContainsLang($needle, $haystack, $message = '') + public static function assertContainsLang($needle, $haystack, $message = '') { - $this->assertStringContainsString(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); + self::assertStringContainsString(html_entity_decode(self::lang($needle), ENT_QUOTES), $haystack, $message); } /** @@ -1183,9 +1196,9 @@ class phpbb_functional_test_case extends phpbb_test_case * @param string $haystack Search this * @param string $message Optional failure message */ - public function assertNotContainsLang($needle, $haystack, $message = '') + public static function assertNotContainsLang($needle, $haystack, $message = '') { - $this->assertStringNotContainsString(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); + self::assertStringNotContainsString(html_entity_decode(self::lang($needle), ENT_QUOTES), $haystack, $message); } /* @@ -1196,7 +1209,7 @@ class phpbb_functional_test_case extends phpbb_test_case * @param mixed $status_code Expected status code, false to disable check * @return null */ - static public function assert_response_html($status_code = 200) + public static function assert_response_html($status_code = 200) { // Any output before the doc type means there was an error $content = self::get_content(); @@ -1217,7 +1230,7 @@ class phpbb_functional_test_case extends phpbb_test_case * @param mixed $status_code Expected status code, false to disable check * @return null */ - static public function assert_response_xml($status_code = 200) + public static function assert_response_xml($status_code = 200) { // Any output before the xml opening means there was an error $content = self::get_content(); @@ -1239,7 +1252,7 @@ class phpbb_functional_test_case extends phpbb_test_case * @param int $status_code Expected status code * @return void */ - static public function assert_response_status_code($status_code = 200) + public static function assert_response_status_code($status_code = 200) { if ($status_code != self::$client->getResponse()->getStatusCode() && preg_match('/^5[0-9]{2}/', self::$client->getResponse()->getStatusCode())) @@ -1662,7 +1675,7 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return string|bool username if logged in, false otherwise */ - protected function get_logged_in_user() + protected static function get_logged_in_user() { $username_logged_in = false; $crawler = self::request('GET', 'index.php');