diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/ContentPreviewToggleTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/ContentPreviewToggleTest.php index ae4db73be9..ecf96abfc1 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/ContentPreviewToggleTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/ContentPreviewToggleTest.php @@ -99,7 +99,7 @@ public function testContentPreviewToggle() { $assert_session->elementExists('css', $links_block . " div"); $assert_session->elementExists('css', $body_block . " div"); - $this->sortAfter($links_block, $body_block, $region_content); + $this->sortableAfter($links_block, $body_block, $region_content); $assert_session->assertWaitOnAjaxRequest(); // Check that the drag-triggered rebuild did not trigger content preview. diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderSortTrait.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderSortTrait.php index 4c12432279..03e6304ec6 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderSortTrait.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderSortTrait.php @@ -2,22 +2,21 @@ namespace Drupal\Tests\layout_builder\FunctionalJavascript; +use Drupal\FunctionalJavascriptTests\SortableTestTrait; + /** - * Functions for simulating layout changes. + * Trait LayoutBuilderSortTrait, calls Drupal.layoutBuilderBlockUpdate. + * + * @package Drupal\Tests\layout_builder\FunctionalJavascript */ trait LayoutBuilderSortTrait { + use SortableTestTrait; + /** - * Callback for ajax update. - * - * @param string $item - * The HTML selector for the element to be moved. - * @param string $from - * The HTML selector for the previous container element. - * @param null|string $to - * The HTML selector for the target container. + * {@inheritdoc} */ - private function sortUpdate($item, $from, $to = NULL) { + protected function sortableUpdate($item, $from, $to = NULL) { // If container does not change, $from and $to are equal. $to = $to ?? $from; @@ -41,74 +40,4 @@ private function sortUpdate($item, $from, $to = NULL) { $this->getSession()->getDriver()->getWebDriverSession()->execute($options); } - /** - * Simulates a drag on an element from one container to another. - * - * @param string $item - * The HTML selector for the element to be moved. - * @param string $from - * The HTML selector for the previous container element. - * @param null|string $to - * The HTML selector for the target container. - */ - protected function sortTo($item, $from, $to) { - - $item = addslashes($item); - $from = addslashes($from); - $to = addslashes($to); - - $script = << $script, - 'args' => [], - ]; - - $this->getSession()->getDriver()->getWebDriverSession()->execute($options); - $this->sortUpdate($item, $from, $to); - } - - /** - * Simulates a drag moving an element after its sibling in the same container. - * - * @param string $item - * The HTML selector for the element to be moved. - * @param string $target - * The HTML selector for the sibling element. - * @param string $from - * The HTML selector for the element container. - */ - protected function sortAfter($item, $target, $from) { - - $item = addslashes($item); - $target = addslashes($target); - $from = addslashes($from); - - $script = << $script, - 'args' => [], - ]; - - $this->getSession()->getDriver()->getWebDriverSession()->execute($options); - $this->sortUpdate($item, $from); - } - } diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php index 68afd5be4d..fa274bc119 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php @@ -159,39 +159,34 @@ public function testLayoutBuilderUi() { $page->pressButton('Add section'); $assert_session->assertWaitOnAjaxRequest(); - $region_content = '.layout__region--content'; - $region_second = '.layout__region--second'; - $block_selector = '.block-system-powered-by-block'; - $block_text = 'Powered by Drupal'; - - $assert_session->assertNoElementAfterWait('css', $region_second . ' ' . $block_selector); - $assert_session->elementTextNotContains('css', $region_second, $block_text); + $assert_session->assertNoElementAfterWait('css', '.layout__region--second .block-system-powered-by-block'); + $assert_session->elementTextNotContains('css', '.layout__region--second', 'Powered by Drupal'); // Drag the block to a region in different section. - $this->sortTo($block_selector, $region_content, $region_second); + $this->sortableTo('.block-system-powered-by-block', '.layout__region--content', '.layout__region--second'); $assert_session->assertWaitOnAjaxRequest(); // Ensure the drag succeeded. - $assert_session->elementExists('css', $region_second . ' ' . $block_selector); - $assert_session->elementTextContains('css', $region_second, $block_text); + $assert_session->elementExists('css', '.layout__region--second .block-system-powered-by-block'); + $assert_session->elementTextContains('css', '.layout__region--second', 'Powered by Drupal'); $this->assertPageNotReloaded(); // Ensure the dragged block is still in the correct position after reload. $this->drupalGet($layout_url); - $assert_session->elementExists('css', $region_second . ' ' . $block_selector); - $assert_session->elementTextContains('css', $region_second, $block_text); + $assert_session->elementExists('css', '.layout__region--second .block-system-powered-by-block'); + $assert_session->elementTextContains('css', '.layout__region--second', 'Powered by Drupal'); // Ensure the dragged block is still in the correct position after save. $page->pressButton('Save layout'); - $assert_session->elementExists('css', $region_second . ' ' . $block_selector); - $assert_session->elementTextContains('css', $region_second, $block_text); + $assert_session->elementExists('css', '.layout__region--second .block-system-powered-by-block'); + $assert_session->elementTextContains('css', '.layout__region--second', 'Powered by Drupal'); // Reconfigure a block and ensure that the layout content is updated. $this->drupalGet($layout_url); $this->markCurrentPage(); - $this->clickContextualLink($block_selector, 'Configure'); + $this->clickContextualLink('.block-system-powered-by-block', 'Configure'); $this->assertOffCanvasFormAfterWait('layout_builder_update_block'); $page->fillField('settings[label]', 'This is the new label'); @@ -200,12 +195,12 @@ public function testLayoutBuilderUi() { $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas'); $assert_session->addressEquals($layout_url); - $assert_session->pageTextContains($block_text); + $assert_session->pageTextContains('Powered by Drupal'); $assert_session->pageTextContains('This is the new label'); $assert_session->pageTextNotContains('This is the label'); // Remove a block. - $this->clickContextualLink($block_selector, 'Remove block'); + $this->clickContextualLink('.block-system-powered-by-block', 'Remove block'); $this->assertOffCanvasFormAfterWait('layout_builder_remove_block'); $assert_session->pageTextContains('Are you sure you want to remove the This is the new label block?'); $assert_session->pageTextContains('This action cannot be undone.'); @@ -213,7 +208,7 @@ public function testLayoutBuilderUi() { $assert_session->assertWaitOnAjaxRequest(); $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas'); - $assert_session->pageTextNotContains($block_text); + $assert_session->pageTextNotContains('Powered by Drupal'); $assert_session->linkExists('Add block'); $assert_session->addressEquals($layout_url); $this->assertPageNotReloaded(); diff --git a/core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php b/core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php new file mode 100644 index 0000000000..6688bd9b74 --- /dev/null +++ b/core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php @@ -0,0 +1,92 @@ + $script, + 'args' => [], + ]; + + $this->getSession()->getDriver()->getWebDriverSession()->execute($options); + $this->sortableUpdate($item, $from, $to); + } + + /** + * Simulates a drag moving an element after its sibling in the same container. + * + * @param string $item + * The HTML selector for the element to be moved. + * @param string $target + * The HTML selector for the sibling element. + * @param string $from + * The HTML selector for the element container. + */ + protected function sortableAfter($item, $target, $from) { + + $item = addslashes($item); + $target = addslashes($target); + $from = addslashes($from); + + $script = << $script, + 'args' => [], + ]; + + $this->getSession()->getDriver()->getWebDriverSession()->execute($options); + $this->sortableUpdate($item, $from); + } + +}