From 69cc2a97340c4c5055ae7de503b00f3874dc524c Mon Sep 17 00:00:00 2001 From: rxu Date: Fri, 8 Sep 2023 20:46:01 +0700 Subject: [PATCH 1/2] [ticket/17151] Make macros available for extensions Also add tests and error reporting. PHPBB3-17151 --- phpBB/includes/acp/acp_modules.php | 2 - phpBB/includes/functions_module.php | 19 ++- phpBB/phpbb/template/twig/extension/forms.php | 12 +- phpBB/phpbb/template/twig/extension/icon.php | 6 +- .../functional/extension_controller_test.php | 38 ++--- .../functional/extension_global_lang_test.php | 18 +-- tests/functional/extension_module_test.php | 137 +++++++++--------- .../extension_permission_lang_test.php | 32 ++-- .../fixtures/ext/foo/bar/acp/main_info.php | 2 +- .../fixtures/ext/foo/bar/acp/main_module.php | 107 ++++++++++++++ .../ext/foo/bar/adm/style/foobar.html | 31 +++- .../fixtures/ext/foo/bar/mcp/main_info.php | 28 ++++ .../fixtures/ext/foo/bar/mcp/main_module.php | 25 ++++ .../ext/foo/bar/migrations/add_acp_module.php | 31 ++++ .../ext/foo/bar/migrations/add_mcp_module.php | 31 ++++ .../ext/foo/bar/migrations/add_permission.php | 25 ++++ .../ext/foo/bar/migrations/add_ucp_module.php | 31 ++++ .../styles/prosilver/template/foobar_mcp.html | 3 + .../fixtures/ext/foo/bar/ucp/main_info.php | 4 +- tests/functional/metadata_manager_test.php | 14 +- .../phpbb_functional_test_case.php | 12 ++ 21 files changed, 455 insertions(+), 153 deletions(-) create mode 100644 tests/functional/fixtures/ext/foo/bar/mcp/main_info.php create mode 100644 tests/functional/fixtures/ext/foo/bar/mcp/main_module.php create mode 100644 tests/functional/fixtures/ext/foo/bar/migrations/add_acp_module.php create mode 100644 tests/functional/fixtures/ext/foo/bar/migrations/add_mcp_module.php create mode 100644 tests/functional/fixtures/ext/foo/bar/migrations/add_permission.php create mode 100644 tests/functional/fixtures/ext/foo/bar/migrations/add_ucp_module.php create mode 100644 tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_mcp.html diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index 8b09dfa911..fb03d50cda 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -618,8 +618,6 @@ class acp_modules $langname = $user->lang($row['module_langname']); $module_list .= ''; - - $iteration++; } $db->sql_freeresult($result); diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 5b7c558365..ae4e77e16a 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -608,12 +608,19 @@ class p_master if (is_dir($module_style_dir)) { - $template->set_custom_style(array( - array( - 'name' => 'adm', - 'ext_path' => 'adm/style/', - ), - ), array($module_style_dir, $phpbb_admin_path . 'style')); + $template->set_custom_style( + [ + [ + 'name' => 'adm', + 'ext_path' => 'adm/style/', + ], + ], + [ + $module_style_dir, + $phpbb_admin_path . 'style', + $phpbb_root_path . 'styles/all/template/', + ] + ); } } diff --git a/phpBB/phpbb/template/twig/extension/forms.php b/phpBB/phpbb/template/twig/extension/forms.php index ac118941db..4d8de94b9d 100644 --- a/phpBB/phpbb/template/twig/extension/forms.php +++ b/phpBB/phpbb/template/twig/extension/forms.php @@ -78,7 +78,7 @@ class forms extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } } @@ -101,7 +101,7 @@ class forms extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } } @@ -134,7 +134,7 @@ class forms extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } } @@ -159,7 +159,7 @@ class forms extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } } @@ -189,7 +189,7 @@ class forms extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } } @@ -217,7 +217,7 @@ class forms extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } } } diff --git a/phpBB/phpbb/template/twig/extension/icon.php b/phpBB/phpbb/template/twig/extension/icon.php index e44fc8b3ed..550a049795 100644 --- a/phpBB/phpbb/template/twig/extension/icon.php +++ b/phpBB/phpbb/template/twig/extension/icon.php @@ -129,7 +129,7 @@ class icon extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } break; @@ -148,7 +148,7 @@ class icon extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } $type = 'svg'; @@ -170,7 +170,7 @@ class icon extends AbstractExtension } catch (\Twig\Error\Error $e) { - return ''; + return $e->getMessage(); } } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 7db05a9e3d..c235278d9d 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -21,13 +21,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c private static $helper; protected static $fixtures = array( - 'foo/bar/config/', - 'foo/bar/controller/', - 'foo/bar/event/', - 'foo/bar/language/en/', - 'foo/bar/styles/prosilver/template/', - 'foo/foo/config/', - 'foo/foo/controller/', + './', ); static public function setUpBeforeClass(): void @@ -45,25 +39,34 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c self::$helper->restore_original_ext_dir(); } + protected static function setup_extensions() + { + return ['foo/bar', 'foo/foo']; + } + protected function setUp(): void { parent::setUp(); - $this->phpbb_extension_manager = $this->get_extension_manager(); - $this->purge_cache(); } + protected function tearDown(): void + { + $this->uninstall_ext('foo/bar'); + $this->uninstall_ext('foo/foo'); + + parent::tearDown(); + } + /** * Check a controller for extension foo/bar. */ public function test_foo_bar() { - $this->phpbb_extension_manager->enable('foo/bar'); $crawler = self::request('GET', 'app.php/foo/bar', array(), false); self::assert_response_status_code(); $this->assertStringContainsString("foo/bar controller handle() method", $crawler->filter('body')->text()); - $this->phpbb_extension_manager->purge('foo/bar'); } /** @@ -71,11 +74,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_routing_resources() { - $this->phpbb_extension_manager->enable('foo/foo'); $crawler = self::request('GET', 'app.php/foo/foo', array(), false); self::assert_response_status_code(); $this->assertStringContainsString("foo/foo controller handle() method", $crawler->filter('body')->text()); - $this->phpbb_extension_manager->purge('foo/foo'); } /** @@ -83,10 +84,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_controller_with_template() { - $this->phpbb_extension_manager->enable('foo/bar'); $crawler = self::request('GET', 'app.php/foo/template'); $this->assertStringContainsString("I am a variable", $crawler->filter('#content')->text()); - $this->phpbb_extension_manager->purge('foo/bar'); } /** @@ -104,11 +103,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_missing_argument() { - $this->phpbb_extension_manager->enable('foo/bar'); $crawler = self::request('GET', 'app.php/foo/baz', array(), false); $this->assert_response_html(500); $this->assertStringContainsString('Controller "foo\bar\controller\controller::baz()" requires that you provide a value for the "$test" argument', $crawler->filter('body')->text()); - $this->phpbb_extension_manager->purge('foo/bar'); } /** @@ -116,11 +113,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_exception_should_result_in_500_status_code() { - $this->phpbb_extension_manager->enable('foo/bar'); $crawler = self::request('GET', 'app.php/foo/exception', array(), false); $this->assert_response_html(500); $this->assertStringContainsString('Exception thrown from foo/exception route', $crawler->filter('body')->text()); - $this->phpbb_extension_manager->purge('foo/bar'); } /** @@ -150,7 +145,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $this->markTestIncomplete('Session table contains incorrect data for controllers on travis,' . 'therefor the redirect fails.'); - $this->phpbb_extension_manager->enable('foo/bar'); $crawler = self::request('GET', 'app.php/foo/login_redirect'); $this->assertContainsLang('LOGIN', $crawler->filter('h2')->text()); $form = $crawler->selectButton('login')->form(array( @@ -161,7 +155,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $crawler = self::submit($form); $this->assertStringContainsString("I am a variable", $crawler->filter('#content')->text(), 'Unsuccessful redirect after using login_box()'); - $this->phpbb_extension_manager->purge('foo/bar'); } /** @@ -169,7 +162,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_redirect() { - $this->phpbb_extension_manager->enable('foo/bar'); $crawler = self::request('GET', 'app.php/foo/redirect'); $nodes = $crawler->filter('div')->extract(array('id')); @@ -186,7 +178,5 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $redirect = $crawler->filter('#redirect_' . $row_num)->text(); $this->assertEquals($crawler->filter('#redirect_expected_' . $row_num)->text(), $redirect); } - - $this->phpbb_extension_manager->purge('foo/bar'); } } diff --git a/tests/functional/extension_global_lang_test.php b/tests/functional/extension_global_lang_test.php index e2b2db2dfd..cf2d9dbf29 100644 --- a/tests/functional/extension_global_lang_test.php +++ b/tests/functional/extension_global_lang_test.php @@ -21,9 +21,7 @@ class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_ private static $helper; protected static $fixtures = array( - 'foo/bar/config/', - 'foo/bar/event/', - 'foo/bar/language/en/', + './', ); static public function setUpBeforeClass(): void @@ -46,23 +44,23 @@ class phpbb_functional_extension_global_lang_test extends phpbb_functional_test_ parent::setUp(); $this->get_db(); - - $this->phpbb_extension_manager = $this->get_extension_manager(); - $this->purge_cache(); } protected function tearDown(): void { - parent::tearDown(); + $this->uninstall_ext('foo/bar'); - $this->purge_cache(); + parent::tearDown(); + } + + protected static function setup_extensions() + { + return ['foo/bar']; } public function test_load_extension_lang_globally() { - $this->phpbb_extension_manager->enable('foo/bar'); - // The board index, which should contain an overwritten translation $crawler = self::request('GET', 'index.php'); diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index f8ecf1a812..67dc35ae73 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -40,76 +40,16 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case self::$helper->restore_original_ext_dir(); } - protected function setUp(): void + protected function tearDown(): void { - global $db; + $this->uninstall_ext('foo/bar'); - parent::setUp(); + parent::tearDown(); + } - $this->phpbb_extension_manager = $this->get_extension_manager(); - $this->phpbb_extension_manager->enable('foo/bar'); - - $db = $this->get_db(); - $cache = $this->get_cache_driver(); - $modules = new \phpbb\module\module_manager($cache, $db, $this->phpbb_extension_manager, MODULES_TABLE, __DIR__ . '/../../phpBB/', 'php'); - - $sql = 'SELECT module_id - FROM ' . MODULES_TABLE . " - WHERE module_langname = 'acp' - AND module_class = 'ACP_CAT_DOT_MODS'"; - $result = $db->sql_query($sql); - $module_id = (int) $db->sql_fetchfield('module_id'); - $db->sql_freeresult($result); - - $parent_data = array( - 'module_basename' => '', - 'module_enabled' => 1, - 'module_display' => 1, - 'parent_id' => $module_id, - 'module_class' => 'acp', - 'module_langname' => 'ACP_FOOBAR_TITLE', - 'module_mode' => '', - 'module_auth' => '', - ); - $modules->update_module_data($parent_data); - - $module_data = array( - 'module_basename' => 'foo\\bar\\acp\\main_module', - 'module_enabled' => 1, - 'module_display' => 1, - 'parent_id' => $parent_data['module_id'], - 'module_class' => 'acp', - 'module_langname' => 'ACP_FOOBAR_TITLE', - 'module_mode' => 'mode', - 'module_auth' => '', - ); - $modules->update_module_data($module_data); - - $parent_data = array( - 'module_basename' => '', - 'module_enabled' => 1, - 'module_display' => 1, - 'parent_id' => 0, - 'module_class' => 'ucp', - 'module_langname' => 'UCP_FOOBAR_TITLE', - 'module_mode' => '', - 'module_auth' => '', - ); - $modules->update_module_data($parent_data); - - $module_data = array( - 'module_basename' => 'foo\\bar\\ucp\\main_module', - 'module_enabled' => 1, - 'module_display' => 1, - 'parent_id' => $parent_data['module_id'], - 'module_class' => 'ucp', - 'module_langname' => 'UCP_FOOBAR_TITLE', - 'module_mode' => 'mode', - 'module_auth' => '', - ); - $modules->update_module_data($module_data); - - $this->purge_cache(); + protected static function setup_extensions() + { + return ['foo/bar']; } public function test_acp() @@ -117,8 +57,50 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case $this->login(); $this->admin_login(); - $crawler = self::request('GET', 'adm/index.php?i=foo%5cbar%5cacp%5cmain_module&mode=mode&sid=' . $this->sid); - $this->assertStringContainsString('Bertie rulez!', $crawler->filter('#main')->text()); + $crawler = self::request('GET', 'adm/index.php?i=-foo-bar-acp-main_module&mode=mode&sid=' . $this->sid); + $this->assertStringContainsString('ACP_FOOBAR_SETTINGS', $crawler->filter('#main')->text()); + $this->assertContainsLang('GENERAL_SETTINGS', $crawler->filter('fieldset')->text()); + + $this->assertStringContainsString('SETTING_0', $crawler->filter('dl')->eq(0)->filter('dt > label[for="setting_0"]')->text()); + $this->assertStringContainsString('SETTING_0_EXPLAIN', $crawler->filter('dl')->eq(0)->filter('dt > span')->text()); + $this->assertEquals(2, $crawler->filter('dl')->eq(0)->filter('dd > input[type="number"]')->count()); + + $this->assertStringContainsString('SETTING_1', $crawler->filter('dl')->eq(1)->filter('dt > label[for="setting_1"]')->text()); + $this->assertStringContainsString('CUSTOM_LANG_EXPLAIN', $crawler->filter('dl')->eq(1)->filter('dt > span')->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(1)->filter('dd > input[type="submit"]')->count()); + + $this->assertStringContainsString('SETTING_2', $crawler->filter('dl')->eq(2)->filter('dt > label[for="setting_2"]')->text()); + $this->assertEquals(0, $crawler->filter('dl')->eq(2)->filter('dt > span')->count()); + $this->assertEquals(2, $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->count()); + + $this->assertStringContainsString('SETTING_3', $crawler->filter('dl')->eq(3)->filter('dt > label[for="setting_3"]')->text()); + $this->assertStringContainsString('SETTING_3_EXPLAIN', $crawler->filter('dl')->eq(3)->filter('dt > span')->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(3)->filter('dd > input[type="number"]')->count()); + + $this->assertStringContainsString('SETTING_4', $crawler->filter('dl')->eq(4)->filter('dt > label[for="setting_4"]')->text()); + $this->assertStringContainsString('SETTING_4_EXPLAIN', $crawler->filter('dl')->eq(4)->filter('dt > span')->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(4)->filter('dd > select[id="setting_4"]')->count()); + $this->assertEquals(3, $crawler->filter('dl')->eq(4)->filter('dd > select > option')->count()); + + $this->assertStringContainsString('SETTING_5', $crawler->filter('dl')->eq(5)->filter('dt > label[for="setting_5"]')->text()); + $this->assertStringContainsString('SETTING_5_EXPLAIN', $crawler->filter('dl')->eq(5)->filter('dt > span')->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(5)->filter('dd > input[type="text"]')->count()); + + $this->assertStringContainsString('SETTING_6', $crawler->filter('dl')->eq(6)->filter('dt > label[for="setting_6"]')->text()); + $this->assertStringContainsString('SETTING_6_EXPLAIN', $crawler->filter('dl')->eq(6)->filter('dt > span')->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(6)->filter('dd > input[type="password"]')->count()); + + $this->assertStringContainsString('SETTING_7', $crawler->filter('dl')->eq(7)->filter('dt > label[for="setting_7"]')->text()); + $this->assertStringContainsString('SETTING_7_EXPLAIN', $crawler->filter('dl')->eq(7)->filter('dt > span')->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(7)->filter('dd > input[type="email"]')->count()); + + $this->assertStringContainsString('SETTING_8', $crawler->filter('dl')->eq(8)->filter('dt > label[for="setting_8"]')->text()); + $this->assertStringContainsString('SETTING_8_EXPLAIN', $crawler->filter('dl')->eq(8)->filter('dt > span')->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(8)->filter('dd > textarea[name="config[setting_8]"]')->count()); + + $this->assertStringContainsString('SETTING_9', $crawler->filter('dl')->eq(9)->filter('dt > label[for="setting_9"]')->text()); + $this->assertStringContainsString('SETTING_9_EXPLAIN', $crawler->filter('dl')->eq(9)->filter('dt > span')->text()); + $this->assertEquals(2, $crawler->filter('dl')->eq(9)->filter('dd > label > input[type="radio"]')->count()); } public function test_ucp() @@ -126,12 +108,23 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case $this->login(); $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid); - $this->assertStringContainsString('UCP_FOOBAR_TITLE', $crawler->filter('#tabs')->text()); + $this->assertStringContainsString('UCP_FOOBAR', $crawler->filter('#navigation')->text()); - $link = $crawler->selectLink('UCP_FOOBAR_TITLE')->link()->getUri(); + $link = $crawler->selectLink('UCP_FOOBAR')->link()->getUri(); $crawler = self::request('GET', substr($link, strpos($link, 'ucp.'))); $this->assertStringContainsString('UCP Extension Template Test Passed!', $crawler->filter('#content')->text()); + } - $this->phpbb_extension_manager->purge('foo/bar'); + public function test_mcp() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'mcp.php?sid=' . $this->sid); + $this->assertStringContainsString('MCP_FOOBAR', $crawler->filter('#navigation')->text()); + + $link = $crawler->selectLink('MCP_FOOBAR')->link()->getUri(); + $crawler = self::request('GET', substr($link, strpos($link, 'mcp.'))); + $this->assertStringContainsString('MCP Extension Template Test Passed!', $crawler->filter('#content')->text()); } } diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 9c78e2db5b..9516e351df 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -21,9 +21,7 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t private static $helper; protected static $fixtures = array( - 'foo/bar/config/', - 'foo/bar/event/', - 'foo/bar/language/en/', + './', ); static public function setUpBeforeClass(): void @@ -45,29 +43,25 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t { parent::setUp(); - $this->get_db(); - - $acl_ary = array( - 'auth_option' => 'u_foo', - 'is_global' => 1, - ); - - $sql = 'INSERT INTO phpbb_acl_options ' . $this->db->sql_build_array('INSERT', $acl_ary); - $this->db->sql_query($sql); - - $this->phpbb_extension_manager = $this->get_extension_manager(); - - $this->purge_cache(); - $this->login(); $this->admin_login(); $this->add_lang('acp/permissions'); } + protected function tearDown(): void + { + $this->uninstall_ext('foo/bar'); + + parent::tearDown(); + } + + protected static function setup_extensions() + { + return ['foo/bar']; + } + public function test_auto_include_permission_lang_from_extensions() { - $this->phpbb_extension_manager->enable('foo/bar'); - // User permissions $crawler = self::request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php index 371ab7c967..a5a005c4df 100644 --- a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php @@ -26,7 +26,7 @@ class main_info function module() { return array( - 'filename' => 'foo\bar\acp\main_module', + 'filename' => '\foo\bar\acp\main_module', 'title' => 'ACP_FOOBAR_TITLE', 'modes' => array( 'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')), diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php index ee797c718d..08cb73da07 100644 --- a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php @@ -27,7 +27,114 @@ class main_module function main($id, $mode) { + global $language, $template; + $this->tpl_name = 'foobar'; $this->page_title = 'Bertie'; + + $display_vars = [ + 'title' => 'ACP_FOOBAR_SETTINGS', + 'vars' => [ + 'legend' => 'GENERAL_SETTINGS', + // For the 'dimension' type the order is important: main setting goes last. + 'setting_0_width' => ['lang' => 'SETTING_0', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false], + 'setting_0_height' => ['lang' => 'SETTING_0', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false], + 'setting_0' => ['lang' => 'SETTING_0', 'validate' => 'int:0:16', 'type' => 'dimension:0:999', 'explain' => true, 'append' => ' ' . $language->lang('PIXEL')], + 'setting_1' => ['lang' => 'SETTING_1', 'validate' => 'bool', 'type' => 'custom', 'method' => 'submit_button', 'lang_explain' => 'CUSTOM_LANG_EXPLAIN', 'explain' => true], + 'setting_2' => ['lang' => 'SETTING_2', 'validate' => 'bool', 'type' => 'radio:yes_no'], + 'setting_3' => ['lang' => 'SETTING_3', 'validate' => 'int:0:99999','type' => 'number:0:99999', 'explain' => true], + 'setting_4' => ['lang' => 'SETTING_4', 'validate' => 'string', 'type' => 'select', 'method' => 'create_select', 'explain' => true], + 'setting_5' => ['lang' => 'SETTING_5', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true], + 'setting_6' => ['lang' => 'SETTING_6', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true], + 'setting_7' => ['lang' => 'SETTING_7', 'validate' => 'email', 'type' => 'email:0:100', 'explain' => true], + 'setting_8' => ['lang' => 'SETTING_8', 'validate' => 'string', 'type' => 'textarea:5:30', 'explain' => true], + 'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true], + ] + ]; + + $this->new_config = $cfg_array = $error = []; + + validate_config_vars($display_vars['vars'], $cfg_array, $error); + + foreach ($display_vars['vars'] as $config_name => $null) + { + if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) + { + continue; + } + + $this->new_config[$config_name] = $cfg_array[$config_name]; + } + + $template->assign_vars([ + 'L_TITLE' => $language->lang($display_vars['title']), + 'L_TITLE_EXPLAIN' => $language->lang($display_vars['title'] . '_EXPLAIN'), + + 'S_ERROR' => (sizeof($error)) ? true : false, + 'ERROR_MSG' => implode('
', $error), + + 'U_ACTION' => $this->u_action + ]); + + // Output relevant page + foreach ($display_vars['vars'] as $config_key => $vars) + { + if (!is_array($vars) && strpos($config_key, 'legend') === false) + { + continue; + } + + if (strpos($config_key, 'legend') !== false) + { + $template->assign_block_vars('options', [ + 'S_LEGEND' => true, + 'LEGEND' => $language->lang($vars), + ]); + + continue; + } + $type = explode(':', $vars['type']); + + $l_explain = ''; + $vars['explain'] = $vars['explain'] ?? false; + $vars['lang_explain'] = $vars['lang_explain'] ?? false; + + if ($vars['explain']) + { + $l_explain = $language->lang($vars['lang_explain'] ?: $vars['lang'] . '_EXPLAIN'); + } + + $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); + + if (empty($content)) + { + continue; + } + + $template->assign_block_vars('options', [ + 'KEY' => $config_key, + 'TITLE' => $language->lang($vars['lang']), + 'S_EXPLAIN' => $vars['explain'], + 'TITLE_EXPLAIN' => $l_explain, + 'CONTENT' => $content, + ]); + + unset($display_vars['vars'][$config_key]); + } } + + function create_select() + { + return ' + + + + '; + } + + function submit_button() + { + return ''; + } + } diff --git a/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html b/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html index 3cb45c269c..4560a09da5 100644 --- a/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html +++ b/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html @@ -1,3 +1,32 @@ -Bertie rulez! +

{{ lang('TITLE') }}

+

{{ lang('TITLE_EXPLAIN') }}

+{% if S_ERROR %} +
+

{{ lang('WARNING') }}

+

{{ ERROR_MSG }}

+
+{% endif %} + +{% for options in loops.options %} + {% if options.S_LEGEND %} + {% if not options.S_FIRST_ROW %} + + {% endif %} +
+ {{ options.LEGEND }} + {% else %} +
+
{% if options.S_EXPLAIN %}
{{ options.TITLE_EXPLAIN }}{% endif %}
+
+ {% if options.CONTENT is iterable %} + {{ FormsBuildTemplate(options.CONTENT) }} + {% else %} + {{ options.CONTENT }} + {% endif %} +
+
+ + {% endif %} +{% endfor %} diff --git a/tests/functional/fixtures/ext/foo/bar/mcp/main_info.php b/tests/functional/fixtures/ext/foo/bar/mcp/main_info.php new file mode 100644 index 0000000000..b756bec3bd --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/mcp/main_info.php @@ -0,0 +1,28 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace foo\bar\mcp; + +class main_info +{ + function module() + { + return array( + 'filename' => '\foo\bar\mcp\main_module', + 'title' => 'MCP_FOOBAR_TITLE', + 'modes' => array( + 'mode' => array('title' => 'MCP_FOOBAR_MODE', 'auth' => '', 'cat' => array('MCP_FOOBAR_TITLE')), + ), + ); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/mcp/main_module.php b/tests/functional/fixtures/ext/foo/bar/mcp/main_module.php new file mode 100644 index 0000000000..fe984a83ff --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/mcp/main_module.php @@ -0,0 +1,25 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace foo\bar\mcp; + +class main_module +{ + var $u_action; + + function main($id, $mode) + { + $this->tpl_name = 'foobar_mcp'; + $this->page_title = 'Bertie MCP'; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/migrations/add_acp_module.php b/tests/functional/fixtures/ext/foo/bar/migrations/add_acp_module.php new file mode 100644 index 0000000000..d2e2fb675b --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/migrations/add_acp_module.php @@ -0,0 +1,31 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace foo\bar\migrations; + +class add_acp_module extends \phpbb\db\migration\migration +{ + public function update_data() + { + // Add ACP module + return [ + ['module.add', ['acp', 'ACP_CAT_DOT_MODS', 'ACP_FOOBAR']], + ['module.add', ['acp', 'ACP_FOOBAR', [ + 'module_basename' => '\foo\bar\acp\main_module', + 'module_langname' => 'ACP_FOOBAR_TITLE', + 'module_mode' => 'mode', + 'module_auth' => '', + ]]], + ]; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/migrations/add_mcp_module.php b/tests/functional/fixtures/ext/foo/bar/migrations/add_mcp_module.php new file mode 100644 index 0000000000..476aa89dfe --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/migrations/add_mcp_module.php @@ -0,0 +1,31 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace foo\bar\migrations; + +class add_mcp_module extends \phpbb\db\migration\container_aware_migration +{ + public function update_data() + { + // Add MCP module + return [ + ['module.add', ['mcp', 'MCP_MAIN', 'MCP_FOOBAR']], + ['module.add', ['mcp', 'MCP_FOOBAR', [ + 'module_basename' => '\foo\bar\mcp\main_module', + 'module_langname' => 'MCP_FOOBAR_TITLE', + 'module_mode' => 'mode', + 'module_auth' => '', + ]]], + ]; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/migrations/add_permission.php b/tests/functional/fixtures/ext/foo/bar/migrations/add_permission.php new file mode 100644 index 0000000000..970c284954 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/migrations/add_permission.php @@ -0,0 +1,25 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace foo\bar\migrations; + +class add_permission extends \phpbb\db\migration\container_aware_migration +{ + public function update_data() + { + // Add global permission + return [ + ['permission.add', ['u_foo', true]], + ]; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/migrations/add_ucp_module.php b/tests/functional/fixtures/ext/foo/bar/migrations/add_ucp_module.php new file mode 100644 index 0000000000..45ef7128c4 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/migrations/add_ucp_module.php @@ -0,0 +1,31 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace foo\bar\migrations; + +class add_ucp_module extends \phpbb\db\migration\container_aware_migration +{ + public function update_data() + { + // Add UCP module + return [ + ['module.add', ['ucp', 'UCP_MAIN', 'UCP_FOOBAR']], + ['module.add', ['ucp', 'UCP_FOOBAR', [ + 'module_basename' => '\foo\bar\ucp\main_module', + 'module_langname' => 'UCP_FOOBAR_TITLE', + 'module_mode' => 'mode', + 'module_auth' => '', + ]]], + ]; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_mcp.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_mcp.html new file mode 100644 index 0000000000..3ffe34cda4 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_mcp.html @@ -0,0 +1,3 @@ + +
MCP Extension Template Test Passed!
+ diff --git a/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php index 4c74442639..aa672cb842 100644 --- a/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php +++ b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php @@ -19,9 +19,9 @@ class main_info { return array( 'filename' => '\foo\bar\ucp\main_module', - 'title' => 'ACP_FOOBAR_TITLE', + 'title' => 'UCP_FOOBAR_TITLE', 'modes' => array( - 'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')), + 'mode' => array('title' => 'UCP_FOOBAR_MODE', 'auth' => '', 'cat' => array('UCP_FOOBAR_TITLE')), ), ); } diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index 20a45c882b..8b4eb8fde5 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -21,12 +21,12 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case private static $helper; protected static $fixtures = array( - 'foo/bar/', + './', ); protected function tearDown(): void { - $this->purge_cache(); + $this->uninstall_ext('foo/bar'); parent::tearDown(); } @@ -50,16 +50,16 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case { parent::setUp(); - $this->phpbb_extension_manager = $this->get_extension_manager(); - - $this->purge_cache(); - $this->phpbb_extension_manager->enable('foo/bar'); - $this->login(); $this->admin_login(); $this->add_lang('acp/extensions'); } + protected static function setup_extensions() + { + return ['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/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 84d9d08c55..1ef7ac6407 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -442,6 +442,10 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->add_lang('acp/extensions'); + if ($this->get_logged_in_user()) + { + $this->logout(); + } $this->login(); $this->admin_login(); @@ -473,6 +477,10 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->add_lang('acp/extensions'); + if ($this->get_logged_in_user()) + { + $this->logout(); + } $this->login(); $this->admin_login(); @@ -504,6 +512,10 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->add_lang('acp/extensions'); + if ($this->get_logged_in_user()) + { + $this->logout(); + } $this->login(); $this->admin_login(); From 0ac97841cba59e781cf44e15374eb08537ba58f5 Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 11 Sep 2023 08:56:46 +0700 Subject: [PATCH 2/2] [ticket/17151] Use Twig and short array syntax in tests PHPBB3-17151 --- .../functional/fixtures/ext/foo/bar/acp/main_info.php | 10 +++++----- .../functional/fixtures/ext/foo/bar/mcp/main_info.php | 10 +++++----- .../foo/bar/styles/prosilver/template/foobar_mcp.html | 4 ++-- .../functional/fixtures/ext/foo/bar/ucp/main_info.php | 10 +++++----- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php index a5a005c4df..9e79de88a6 100644 --- a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php @@ -25,12 +25,12 @@ class main_info { function module() { - return array( + return [ 'filename' => '\foo\bar\acp\main_module', 'title' => 'ACP_FOOBAR_TITLE', - 'modes' => array( - 'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')), - ), - ); + 'modes' => [ + 'mode' => ['title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => ['ACP_FOOBAR_TITLE']], + ], + ]; } } diff --git a/tests/functional/fixtures/ext/foo/bar/mcp/main_info.php b/tests/functional/fixtures/ext/foo/bar/mcp/main_info.php index b756bec3bd..cad3cf76e4 100644 --- a/tests/functional/fixtures/ext/foo/bar/mcp/main_info.php +++ b/tests/functional/fixtures/ext/foo/bar/mcp/main_info.php @@ -17,12 +17,12 @@ class main_info { function module() { - return array( + return [ 'filename' => '\foo\bar\mcp\main_module', 'title' => 'MCP_FOOBAR_TITLE', - 'modes' => array( - 'mode' => array('title' => 'MCP_FOOBAR_MODE', 'auth' => '', 'cat' => array('MCP_FOOBAR_TITLE')), - ), - ); + 'modes' => [ + 'mode' => ['title' => 'MCP_FOOBAR_MODE', 'auth' => '', 'cat' => ['MCP_FOOBAR_TITLE']], + ], + ]; } } diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_mcp.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_mcp.html index 3ffe34cda4..304d0fbd20 100644 --- a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_mcp.html +++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_mcp.html @@ -1,3 +1,3 @@ - +{% INCLUDE 'overall_header.html' %}
MCP Extension Template Test Passed!
- +{% INCLUDE 'overall_footer.html' %} diff --git a/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php index aa672cb842..26b515a1d6 100644 --- a/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php +++ b/tests/functional/fixtures/ext/foo/bar/ucp/main_info.php @@ -17,12 +17,12 @@ class main_info { function module() { - return array( + return [ 'filename' => '\foo\bar\ucp\main_module', 'title' => 'UCP_FOOBAR_TITLE', - 'modes' => array( - 'mode' => array('title' => 'UCP_FOOBAR_MODE', 'auth' => '', 'cat' => array('UCP_FOOBAR_TITLE')), - ), - ); + 'modes' => [ + 'mode' => ['title' => 'UCP_FOOBAR_MODE', 'auth' => '', 'cat' => ['UCP_FOOBAR_TITLE']], + ], + ]; } }