function WorkspacesLayoutBuilderIntegrationTest::testBlocksInWorkspaces

Same name in other branches
  1. 10 core/modules/workspaces/tests/src/FunctionalJavascript/WorkspacesLayoutBuilderIntegrationTest.php \Drupal\Tests\workspaces\FunctionalJavascript\WorkspacesLayoutBuilderIntegrationTest::testBlocksInWorkspaces()

Tests changing a layout/blocks inside a workspace.

File

core/modules/workspaces/tests/src/FunctionalJavascript/WorkspacesLayoutBuilderIntegrationTest.php, line 74

Class

WorkspacesLayoutBuilderIntegrationTest
Tests for layout editing in workspaces.

Namespace

Drupal\Tests\workspaces\FunctionalJavascript

Code

public function testBlocksInWorkspaces() : void {
    $assert_session = $this->assertSession();
    $this->drupalGet('node/1');
    $assert_session->pageTextContains('The DEFAULT block body');
    $this->drupalGet('node/2');
    $assert_session->pageTextContains('The DEFAULT block body');
    $stage = Workspace::load('stage');
    $this->switchToWorkspace($stage);
    // Confirm the block can be edited.
    $this->drupalGet('node/1/layout');
    $new_block_body = 'The NEW block body';
    $this->configureInlineBlock('The DEFAULT block body', $new_block_body);
    $this->assertSaveLayout();
    $this->drupalGet('node/1');
    $assert_session->pageTextContains($new_block_body);
    $assert_session->pageTextNotContains('The DEFAULT block body');
    $this->drupalGet('node/2');
    // Node 2 should use default layout.
    $assert_session->pageTextContains('The DEFAULT block body');
    $assert_session->pageTextNotContains($new_block_body);
    // Switch back to the live workspace and verify that the changes are not
    // visible there.
    $this->switchToLive();
    $this->drupalGet('node/1');
    $assert_session->pageTextNotContains($new_block_body);
    $assert_session->pageTextContains('The DEFAULT block body');
    $this->switchToWorkspace($stage);
    // Add a basic block with the body field set.
    $this->drupalGet('node/1/layout');
    $second_block_body = 'The 2nd block body';
    $this->addInlineBlockToLayout('2nd Block title', $second_block_body);
    $this->assertSaveLayout();
    $this->drupalGet('node/1');
    $assert_session->pageTextContains($second_block_body);
    $this->drupalGet('node/2');
    // Node 2 should use default layout.
    $assert_session->pageTextContains('The DEFAULT block body');
    $assert_session->pageTextNotContains($new_block_body);
    $assert_session->pageTextNotContains($second_block_body);
    // Switch back to the live workspace and verify that the new added block is
    // not visible there.
    $this->switchToLive();
    $this->drupalGet('node/1');
    $assert_session->pageTextNotContains($second_block_body);
    $assert_session->pageTextContains('The DEFAULT block body');
    // Check the concurrent editing protection on the Layout Builder form.
    $this->drupalGet('/node/1/layout');
    $assert_session->pageTextContains('The content is being edited in the Stage workspace. As a result, your changes cannot be saved.');
    $stage->publish();
    $this->drupalGet('node/1');
    $assert_session->pageTextNotContains('The DEFAULT block body');
    $assert_session->pageTextContains($new_block_body);
    $assert_session->pageTextContains($second_block_body);
}

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