Skip to content
Snippets Groups Projects
Verified Commit d5208fb8 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3390033 by catch, smustgrave: Split up LayoutBuilderTest

parent fec7c654
No related branches found
No related tags found
No related merge requests found
<?php
namespace Drupal\Tests\layout_builder\Functional;
use Drupal\node\Entity\Node;
use Drupal\views\Entity\View;
/**
* Tests the Layout Builder UI with blocks.
*
* @group layout_builder
* @group #slow
*/
class LayoutBuilderBlocksTest extends LayoutBuilderTestBase {
/**
* Tests that block plugins can define custom attributes and contextual links.
*/
public function testPluginsProvidingCustomAttributesAndContextualLinks() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'access contextual links',
'configure any layout',
'administer node display',
]));
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
$page->clickLink('Manage layout');
$page->clickLink('Add section');
$page->clickLink('Layout Builder Test Plugin');
$page->pressButton('Add section');
$page->clickLink('Add block');
$page->clickLink('Test Attributes');
$page->pressButton('Add block');
$page->pressButton('Save layout');
$this->drupalGet('node/1');
$assert_session->elementExists('css', '.attribute-test-class');
$assert_session->elementExists('css', '[custom-attribute=test]');
$assert_session->elementExists('css', 'div[data-contextual-id*="layout_builder_test"]');
}
/**
* Tests preview-aware layout & block plugins.
*/
public function testPreviewAwarePlugins() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
$page->clickLink('Manage layout');
$page->clickLink('Add section');
$page->clickLink('Layout Builder Test Plugin');
$page->pressButton('Add section');
$page->clickLink('Add block');
$page->clickLink('Preview-aware block');
$page->pressButton('Add block');
$assert_session->elementExists('css', '.go-birds-preview');
$assert_session->pageTextContains('The block template is being previewed.');
$assert_session->pageTextContains('This block is being rendered in preview mode.');
$page->pressButton('Save layout');
$this->drupalGet('node/1');
$assert_session->elementNotExists('css', '.go-birds-preview');
$assert_session->pageTextNotContains('The block template is being previewed.');
$assert_session->pageTextContains('This block is being rendered normally.');
}
/**
* {@inheritdoc}
*/
public function testLayoutBuilderChooseBlocksAlter() {
// See layout_builder_test_plugin_filter_block__layout_builder_alter().
$assert_session = $this->assertSession();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]));
// From the manage display page, go to manage the layout.
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
$assert_session->linkExists('Manage layout');
$this->clickLink('Manage layout');
// 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');
// Go back to Manage layout.
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this->clickLink('Manage layout');
// 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');
}
/**
* Tests that deleting a View block used in Layout Builder works.
*/
public function testDeletedView() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
// Enable overrides.
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['layout[allow_custom]' => TRUE], 'Save');
$this->drupalGet('node/1');
$assert_session->linkExists('Layout');
$this->clickLink('Layout');
$this->clickLink('Add block');
$this->clickLink('Test Block View');
$page->pressButton('Add block');
$assert_session->pageTextContains('Test Block View');
$assert_session->elementExists('css', '.block-views-blocktest-block-view-block-1');
$page->pressButton('Save');
$assert_session->pageTextContains('Test Block View');
$assert_session->elementExists('css', '.block-views-blocktest-block-view-block-1');
View::load('test_block_view')->delete();
$this->drupalGet('node/1');
// Node can be loaded after deleting the View.
$assert_session->pageTextContains(Node::load(1)->getTitle());
$assert_session->pageTextNotContains('Test Block View');
}
/**
* Tests the usage of placeholders for empty blocks.
*
* @see \Drupal\Core\Render\PreviewFallbackInterface::getPreviewFallbackString()
* @see \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender()
*/
public function testBlockPlaceholder() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
// Customize the default view mode.
$this->drupalGet("$field_ui_prefix/display/default/layout");
// Add a block whose content is controlled by state and is empty by default.
$this->clickLink('Add block');
$this->clickLink('Test block caching');
$page->fillField('settings[label]', 'The block label');
$page->pressButton('Add block');
$block_content = 'I am content';
$placeholder_content = 'Placeholder for the "The block label" block';
// The block placeholder is displayed and there is no content.
$assert_session->pageTextContains($placeholder_content);
$assert_session->pageTextNotContains($block_content);
// Set block content and reload the page.
\Drupal::state()->set('block_test.content', $block_content);
$this->getSession()->reload();
// The block placeholder is no longer displayed and the content is visible.
$assert_session->pageTextNotContains($placeholder_content);
$assert_session->pageTextContains($block_content);
}
/**
* Tests the ability to use a specified block label for field blocks.
*/
public function testFieldBlockLabel() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this->drupalGet("$field_ui_prefix/display/default");
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
// Customize the default view mode.
$this->drupalGet("$field_ui_prefix/display/default/layout");
// Add a body block whose label will be overridden.
$this->clickLink('Add block');
$this->clickLink('Body');
// Enable the Label Display and set the Label to a modified field
// block label.
$modified_field_block_label = 'Modified Field Block Label';
$page->checkField('settings[label_display]');
$page->fillField('settings[label]', $modified_field_block_label);
// Save the block and layout.
$page->pressButton('Add block');
$page->pressButton('Save layout');
// Revisit the default layout view mode page.
$this->drupalGet("$field_ui_prefix/display/default/layout");
// The modified field block label is displayed.
$assert_session->pageTextContains($modified_field_block_label);
}
/**
* Tests the Block UI when Layout Builder is installed.
*/
public function testBlockUiListing() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'administer blocks',
]));
$this->drupalGet('admin/structure/block');
$page->clickLink('Place block');
// Ensure that blocks expected to appear are available.
$assert_session->pageTextContains('Test HTML block');
$assert_session->pageTextContains('Block test');
// Ensure that blocks not expected to appear are not available.
$assert_session->pageTextNotContains('Body');
$assert_session->pageTextNotContains('Content fields');
}
}
<?php
namespace Drupal\Tests\layout_builder\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
/**
* Tests the Layout Builder UI.
*/
class LayoutBuilderTestBase extends BrowserTestBase {
use FieldUiTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'field_ui',
'views',
'layout_builder',
'layout_builder_views_test',
'layout_test',
'block',
'block_test',
'contextual',
'node',
'layout_builder_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'starterkit_theme';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->drupalPlaceBlock('local_tasks_block');
// Create two nodes.
$this->createContentType([
'type' => 'bundle_with_section_field',
'name' => 'Bundle with section field',
]);
$this->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The first node title',
'body' => [
[
'value' => 'The first node body',
],
],
]);
$this->createNode([
'type' => 'bundle_with_section_field',
'title' => 'The second node title',
'body' => [
[
'value' => 'The second node body',
],
],
]);
}
}
<?php
namespace Drupal\Tests\layout_builder\Functional;
/**
* Tests the Layout Builder UI with view modes.
*
* @group layout_builder
* @group #slow
*/
class LayoutBuilderViewModeTest extends LayoutBuilderTestBase {
/**
* Tests that a non-default view mode works as expected.
*/
public function testNonDefaultViewMode() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
// Allow overrides for the layout.
$this->drupalGet("$field_ui_prefix/display/default");
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$page->checkField('layout[allow_custom]');
$page->pressButton('Save');
$this->clickLink('Manage layout');
// Confirm the body field only is shown once.
$assert_session->elementsCount('css', '.field--name-body', 1);
$page->pressButton('Discard changes');
$page->pressButton('Confirm');
$this->clickLink('Teaser');
// Enabling Layout Builder for the default mode does not affect the teaser.
$assert_session->addressEquals("$field_ui_prefix/display/teaser");
$assert_session->elementNotExists('css', '#layout-builder__layout');
$assert_session->checkboxNotChecked('layout[enabled]');
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$assert_session->linkExists('Manage layout');
$page->clickLink('Manage layout');
// Confirm the body field only is shown once.
$assert_session->elementsCount('css', '.field--name-body', 1);
// Enable a disabled view mode.
$page->pressButton('Discard changes');
$page->pressButton('Confirm');
$assert_session->addressEquals("$field_ui_prefix/display/teaser");
$page->clickLink('Default');
$assert_session->addressEquals("$field_ui_prefix/display");
$assert_session->linkNotExists('Full content');
$page->checkField('display_modes_custom[full]');
$page->pressButton('Save');
$assert_session->linkExists('Full content');
$page->clickLink('Full content');
$assert_session->addressEquals("$field_ui_prefix/display/full");
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$assert_session->linkExists('Manage layout');
$page->clickLink('Manage layout');
// Confirm the body field only is shown once.
$assert_session->elementsCount('css', '.field--name-body', 1);
}
/**
* Tests the interaction between full and default view modes.
*
* @see \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::getDefaultSectionStorage()
*/
public function testLayoutBuilderUiFullViewMode() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
// For the purposes of this test, turn the full view mode on and off to
// prevent copying from the customized default view mode.
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['display_modes_custom[full]' => TRUE], 'Save');
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['display_modes_custom[full]' => FALSE], 'Save');
// Allow overrides for the layout.
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['layout[allow_custom]' => TRUE], 'Save');
// Customize the default view mode.
$this->drupalGet("$field_ui_prefix/display/default/layout");
$this->clickLink('Add block');
$this->clickLink('Powered by Drupal');
$page->fillField('settings[label]', 'This is the default view mode');
$page->checkField('settings[label_display]');
$page->pressButton('Add block');
$assert_session->pageTextContains('This is the default view mode');
$page->pressButton('Save layout');
// The default view mode is used for both the node display and layout UI.
$this->drupalGet('node/1');
$assert_session->pageTextContains('This is the default view mode');
$assert_session->pageTextNotContains('This is the full view mode');
$this->drupalGet('node/1/layout');
$assert_session->pageTextContains('This is the default view mode');
$assert_session->pageTextNotContains('This is the full view mode');
$page->pressButton('Discard changes');
$page->pressButton('Confirm');
// Enable the full view mode and customize it.
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['display_modes_custom[full]' => TRUE], 'Save');
$this->drupalGet("{$field_ui_prefix}/display/full");
$this->submitForm(['layout[enabled]' => TRUE], 'Save');
$this->drupalGet("{$field_ui_prefix}/display/full");
$this->submitForm(['layout[allow_custom]' => TRUE], 'Save');
$this->drupalGet("$field_ui_prefix/display/full/layout");
$this->clickLink('Add block');
$this->clickLink('Powered by Drupal');
$page->fillField('settings[label]', 'This is the full view mode');
$page->checkField('settings[label_display]');
$page->pressButton('Add block');
$assert_session->pageTextContains('This is the full view mode');
$page->pressButton('Save layout');
// The full view mode is now used for both the node display and layout UI.
$this->drupalGet('node/1');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
$this->drupalGet('node/1/layout');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
$page->pressButton('Discard changes');
$page->pressButton('Confirm');
// Disable the full view mode, the default should be used again.
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['display_modes_custom[full]' => FALSE], 'Save');
$this->drupalGet('node/1');
$assert_session->pageTextContains('This is the default view mode');
$assert_session->pageTextNotContains('This is the full view mode');
$this->drupalGet('node/1/layout');
$assert_session->pageTextContains('This is the default view mode');
$assert_session->pageTextNotContains('This is the full view mode');
$page->pressButton('Discard changes');
$page->pressButton('Confirm');
// Re-enabling the full view mode restores the layout changes.
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['display_modes_custom[full]' => TRUE], 'Save');
$this->drupalGet('node/1');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
$this->drupalGet('node/1/layout');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
// Create an override of the full view mode.
$this->clickLink('Add block');
$this->clickLink('Powered by Drupal');
$page->fillField('settings[label]', 'This is an override of the full view mode');
$page->checkField('settings[label_display]');
$page->pressButton('Add block');
$assert_session->pageTextContains('This is an override of the full view mode');
$page->pressButton('Save layout');
$this->drupalGet('node/1');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextContains('This is an override of the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
$this->drupalGet('node/1/layout');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextContains('This is an override of the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
$page->pressButton('Discard changes');
$page->pressButton('Confirm');
// The override does not affect the full view mode.
$this->drupalGet("$field_ui_prefix/display/full/layout");
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextNotContains('This is an override of the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
// Reverting the override restores back to the full view mode.
$this->drupalGet('node/1/layout');
$page->pressButton('Revert to default');
$page->pressButton('Revert');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextNotContains('This is an override of the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
$this->drupalGet('node/1/layout');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextNotContains('This is an override of the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
// Recreate an override of the full view mode.
$this->clickLink('Add block');
$this->clickLink('Powered by Drupal');
$page->fillField('settings[label]', 'This is an override of the full view mode');
$page->checkField('settings[label_display]');
$page->pressButton('Add block');
$assert_session->pageTextContains('This is an override of the full view mode');
$page->pressButton('Save layout');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextContains('This is an override of the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
$this->drupalGet('node/1/layout');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextContains('This is an override of the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
$page->pressButton('Discard changes');
$page->pressButton('Confirm');
// Disable the full view mode.
$this->drupalGet("{$field_ui_prefix}/display/default");
$this->submitForm(['display_modes_custom[full]' => FALSE], 'Save');
// The override of the full view mode is still available.
$this->drupalGet('node/1');
$assert_session->pageTextContains('This is the full view mode');
$assert_session->pageTextContains('This is an override of the full view mode');
$assert_session->pageTextNotContains('This is the default view mode');
// Reverting the override restores back to the default view mode.
$this->drupalGet('node/1/layout');
$page->pressButton('Revert to default');
$page->pressButton('Revert');
$assert_session->pageTextContains('This is the default view mode');
$assert_session->pageTextNotContains('This is the full view mode');
$this->drupalGet('node/1/layout');
$assert_session->pageTextContains('This is the default view mode');
$assert_session->pageTextNotContains('This is the full view mode');
$page->pressButton('Discard changes');
$page->pressButton('Confirm');
}
/**
* Ensures that one bundle doesn't interfere with another bundle.
*/
public function testFullViewModeMultipleBundles() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
// Create one bundle with the full view mode enabled.
$this->createContentType(['type' => 'full_bundle']);
$this->drupalGet('admin/structure/types/manage/full_bundle/display/default');
$page->checkField('display_modes_custom[full]');
$page->pressButton('Save');
// Create another bundle without the full view mode enabled.
$this->createContentType(['type' => 'default_bundle']);
$this->drupalGet('admin/structure/types/manage/default_bundle/display/default');
// Enable Layout Builder for defaults and overrides.
$page->checkField('layout[enabled]');
$page->pressButton('Save');
$page->checkField('layout[allow_custom]');
$page->pressButton('Save');
$assert_session->checkboxChecked('layout[allow_custom]');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment