function DisplayPathTest::testDefaultMenuTabRegression

Same name in other branches
  1. 8.9.x core/modules/views_ui/tests/src/Functional/DisplayPathTest.php \Drupal\Tests\views_ui\Functional\DisplayPathTest::testDefaultMenuTabRegression()
  2. 10 core/modules/views_ui/tests/src/Functional/DisplayPathTest.php \Drupal\Tests\views_ui\Functional\DisplayPathTest::testDefaultMenuTabRegression()
  3. 11.x core/modules/views_ui/tests/src/Functional/DisplayPathTest.php \Drupal\Tests\views_ui\Functional\DisplayPathTest::testDefaultMenuTabRegression()

Tests the regression in https://www.drupal.org/node/2532490.

File

core/modules/views_ui/tests/src/Functional/DisplayPathTest.php, line 204

Class

DisplayPathTest
Tests the UI of generic display path plugin.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testDefaultMenuTabRegression() {
    $this->container
        ->get('module_installer')
        ->install([
        'menu_link_content',
        'toolbar',
        'system',
    ]);
    $this->resetAll();
    $admin_user = $this->drupalCreateUser([
        'administer views',
        'administer blocks',
        'bypass node access',
        'access user profiles',
        'view all revisions',
        'administer permissions',
        'administer menu',
        'link to any page',
        'access toolbar',
    ]);
    $this->drupalLogin($admin_user);
    $edit = [
        'title[0][value]' => 'Menu title',
        'link[0][uri]' => '/admin/foo',
        'menu_parent' => 'admin:system.admin',
    ];
    $this->drupalGet('admin/structure/menu/manage/admin/add');
    $this->submitForm($edit, 'Save');
    $menu_items = \Drupal::entityTypeManager()->getStorage('menu_link_content')
        ->getQuery()
        ->accessCheck(FALSE)
        ->sort('id', 'DESC')
        ->pager(1)
        ->execute();
    $menu_item = end($menu_items);
    
    /** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link_content */
    $menu_link_content = MenuLinkContent::load($menu_item);
    $edit = [];
    $edit['label'] = $this->randomMachineName(16);
    $view_id = $edit['id'] = strtolower($this->randomMachineName(16));
    $edit['description'] = $this->randomMachineName(16);
    $edit['page[create]'] = TRUE;
    $edit['page[path]'] = 'admin/foo';
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($edit, 'Save and edit');
    $parameters = new MenuTreeParameters();
    $parameters->addCondition('id', $menu_link_content->getPluginId());
    $result = \Drupal::menuTree()->load('admin', $parameters);
    $plugin_definition = end($result)->link
        ->getPluginDefinition();
    $this->assertEquals('view.' . $view_id . '.page_1', $plugin_definition['route_name']);
    $this->clickLink('No menu');
    $this->submitForm([
        'menu[type]' => 'default tab',
        'menu[title]' => 'Menu title',
    ], 'Apply');
    $this->assertSession()
        ->pageTextContains('Default tab options');
    $this->submitForm([
        'tab_options[type]' => 'normal',
        'tab_options[title]' => 'Parent title',
    ], 'Apply');
    // Open the menu options again.
    $this->clickLink('Tab: Menu title');
    // Assert a menu can be selected as a parent.
    $this->assertSession()
        ->optionExists('menu[parent]', 'admin:');
    // Assert a parent menu item can be selected from within a menu.
    $this->assertSession()
        ->optionExists('menu[parent]', 'admin:system.admin');
    // Check that parent menu item can now be
    // added without the menu_ui module being enabled.
    $this->submitForm([
        'menu[type]' => 'normal',
        'menu[parent]' => 'admin:system.admin',
        'menu[title]' => 'Menu title',
    ], 'Apply');
    $this->submitForm([], 'Save');
    // Assert that saving the view will not cause an exception.
    $this->assertSession()
        ->statusCodeEquals(200);
}

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