diff --git a/styles/scaffoldBB/template/event/overall_footer_after.html b/styles/scaffoldBB/template/event/overall_footer_after.html index 916a5877..8bfbc104 100644 --- a/styles/scaffoldBB/template/event/overall_footer_after.html +++ b/styles/scaffoldBB/template/event/overall_footer_after.html @@ -1,2 +1,7 @@ {% INCLUDEJS '@vse_abbc3/js/abbc3.min.js' %} {% INCLUDEJS '@vse_abbc3/js/scaffoldBB.js' %} + \ No newline at end of file diff --git a/styles/scaffoldBB/template/js/scaffoldBB.js b/styles/scaffoldBB/template/js/scaffoldBB.js index b458e9d5..328debef 100644 --- a/styles/scaffoldBB/template/js/scaffoldBB.js +++ b/styles/scaffoldBB/template/js/scaffoldBB.js @@ -1,51 +1,115 @@ -const mainBox = document.querySelector('#abbc3_buttons'); -const buttons = [ ...document.querySelectorAll('#abbc3_buttons .button-secondary') ]; -const selectElements = [ ...document.querySelectorAll('#abbc3_buttons select') ]; -const modal = document.querySelector('#bbcode_wizard'); -const dropdown = document.querySelector('.abbc3_font_menu_btn'); -const dropdownLists = [ ...document.querySelectorAll('.abbc3_font_menu_btn ul') ]; +const abbc3mainBox = document.querySelector("#abbc3_buttons"); +const abbc3buttons = [ + ...document.querySelectorAll("#abbc3_buttons .button-secondary"), +]; +const abbc3selectElements = [ + ...document.querySelectorAll("#abbc3_buttons select"), +]; +const abbc3modal = document.querySelector("#bbcode_wizard"); +const abbc3dropdown = document.querySelector(".abbc3_font_menu_btn"); +const abbc3dropdownLists = [ + ...document.querySelectorAll(".abbc3_font_menu_btn ul"), +]; +const abbc3icons = document.querySelectorAll(".materialbutton .icon"); +abbc3icons.forEach((icon) => { + icon.classList.add("fa"); + icon.parentElement.classList.add("btn", "btn-sm", "btn-secondary"); +}); +const abbc3tables = document.querySelectorAll(".pipe-table"); +abbc3tables.forEach((table) => { + table.parentElement.classList.add("table-responsive"); + table.parentElement.style.lineHeight = "inherit"; + table.parentElement.style.border = "inherit"; + table.classList.add( + "table", + "table-sm", + "table-striped", + "table-bordered", + "table-hover" + ); + table.querySelectorAll("th").forEach((th) => { + th.style.backgroundColor = "var(--bs-table-bg)"; + th.style.color = "var(--bs-body-color)"; + }); +}); -if (mainBox !== null) { - modal.classList.add('modal'); - modal.setAttribute('tabindex', '-1'); - modal.style.cssText += 'border: inherit;font-size: inherit;background: inherit;border-radius: inherit;box-shadow: inherit;top: 0;left: 0;width: 100%;margin-top: unset;margin-left: unset;'; - mainBox.classList.add('my-2', 'gx-0', 'row'); - mainBox.firstElementChild.classList.remove('abbc3_buttons_row'); - mainBox.firstElementChild.classList.add('bg-gradient', 'bg-body', 'border', 'px-3', 'rounded-top'); - mainBox.lastElementChild.classList.remove('abbc3_buttons_row'); - mainBox.lastElementChild.classList.add('bg-gradient', 'bg-body', 'border', 'border-top-0', 'px-3', 'rounded-bottom', 'pt-1', 'pb-2'); +if (abbc3mainBox !== null) { + const abbc3rows = Array.from(abbc3mainBox.children); + abbc3modal.classList.add("modal"); + abbc3modal.setAttribute("tabindex", "-1"); + abbc3modal.style.cssText += + "border: inherit;font-size: inherit;background: inherit;border-radius: inherit;box-shadow: inherit;"; + abbc3mainBox.classList.add("my-2", "gx-0", "row"); + abbc3mainBox.firstElementChild.classList.remove("abbc3_buttons_row"); + abbc3mainBox.firstElementChild.classList.add( + "bg-gradient", + "bg-body", + "border", + "px-3", + "rounded-top" + ); + abbc3mainBox.lastElementChild.classList.remove("abbc3_buttons_row"); + abbc3mainBox.lastElementChild.classList.add( + "bg-gradient", + "bg-body", + "border", + "border-top-0", + "px-3", + "rounded-bottom", + "pt-1", + "pb-2" + ); - if (document.body.contains(document.querySelector('.section-viewtopic'))) { - mainBox.firstElementChild.classList.add('col-md-12'); - mainBox.lastElementChild.classList.add('col-md-12'); + if (document.body.contains(document.querySelector(".section-viewtopic"))) { + abbc3mainBox.firstElementChild.classList.add("col-md-12"); + abbc3mainBox.lastElementChild.classList.add("col-md-12"); } else { - mainBox.firstElementChild.classList.add('col-md-10'); - mainBox.lastElementChild.classList.add('col-md-10'); + abbc3mainBox.firstElementChild.classList.add("col-md-10"); + abbc3mainBox.lastElementChild.classList.add("col-md-10"); } - buttons.forEach(button => { - button.classList.add('btn', 'btn-sm', 'btn-secondary', 'bg-gradient', 'button', 'button-secondary'); + abbc3buttons.forEach((button) => { + button.classList.add( + "btn", + "btn-sm", + "btn-secondary", + "bg-gradient", + "button", + "button-secondary" + ); }); - selectElements.forEach(element => { - element.style.cssText += 'border: 1px solid #ced4da;padding-top: 0.25rem;padding-bottom: 0.25rem;padding-left: 0.5rem;font-size: 0.875rem;border-radius: 0.2rem;height: auto;'; + abbc3selectElements.forEach((element) => { + element.classList.remove("form-select", "form-select-sm"); + element.style.cssText += + "border: 1px solid #ced4da;padding-top: 0.25rem;padding-bottom: 0.25rem;padding-left: 0.5rem;font-size: 0.875rem;border-radius: 0.2rem;height: auto;"; }); - dropdown.classList.add('dropdown'); - dropdown.classList.remove('dropdown-container'); - dropdown.firstElementChild.classList.add('dropdown-toggle'); - dropdown.firstElementChild.classList.remove('dropdown-trigger'); - dropdown.firstElementChild.setAttribute('id', 'abbc3-dropdown'); - dropdown.firstElementChild.setAttribute('data-bs-toggle', 'dropdown'); - dropdown.firstElementChild.setAttribute('aria-expanded', 'false'); - dropdown.firstElementChild.lastChild.remove(); + abbc3dropdown.classList.add("dropdown"); + abbc3dropdown.classList.remove("dropdown-container"); + abbc3dropdown.firstElementChild.classList.add("dropdown-toggle"); + abbc3dropdown.firstElementChild.classList.remove("dropdown-trigger"); + abbc3dropdown.firstElementChild.setAttribute("id", "abbc3-dropdown"); + abbc3dropdown.firstElementChild.setAttribute("data-bs-toggle", "dropdown"); + abbc3dropdown.firstElementChild.setAttribute("aria-expanded", "false"); + abbc3dropdown.firstElementChild.lastChild.remove(); - dropdown.lastElementChild.classList.remove('dropdown'); - dropdown.lastElementChild.classList.add('dropdown-menu'); - dropdown.lastElementChild.setAttribute('aria-labelledby', 'abbc3-dropdown'); - dropdown.lastElementChild.lastElementChild.classList.add('list-unstyled'); - dropdown.lastElementChild.lastElementChild.classList.remove('dropdown-contents'); + abbc3dropdown.lastElementChild.classList.remove("dropdown"); + abbc3dropdown.lastElementChild.classList.add("dropdown-menu"); + abbc3dropdown.lastElementChild.setAttribute( + "aria-labelledby", + "abbc3-dropdown" + ); + abbc3dropdown.lastElementChild.lastElementChild.classList.add( + "list-unstyled" + ); + abbc3dropdown.lastElementChild.lastElementChild.classList.remove( + "dropdown-contents" + ); - dropdownLists.forEach(elem => { - elem.classList.add('list-unstyled', 'dropdown-header'); + abbc3dropdownLists.forEach((elem) => { + elem.classList.add("list-unstyled", "dropdown-header"); + }); + abbc3rows.forEach((row) => { + row.classList.remove("abbc3_buttons_row_legacy"); }); } diff --git a/tests/acp/module_test.php b/tests/acp/acp_test.php similarity index 76% rename from tests/acp/module_test.php rename to tests/acp/acp_test.php index 85f30bc1..6ea1cb5a 100644 --- a/tests/acp/module_test.php +++ b/tests/acp/acp_test.php @@ -15,11 +15,14 @@ require_once __DIR__ . '/../../../../../includes/functions_acp.php'; -class module_test extends \phpbb_database_test_case +class acp_test extends \phpbb_database_test_case { /** @var bool A return value for check_form_key() */ public static $valid_form = false; + /** @var \vse\abbc3\controller\acp_controller */ + protected $acp_controller; + /** @var ContainerInterface|MockObject */ protected $container; @@ -88,28 +91,44 @@ protected function setUp(): void $user->lang = new \phpbb_mock_lang(); } + public function main_module_data() + { + return [ + [0], + [E_USER_NOTICE], + [E_USER_WARNING], + ]; + } + /** - * @return \vse\abbc3\acp\abbc3_module + * @dataProvider main_module_data + * @param $error + * @return void + * @throws \Exception */ - public function get_main_module() + public function test_main_module($error) { - $this->container->expects(self::once()) + $controller = $this->container->expects(self::once()) ->method('get') ->willReturnMap([ ['vse.abbc3.acp_controller', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->acp_controller], ]); - // Test basic module instantiation + if ($error) + { + $controller->willThrowException(new \RuntimeException('ERROR_TEST', $error)); + $this->setExpectedTriggerError($error, 'ERROR_TEST'); + } + $module = new \vse\abbc3\acp\abbc3_module(); - self::assertInstanceOf('\vse\abbc3\acp\abbc3_module', $module); - return $module; + $module->main(); + + self::assertEquals('acp_abbc3_settings', $module->tpl_name); } public function test_main_display() { - $module = $this->get_main_module(); - $this->template->expects(self::once()) ->method('assign_vars') ->with([ @@ -120,56 +139,52 @@ public function test_main_display() 'S_ABBC3_ICONS_TYPE' => build_select(['png' => 'PNG', 'svg' => 'SVG'], $this->config['abbc3_icons_type']), 'S_ABBC3_GOOGLE_FONTS' => "Droid Sans\nRoboto", 'S_ABBC3_MEDIA_EMBED' => 0, - 'U_ACTION' => $module->u_action, + 'U_ACTION' => 'foo', ]); - $module->main(); - - self::assertEquals('acp_abbc3_settings', $module->tpl_name); + $this->acp_controller + ->set_u_action('foo') + ->handle(); } public function test_main_save() { self::$valid_form = true; - $module = $this->get_main_module(); - $this->request->expects(self::once()) ->method('is_set_post') ->willReturn('submit'); - // Throws Notice in PHP 8.0+ and Error in earlier versions - $exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Notice::class; - $this->expectException($exceptionName); + $this->expectException('\RuntimeException'); + $this->expectExceptionCode(E_USER_NOTICE); + $this->expectExceptionMessage('CONFIG_UPDATED'); - $module->main(); + $this->acp_controller->handle(); } public function test_main_save_error() { self::$valid_form = false; - $module = $this->get_main_module(); - $this->request->expects(self::once()) ->method('is_set_post') ->willReturn('submit'); - // Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions - $exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class; - $this->expectException($exceptionName); + $this->expectException('\RuntimeException'); + $this->expectExceptionCode(E_USER_WARNING); + $this->expectExceptionMessage($this->lang->lang('FORM_INVALID')); - $module->main(); + $this->acp_controller->handle(); } public function save_google_fonts_data() { return [ - ['', '[]', \PHPUnit\Framework\Error\Notice::class], - ['Droid Sans', '["Droid Sans"]', \PHPUnit\Framework\Error\Notice::class], - ["Droid Sans\nRoboto", '["Droid Sans","Roboto"]', \PHPUnit\Framework\Error\Notice::class], - ["Droid Sans\nRoboto\nMac Donald", '["Droid Sans","Roboto"]', \PHPUnit\Framework\Error\Warning::class], - ['Mac Donald', '[]', \PHPUnit\Framework\Error\Warning::class], + ['', '[]', E_USER_NOTICE, 'CONFIG_UPDATED'], + ['Droid Sans', '["Droid Sans"]', E_USER_NOTICE, 'CONFIG_UPDATED'], + ["Droid Sans\nRoboto", '["Droid Sans","Roboto"]', E_USER_NOTICE, 'CONFIG_UPDATED'], + ["Droid Sans\nRoboto\nMac Donald", '["Droid Sans","Roboto"]', E_USER_WARNING, 'ABBC3_INVALID_FONT'], + ['Mac Donald', '[]', E_USER_WARNING, 'ABBC3_INVALID_FONT'], ]; } @@ -178,19 +193,21 @@ public function save_google_fonts_data() * @param $input * @param $expected * @param $error - * @throws \Exception + * @param $error_message */ - public function test_save_google_fonts($input, $expected, $error) + public function test_save_google_fonts($input, $expected, $error, $error_message) { self::$valid_form = true; - $module = $this->get_main_module(); - $this->request->expects(self::once()) ->method('is_set_post') ->willReturn('submit'); +<<<<<<< HEAD:tests/acp/module_test.php $this->request +======= + $this->request->expects(self::exactly(6)) +>>>>>>> master:tests/acp/acp_test.php ->method('variable') ->willReturnMap([ ['abbc3_bbcode_bar', 0, false, \phpbb\request\request_interface::REQUEST, 0], @@ -201,11 +218,11 @@ public function test_save_google_fonts($input, $expected, $error) ['abbc3_google_fonts', '', false, \phpbb\request\request_interface::REQUEST, $input], ]); - // Throws Notice in PHP 8.0+ and Error in earlier versions - $exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : $error; - $this->expectException($exceptionName); + $this->expectException('\RuntimeException'); + $this->expectExceptionCode($error); + $this->expectExceptionMessage($error_message); - $module->main(); + $this->acp_controller->handle(); $this->assertSame($expected, $this->config_text->get('abbc3_google_fonts')); } @@ -213,7 +230,6 @@ public function test_save_google_fonts($input, $expected, $error) public function test_info() { $info_class = new \vse\abbc3\acp\abbc3_info(); - self::assertInstanceOf('\vse\abbc3\acp\abbc3_info', $info_class); $info_array = $info_class->module(); self::assertArrayHasKey('filename', $info_array); self::assertEquals('\vse\abbc3\acp\abbc3_module', $info_array['filename']); @@ -229,7 +245,7 @@ public function test_info() */ function check_form_key() { - return \vse\abbc3\controller\module_test::$valid_form; + return \vse\abbc3\controller\acp_test::$valid_form; } /**