function InlineBlockTest::testAddWorkFlow

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

Tests the workflow for adding an inline block depending on number of types.

Throws

\Behat\Mink\Exception\ElementNotFoundException

\Behat\Mink\Exception\ExpectationException

File

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

Class

InlineBlockTest
Tests that the inline block feature works correctly.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testAddWorkFlow() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $type_storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('block_content_type');
    foreach ($type_storage->loadByProperties() as $type) {
        $type->delete();
    }
    $this->drupalLogin($this->drupalCreateUser([
        'access contextual links',
        'configure any layout',
        'administer node display',
        'administer node fields',
        'create and edit custom blocks',
    ]));
    // Enable layout builder and overrides.
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default');
    $this->submitForm([
        'layout[enabled]' => TRUE,
        'layout[allow_custom]' => TRUE,
    ], 'Save');
    $layout_default_path = 'admin/structure/types/manage/bundle_with_section_field/display/default/layout';
    $this->drupalGet($layout_default_path);
    // Add a basic block with the body field set.
    $page->clickLink('Add block');
    $assert_session->assertWaitOnAjaxRequest();
    // Confirm that with no block content types the link does not appear.
    $assert_session->linkNotExists('Create content block');
    $this->createBlockContentType('basic', 'Basic block');
    $this->drupalGet($layout_default_path);
    // Add a basic block with the body field set.
    $page->clickLink('Add block');
    $assert_session->assertWaitOnAjaxRequest();
    // Confirm with only 1 type the "Create content block" link goes directly t
    // block add form.
    $assert_session->linkNotExists('Basic block');
    $this->clickLink('Create content block');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->fieldExists('Title');
    $this->createBlockContentType('advanced', 'Advanced block');
    $this->drupalGet($layout_default_path);
    // Add a basic block with the body field set.
    $page->clickLink('Add block');
    // Confirm that, when more than 1 type exists, "Create content block" shows a
    // list of block types.
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->linkNotExists('Basic block');
    $assert_session->linkNotExists('Advanced block');
    $this->clickLink('Create content block');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->fieldNotExists('Title');
    $assert_session->linkExists('Basic block');
    $assert_session->linkExists('Advanced block');
    $this->clickLink('Advanced block');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->fieldExists('Title');
}

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