function DisplayPathTest::testMenuOptions

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

Tests the menu and tab option form.

File

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

Class

DisplayPathTest
Tests the UI of generic display path plugin.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testMenuOptions() {
    $this->drupalGet('admin/structure/views/view/test_view');
    // Add a new page display.
    $this->submitForm([], 'Add Page');
    // Add an invalid path (only fragment).
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
    $this->submitForm([
        'path' => '#foo',
    ], 'Apply');
    $this->assertSession()
        ->pageTextContains('Path is empty');
    // Add an invalid path with a query.
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
    $this->submitForm([
        'path' => 'foo?bar',
    ], 'Apply');
    $this->assertSession()
        ->pageTextContains('No query allowed.');
    // Add an invalid path with just a query.
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
    $this->submitForm([
        'path' => '?bar',
    ], 'Apply');
    $this->assertSession()
        ->pageTextContains('Path is empty');
    // Provide a random, valid path string.
    $random_string = $this->randomMachineName();
    // Save a path.
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
    $this->submitForm([
        'path' => $random_string,
    ], 'Apply');
    $this->drupalGet('admin/structure/views/view/test_view');
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/menu');
    $this->submitForm([
        'menu[type]' => 'default tab',
        'menu[title]' => 'Test tab title',
    ], 'Apply');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->addressEquals('admin/structure/views/nojs/display/test_view/page_1/tab_options');
    $this->submitForm([
        'tab_options[type]' => 'tab',
        'tab_options[title]' => $this->randomString(),
    ], 'Apply');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->addressEquals('admin/structure/views/view/test_view/edit/page_1');
    $this->drupalGet('admin/structure/views/view/test_view');
    $this->assertSession()
        ->linkExists('Tab: Test tab title');
    // If it's a default tab, it should also have an additional settings link.
    $this->assertSession()
        ->linkByHrefExists('admin/structure/views/nojs/display/test_view/page_1/tab_options');
    // Ensure that you can select a parent in case the parent does not exist.
    $this->drupalGet('admin/structure/views/nojs/display/test_page_display_menu/page_5/menu');
    $this->assertSession()
        ->statusCodeEquals(200);
    $menu_options = $this->assertSession()
        ->selectExists('edit-menu-parent')
        ->findAll('css', 'option');
    $menu_options = array_map(function ($element) {
        return $element->getText();
    }, $menu_options);
    $this->assertEquals([
        '<User account menu>',
        '-- My account',
        '-- Log out',
        '<Administration>',
        '<Footer>',
        '<Main navigation>',
        '<Tools>',
        '-- Compose tips (disabled)',
        '-- Test menu link',
    ], $menu_options);
    // The cache contexts associated with the (in)accessible menu links are
    // bubbled.
    $this->assertCacheContext('user.permissions');
}

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