function LayoutBuilderIntegrationTest::testCustomBlock

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

File

core/modules/quickedit/tests/src/FunctionalJavascript/LayoutBuilderIntegrationTest.php, line 289

Class

LayoutBuilderIntegrationTest
@group quickedit @group legacy

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',
    ]);
    // The label 'body' will only be shown when the pointer hovers over the
    // body. This can't be guaranteed by "just" opening the block in QuickEdit.
    // We explicitly move the pointer first over the page title and afterwards
    // over the block body to be sure.
    $this->movePointerTo('.page-title');
    $this->movePointerTo('[data-quickedit-field-id="block_content/1/body/en/full"]');
    $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"]');
}

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