public function LayoutBuilderTest::testPluginDependencies in Drupal 8
Same name and namespace in other branches
- 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest::testPluginDependencies()
Tests that component's dependencies are respected during removal.
File
- core/
modules/ layout_builder/ tests/ src/ Functional/ LayoutBuilderTest.php, line 544
Class
- LayoutBuilderTest
- Tests the Layout Builder UI.
Namespace
Drupal\Tests\layout_builder\FunctionalCode
public function testPluginDependencies() {
$assert_session = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$this->container
->get('module_installer')
->install([
'menu_ui',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer menu',
]));
// Create a new menu.
$this
->drupalGet('admin/structure/menu/add');
$page
->fillField('label', 'My Menu');
$page
->fillField('id', 'mymenu');
$page
->pressButton('Save');
$this
->drupalGet('admin/structure/menu/add');
$page
->fillField('label', 'My Menu');
$page
->fillField('id', 'myothermenu');
$page
->pressButton('Save');
$page
->clickLink('Add link');
$page
->fillField('title[0][value]', 'My link');
$page
->fillField('link[0][uri]', '/');
$page
->pressButton('Save');
$this
->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display', [
'layout[enabled]' => TRUE,
], 'Save');
$assert_session
->linkExists('Manage layout');
$this
->clickLink('Manage layout');
$assert_session
->linkExists('Add section');
$this
->clickLink('Add section');
$assert_session
->linkExists('Layout plugin (with dependencies)');
$this
->clickLink('Layout plugin (with dependencies)');
$page
->pressButton('Add section');
$assert_session
->elementExists('css', '.layout--layout-test-dependencies-plugin');
$assert_session
->elementExists('css', '.field--name-body');
$page
->pressButton('Save layout');
$this
->drupalPostForm('admin/structure/menu/manage/myothermenu/delete', [], 'Delete');
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
$assert_session
->elementNotExists('css', '.layout--layout-test-dependencies-plugin');
$assert_session
->elementExists('css', '.field--name-body');
// Add a menu block.
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->linkExists('My Menu');
$this
->clickLink('My Menu');
$page
->pressButton('Add block');
// Add another block alongside the menu.
$assert_session
->linkExists('Add block');
$this
->clickLink('Add block');
$assert_session
->linkExists('Powered by Drupal');
$this
->clickLink('Powered by Drupal');
$page
->pressButton('Add block');
// Assert that the blocks are visible, and save the layout.
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextContains('My Menu');
$assert_session
->elementExists('css', '.block.menu--mymenu');
$page
->pressButton('Save layout');
// Delete the menu.
$this
->drupalPostForm('admin/structure/menu/manage/mymenu/delete', [], 'Delete');
// Ensure that the menu block is gone, but that the other block remains.
$this
->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
$assert_session
->pageTextContains('Powered by Drupal');
$assert_session
->pageTextNotContains('My Menu');
$assert_session
->elementNotExists('css', '.block.menu--mymenu');
}