You are here

public function InlineBlockTest::testAddWorkFlow in Drupal 9

Same name and namespace in other branches
  1. 8 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 521

Class

InlineBlockTest
Tests that the inline block feature works correctly.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testAddWorkFlow() {
  $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 custom 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 custom block" link goes directly t
  // block add form.
  $assert_session
    ->linkNotExists('Basic block');
  $this
    ->clickLink('Create custom 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 custom block" shows a
  // list of block types.
  $assert_session
    ->assertWaitOnAjaxRequest();
  $assert_session
    ->linkNotExists('Basic block');
  $assert_session
    ->linkNotExists('Advanced block');
  $this
    ->clickLink('Create custom 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');
}