function BlockContentThemeSuggestionsTest::testBlockContentThemeSuggestionsExtraField

Test suggestions for content blocks within extra fields blocks.

File

core/modules/block_content/tests/src/Functional/BlockContentThemeSuggestionsTest.php, line 68

Class

BlockContentThemeSuggestionsTest
Tests block content theme suggestions.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testBlockContentThemeSuggestionsExtraField() : void {
    // Extra field blocks are a block plugin provided by layout builder, so
    // enable layouts for the test bundle and view a node of that bundle.
    // A test module injects an extra field referencing a block content entity.
    // @see block_content_theme_suggestions_test.module
    // @see \Drupal\block_content_theme_suggestions_test\Hook\BlockContentThemeSuggestionsTestHooks
    $this->drupalLogin($this->drupalCreateUser([
        'configure any layout',
        'administer node display',
    ]));
    $this->createContentType([
        'type' => 'bundle_with_extra_field',
    ]);
    $this->drupalGet(static::FIELD_UI_PREFIX . '/display/default');
    $this->submitForm([
        'layout[enabled]' => TRUE,
    ], 'Save');
    $node = $this->createNode([
        'type' => 'bundle_with_extra_field',
        'title' => 'The first node title',
    ]);
    $node->save();
    $this->drupalGet('/node/' . $node->id());
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains('Example block!');
    $this->assertSession()
        ->pageTextContains('I am a block content template for a specific bundle and view mode!');
}

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