diff --git a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php index dc7aa1b..4409294 100644 --- a/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php +++ b/core/modules/outside_in/tests/src/FunctionalJavascript/OutsideInBlockFormTest.php @@ -50,33 +50,72 @@ protected function setUp() { /** * Tests opening Offcanvas tray by click blocks and elements in the blocks. * - * @todo Remove this function if testBlockWithProvider works without random fails. + * @dataProvider providerTestBlocks */ - public function testBlocks() { - $blocks = $this->providerTestBlocks(); - foreach ($blocks as $block_info) { - $this->individualBlockTest($block_info); + public function testBlocks($block_id, $new_page_text, $element_selector, $button_text, $toolbar_item) { + $web_assert = $this->assertSession(); + $page = $this->getSession()->getPage(); + $block_selector = '#' . $block_id; + $this->drupalGet('user'); + if (isset($toolbar_item)) { + // Check that you can open a toolbar tray and it will be closed after + // entering edit mode. + if ($element = $page->find('css', "#toolbar-administration a.is-active")) { + // If a tray was open from page load close it. + $element->click(); + $this->waitForNoElement("#toolbar-administration a.is-active"); + } + $page->find('css', $toolbar_item)->click(); + $this->waitForElement("{$toolbar_item}.is-active"); + } + $this->toggleEditingMode(); + if (isset($toolbar_item)) { + $this->waitForNoElement("{$toolbar_item}.is-active"); } - } - /** - * USING DATAPROVIDER: Tests opening Offcanvas tray by click blocks and elements in the blocks. - * - * @dataProvider providerTestBlocks - */ - public function testBlockWithProvider($id, $new_page_text, $element_selector, $button_text, $toolbar_item) { - $block_info = [ - 'id' => $id, - 'new_page_text' => $new_page_text, - 'element_selector' => $element_selector, - 'button_text' => $button_text, - 'toolbar_item' => $toolbar_item, - ]; - $this->individualBlockTest($block_info); + $this->openBlockForm($block_selector); + + switch ($block_id) { + case 'block-powered': + // Fill out form, save the form. + $page->fillField('settings[label]', $new_page_text); + $page->checkField('settings[label_display]'); + break; + + case 'block-branding': + // Fill out form, save the form. + $page->fillField('settings[site_information][site_name]', $new_page_text); + break; + } + + if (isset($new_page_text)) { + $page->pressButton($button_text); + // Make sure the changes are present. + $this->assertSession()->assertWaitOnAjaxRequest(); + $web_assert->pageTextContains($new_page_text); + } + + $this->openBlockForm($block_selector); + + $this->toggleEditingMode(); + // Canvas should close when editing module is closed. + $this->waitForOffCanvasToClose(); + + // Go into Edit mode again. + $this->toggleEditingMode(); + + $element_selector = "$block_selector {$element_selector}"; + // Open block form by clicking a element inside the block. + // This confirms that default action for links and form elements is + // suppressed. + $this->openBlockForm($element_selector); + + // Exit edit mode. + $this->toggleEditingMode(); } /** - * Dataprovider for + * Dataprovider for testBlocks(). */ public function providerTestBlocks() { $blocks = [ @@ -143,72 +182,4 @@ protected function openBlockForm($block_selector) { $this->assertOffCanvasBlockFormIsValid(); } - /** - * Test with info for an individual block. - * - * @param array $block - * Block info. - */ - protected function individualBlockTest($block) { - $web_assert = $this->assertSession(); - $page = $this->getSession()->getPage(); - $block_selector = '#' . $block['id']; - $this->drupalGet('user'); - if (isset($block['toolbar_item'])) { - // Check that you can open a toolbar tray and it will be closed after - // entering edit mode. - if ($element = $page->find('css', "#toolbar-administration a.is-active")) { - // If a tray was open from page load close it. - $element->click(); - $this->waitForNoElement("#toolbar-administration a.is-active"); - } - $page->find('css', $block['toolbar_item'])->click(); - $this->waitForElement("{$block['toolbar_item']}.is-active"); - } - $this->toggleEditingMode(); - if (isset($block['toolbar_item'])) { - $this->waitForNoElement("{$block['toolbar_item']}.is-active"); - } - - $this->openBlockForm($block_selector); - - switch ($block['id']) { - case 'block-powered': - // Fill out form, save the form. - $page->fillField('settings[label]', $block['new_page_text']); - $page->checkField('settings[label_display]'); - break; - - case 'block-branding': - // Fill out form, save the form. - $page->fillField('settings[site_information][site_name]', $block['new_page_text']); - break; - } - - if (isset($block['new_page_text'])) { - $page->pressButton($block['button_text']); - // Make sure the changes are present. - $this->assertSession()->assertWaitOnAjaxRequest(); - $web_assert->pageTextContains($block['new_page_text']); - } - - $this->openBlockForm($block_selector); - - $this->toggleEditingMode(); - // Canvas should close when editing module is closed. - $this->waitForOffCanvasToClose(); - - // Go into Edit mode again. - $this->toggleEditingMode(); - - $element_selector = "$block_selector {$block['element_selector']}"; - // Open block form by clicking a element inside the block. - // This confirms that default action for links and form elements is - // suppressed. - $this->openBlockForm($element_selector); - - // Exit edit mode. - $this->toggleEditingMode(); - } - }