function LayoutBuilderBlocksTest::testLayoutBuilderChooseBlocksAlter
Same name and namespace in other branches
- 11.x core/modules/layout_builder/tests/src/Functional/LayoutBuilderBlocksTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderBlocksTest::testLayoutBuilderChooseBlocksAlter()
- 10 core/modules/layout_builder/tests/src/Functional/LayoutBuilderBlocksTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderBlocksTest::testLayoutBuilderChooseBlocksAlter()
Tests altering block definitions in the choose block controller.
See also
\Drupal\layout_builder_test\Hook\LayoutBuilderTestHooks::pluginFilterBlockLayoutBuilderAlter
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderBlocksTest.php, line 93
Class
- LayoutBuilderBlocksTest
- Tests the Layout Builder UI with blocks.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
public function testLayoutBuilderChooseBlocksAlter() : void {
\Drupal::service('module_installer')->install([
'block_content',
]);
$assert_session = $this->assertSession();
// Create 2 block content types so the inline block list displays.
BlockContentType::create([
'id' => 'not_hidden_type',
'label' => 'I can be added to all sections',
])->save();
BlockContentType::create([
'id' => 'hidden_type',
'label' => 'I cannot be added to the first section',
])->save();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
'create and edit custom blocks',
]));
// Enable layout builder and go to manage the layout.
LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')->enableLayoutBuilder()
->save();
$manageLayoutUrl = Url::fromRoute('layout_builder.defaults.node.view', [
'node_type' => 'bundle_with_section_field',
'view_mode_name' => 'default',
]);
$this->drupalGet($manageLayoutUrl);
// Add a new block.
$this->clickLink('Add block');
// Verify that blocks not modified are present.
$assert_session->linkExists('Powered by Drupal');
$assert_session->linkExists('Default revision');
// Verify that blocks explicitly removed are not present.
$assert_session->linkNotExists('Help');
$assert_session->linkNotExists('Sticky at top of lists');
$assert_session->linkNotExists('Main page content');
$assert_session->linkNotExists('Page title');
$assert_session->linkNotExists('Messages');
$assert_session->linkNotExists('Help');
$assert_session->linkNotExists('Tabs');
$assert_session->linkNotExists('Primary admin actions');
// Verify that Changed block is not present on first section.
$assert_session->linkNotExists('Changed');
// Verify the inline block list is also filtered.
$this->clickLink('Create content block');
$assert_session->linkExists('I can be added to all sections');
$assert_session->linkNotExists('I cannot be added to the first section');
// Go back to Manage layout.
$this->drupalGet($manageLayoutUrl);
// Add a new section.
$this->clickLink('Add section', 1);
$assert_session->linkExists('Two column');
$this->clickLink('Two column');
$assert_session->buttonExists('Add section');
$this->getSession()
->getPage()
->pressButton('Add section');
// Add a new block to second section.
$this->clickLink('Add block', 1);
// Verify that Changed block is present on second section.
$assert_session->linkExists('Changed');
// Verify the inline block type is present on the second section.
$this->clickLink('Create content block');
$assert_session->linkExists('I can be added to all sections');
$assert_session->linkExists('I cannot be added to the first section');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.