function LayoutBuilderOverridesEditingThemeTest::testEditing

Same name in other branches
  1. 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderOverridesEditingThemeTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderOverridesEditingThemeTest::testEditing()

Tests editing block content with Layout Builder.

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderOverridesEditingThemeTest.php, line 75

Class

LayoutBuilderOverridesEditingThemeTest
Tests overrides editing uses the correct theme.

Namespace

Drupal\Tests\layout_builder\Functional

Code

public function testEditing() : void {
    // Create a new role for additional permissions needed.
    $role = Role::create([
        'id' => 'layout_builder_tester',
        'label' => 'Layout Builder Tester',
    ]);
    // Set a different theme for the admin pages. So we can assert the theme
    // in Layout Builder is not the same as the admin theme.
    \Drupal::service('theme_installer')->install([
        'claro',
    ]);
    $this->config('system.theme')
        ->set('admin', 'claro')
        ->save();
    // Enable layout builder for the block content display.
    $display = LayoutBuilderEntityViewDisplay::create([
        'targetEntityType' => 'block_content',
        'bundle' => 'basic',
        'mode' => 'default',
        'status' => TRUE,
    ]);
    $display->save();
    $this->enableLayoutBuilder($display);
    $role->grantPermission('configure all basic block_content layout overrides');
    $role->save();
    $this->adminUser
        ->addRole($role->id())
        ->save();
    $this->drupalLogin($this->adminUser);
    // Create a block content and test the themes used.
    $blockContent = BlockContent::create([
        'info' => $this->randomMachineName(),
        'type' => 'basic',
        'langcode' => 'en',
    ]);
    $blockContent->save();
    // Assert the test_theme is being used for overrides.
    $this->drupalGet('admin/content/block/' . $blockContent->id() . '/layout');
    $this->assertSession()
        ->statusCodeEquals(200);
    // Assert the test_theme is being used.
    $this->assertSession()
        ->responseContains('test_theme/kitten.css');
    // Assert the claro theme is not being used.
    $this->assertSession()
        ->elementNotExists('css', '#block-claro-content');
    // Assert the default still uses the test_theme.
    $this->drupalGet('admin/structure/block-content/manage/basic/display/default/layout');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->responseContains('test_theme/kitten.css');
    $this->assertSession()
        ->elementNotExists('css', '#block-claro-content');
}

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