function LayoutBuilderToolbarTest::testBackToSiteLink

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderToolbarTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderToolbarTest::testBackToSiteLink()
  2. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderToolbarTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderToolbarTest::testBackToSiteLink()
  3. 11.x core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderToolbarTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderToolbarTest::testBackToSiteLink()

Tests the 'Back to site' link behaves with manage layout as admin page.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderToolbarTest.php, line 62

Class

LayoutBuilderToolbarTest
Test Layout Builder integration with Toolbar.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testBackToSiteLink() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $this->drupalLogin($this->drupalCreateUser([
        'configure any layout',
        'access administration pages',
        'administer node display',
        'administer node fields',
        'access toolbar',
    ]));
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
    // From the manage display page, go to manage the layout.
    $this->drupalGet("{$field_ui_prefix}/display/default");
    $this->submitForm([
        'layout[enabled]' => TRUE,
    ], 'Save');
    $assert_session->linkExists('Manage layout');
    $this->clickLink('Manage layout');
    // Save the defaults.
    $page->pressButton('Save layout');
    $assert_session->addressEquals("{$field_ui_prefix}/display/default");
    // As the Layout Builder UI is typically displayed using the frontend theme,
    // it is not marked as an administrative page at the route level even though
    // it performs an administrative task, therefore, we need to verify that it
    // behaves as such, redirecting out of the admin section.
    // Clicking "Back to site" navigates to the homepage.
    $this->drupalGet("{$field_ui_prefix}/display/default/layout");
    $this->clickLink('Back to site');
    $assert_session->addressEquals("/user/2");
    $this->drupalGet("{$field_ui_prefix}/display/default/layout/discard-changes");
    $page->pressButton('Confirm');
    $this->clickLink('Back to site');
    $assert_session->addressEquals("/user/2");
    $this->drupalGet("{$field_ui_prefix}/display/default/layout/disable");
    $page->pressButton('Confirm');
    $this->clickLink('Back to site');
    $assert_session->addressEquals("/user/2");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.