function InlineBlockTest::testInlineBlocks

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

Tests adding and editing of inline blocks.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php, line 33

Class

InlineBlockTest
Tests that the inline block feature works correctly.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testInlineBlocks() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $this->drupalLogin($this->drupalCreateUser([
        'access contextual links',
        'configure any layout',
        'administer node display',
        'administer node fields',
        'create and edit custom blocks',
    ]));
    // Enable layout builder.
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default');
    $this->submitForm([
        'layout[enabled]' => TRUE,
    ], 'Save');
    $this->clickLink('Manage layout');
    $assert_session->addressEquals(static::FIELD_UI_PREFIX . '/display/default/layout');
    // Add a basic block with the body field set.
    $this->addInlineBlockToLayout('Block title', 'The DEFAULT block body');
    $this->assertSaveLayout();
    $this->drupalGet('node/1');
    $assert_session->pageTextContains('The DEFAULT block body');
    $this->drupalGet('node/2');
    $assert_session->pageTextContains('The DEFAULT block body');
    // Enable overrides.
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default');
    $this->submitForm([
        'layout[allow_custom]' => TRUE,
    ], 'Save');
    $this->drupalGet('node/1/layout');
    // Confirm the block can be edited.
    $this->drupalGet('node/1/layout');
    $this->configureInlineBlock('The DEFAULT block body', 'The NEW block body!');
    $this->assertSaveLayout();
    $this->drupalGet('node/1');
    $assert_session->pageTextContains('The 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('The NEW block body');
    // Add a basic block with the body field set.
    $this->drupalGet('node/1/layout');
    $this->addInlineBlockToLayout('2nd Block title', 'The 2nd block body');
    $this->assertSaveLayout();
    $this->drupalGet('node/1');
    $assert_session->pageTextContains('The NEW block body!');
    $assert_session->pageTextContains('The 2nd block body');
    $this->drupalGet('node/2');
    // Node 2 should use default layout.
    $assert_session->pageTextContains('The DEFAULT block body');
    $assert_session->pageTextNotContains('The NEW block body');
    $assert_session->pageTextNotContains('The 2nd block body');
    // Confirm the block can be edited.
    $this->drupalGet('node/1/layout');
    
    /** @var \Behat\Mink\Element\NodeElement $inline_block_2 */
    $inline_block_2 = $page->findAll('css', static::INLINE_BLOCK_LOCATOR)[1];
    $uuid = $inline_block_2->getAttribute('data-layout-block-uuid');
    $block_css_locator = static::INLINE_BLOCK_LOCATOR . "[data-layout-block-uuid=\"{$uuid}\"]";
    $this->configureInlineBlock('The 2nd block body', 'The 2nd NEW block body!', $block_css_locator);
    $this->assertSaveLayout();
    $this->drupalGet('node/1');
    $assert_session->pageTextContains('The NEW block body!');
    $assert_session->pageTextContains('The 2nd NEW block body!');
    $this->drupalGet('node/2');
    // Node 2 should use default layout.
    $assert_session->pageTextContains('The DEFAULT block body');
    $assert_session->pageTextNotContains('The NEW block body!');
    $assert_session->pageTextNotContains('The 2nd NEW block body!');
    // The default layout entity block should be changed.
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default/layout');
    $assert_session->pageTextContains('The DEFAULT block body');
    // Confirm default layout still only has 1 entity block.
    $assert_session->elementsCount('css', static::INLINE_BLOCK_LOCATOR, 1);
}

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