mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-23 10:28:55 +00:00
Merge pull request #6530 from rxu/ticket/17151
[ticket/17151] Make macros available for extensions
This commit is contained in:
commit
fd4ffe58ac
21 changed files with 464 additions and 162 deletions
|
@ -618,8 +618,6 @@ class acp_modules
|
|||
|
||||
$langname = $user->lang($row['module_langname']);
|
||||
$module_list .= '<option value="' . $row['module_id'] . '"' . $selected . ((!$row['module_enabled']) ? ' class="disabled"' : '') . '>' . $padding . $langname . '</option>';
|
||||
|
||||
$iteration++;
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
|
|
|
@ -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/',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -25,12 +25,12 @@ class main_info
|
|||
{
|
||||
function module()
|
||||
{
|
||||
return array(
|
||||
'filename' => 'foo\bar\acp\main_module',
|
||||
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']],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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('<br />', $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 '
|
||||
<option value="1" selected="selected">Option 1</option>
|
||||
<option value="2">Option 2</option>
|
||||
<option value="3">Option 3</option>
|
||||
';
|
||||
}
|
||||
|
||||
function submit_button()
|
||||
{
|
||||
return '<input class="button2" type="submit" id="test_button" value="Test submit button" />';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,32 @@
|
|||
<!-- INCLUDE overall_header.html -->
|
||||
Bertie rulez!
|
||||
<h1>{{ lang('TITLE') }}</h1>
|
||||
<p>{{ lang('TITLE_EXPLAIN') }}</p>
|
||||
{% if S_ERROR %}
|
||||
<div class="errorbox">
|
||||
<h3>{{ lang('WARNING') }}</h3>
|
||||
<p>{{ ERROR_MSG }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% for options in loops.options %}
|
||||
{% if options.S_LEGEND %}
|
||||
{% if not options.S_FIRST_ROW %}
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
<fieldset>
|
||||
<legend>{{ options.LEGEND }}</legend>
|
||||
{% else %}
|
||||
<dl>
|
||||
<dt><label for="{{ options.KEY }}">{{ options.TITLE }}{{ lang('COLON') }}</label>{% if options.S_EXPLAIN %}<br /><span>{{ options.TITLE_EXPLAIN }}</span>{% endif %}</dt>
|
||||
<dd>
|
||||
{% if options.CONTENT is iterable %}
|
||||
{{ FormsBuildTemplate(options.CONTENT) }}
|
||||
{% else %}
|
||||
{{ options.CONTENT }}
|
||||
{% endif %}
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<!-- INCLUDE overall_footer.html -->
|
||||
|
|
28
tests/functional/fixtures/ext/foo/bar/mcp/main_info.php
Normal file
28
tests/functional/fixtures/ext/foo/bar/mcp/main_info.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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 [
|
||||
'filename' => '\foo\bar\mcp\main_module',
|
||||
'title' => 'MCP_FOOBAR_TITLE',
|
||||
'modes' => [
|
||||
'mode' => ['title' => 'MCP_FOOBAR_MODE', 'auth' => '', 'cat' => ['MCP_FOOBAR_TITLE']],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
25
tests/functional/fixtures/ext/foo/bar/mcp/main_module.php
Normal file
25
tests/functional/fixtures/ext/foo/bar/mcp/main_module.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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' => '',
|
||||
]]],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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' => '',
|
||||
]]],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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]],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
*
|
||||
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||
* @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' => '',
|
||||
]]],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{% INCLUDE 'overall_header.html' %}
|
||||
<div id="content">MCP Extension Template Test Passed!</div>
|
||||
{% INCLUDE 'overall_footer.html' %}
|
|
@ -17,12 +17,12 @@ class main_info
|
|||
{
|
||||
function module()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'filename' => '\foo\bar\ucp\main_module',
|
||||
'title' => 'ACP_FOOBAR_TITLE',
|
||||
'modes' => array(
|
||||
'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')),
|
||||
),
|
||||
);
|
||||
'title' => 'UCP_FOOBAR_TITLE',
|
||||
'modes' => [
|
||||
'mode' => ['title' => 'UCP_FOOBAR_MODE', 'auth' => '', 'cat' => ['UCP_FOOBAR_TITLE']],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue