You are here

public function QuickEditIntegrationTest::testCustomBlock in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditIntegrationTest::testCustomBlock()

Tests if a custom can be in-place edited with Quick Edit.

File

core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditIntegrationTest.php, line 295

Class

QuickEditIntegrationTest
@group quickedit

Namespace

Drupal\Tests\quickedit\FunctionalJavascript

Code

public function testCustomBlock() {
  $block_content_type = BlockContentType::create([
    'id' => 'basic',
    'label' => 'basic',
    'revision' => FALSE,
  ]);
  $block_content_type
    ->save();
  block_content_add_body_field($block_content_type
    ->id());
  $block_content = BlockContent::create([
    'info' => 'Llama',
    'type' => 'basic',
    'body' => [
      'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
      'format' => 'some_format',
    ],
  ]);
  $block_content
    ->save();
  $this
    ->drupalPlaceBlock('block_content:' . $block_content
    ->uuid(), [
    'label' => 'My custom block!',
  ]);
  $this
    ->drupalGet('');

  // Initial state.
  $this
    ->awaitQuickEditForEntity('block_content', 1);
  $this
    ->assertEntityInstanceStates([
    'block_content/1[0]' => 'closed',
  ]);

  // Start in-place editing of the article node.
  $this
    ->startQuickEditViaToolbar('block_content', 1, 0);
  $this
    ->assertEntityInstanceStates([
    'block_content/1[0]' => 'opened',
  ]);
  $this
    ->assertQuickEditEntityToolbar((string) $block_content
    ->label(), 'Body');
  $this
    ->assertEntityInstanceFieldStates('block_content', 1, 0, [
    'block_content/1/body/en/full' => 'highlighted',
  ]);

  // Click the body field.
  $this
    ->click('[data-quickedit-entity-id="block_content/1"] .field--name-body');
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->waitForElement('css', '.quickedit-toolbar-field div[id*="body"]');
  $this
    ->assertQuickEditEntityToolbar((string) $block_content
    ->label(), 'Body');
  $this
    ->assertEntityInstanceFieldStates('block_content', 1, 0, [
    'block_content/1/body/en/full' => 'active',
  ]);
  $this
    ->assertEntityInstanceFieldMarkup([
    'block_content/1/body/en/full' => '.cke_editable_inline',
  ]);
  $this
    ->assertSession()
    ->elementExists('css', '#quickedit-entity-toolbar .quickedit-toolgroup.wysiwyg-main > .cke_chrome .cke_top[role="presentation"] .cke_toolbar[role="toolbar"] .cke_toolgroup[role="presentation"] > .cke_button[title~="Bold"][role="button"]');
}