You are here

public function DisplayPathTest::testMenuOptions in Drupal 8

Same name and namespace in other branches
  1. 9 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()

Tests the menu and tab option form.

File

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

Class

DisplayPathTest
Tests the UI of generic display path plugin.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testMenuOptions() {
  $this->container
    ->get('module_installer')
    ->install([
    'menu_ui',
  ]);
  $this
    ->drupalGet('admin/structure/views/view/test_view');

  // Add a new page display.
  $this
    ->drupalPostForm(NULL, [], 'Add Page');

  // Add an invalid path (only fragment).
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', [
    'path' => '#foo',
  ], t('Apply'));
  $this
    ->assertText('Path is empty');

  // Add an invalid path with a query.
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', [
    'path' => 'foo?bar',
  ], t('Apply'));
  $this
    ->assertText('No query allowed.');

  // Add an invalid path with just a query.
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', [
    'path' => '?bar',
  ], t('Apply'));
  $this
    ->assertText('Path is empty');

  // Provide a random, valid path string.
  $random_string = $this
    ->randomMachineName();

  // Save a path.
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', [
    'path' => $random_string,
  ], t('Apply'));
  $this
    ->drupalGet('admin/structure/views/view/test_view');
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/menu', [
    'menu[type]' => 'default tab',
    'menu[title]' => 'Test tab title',
  ], t('Apply'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertUrl('admin/structure/views/nojs/display/test_view/page_1/tab_options');
  $this
    ->drupalPostForm(NULL, [
    'tab_options[type]' => 'tab',
    'tab_options[title]' => $this
      ->randomString(),
  ], t('Apply'));
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertUrl('admin/structure/views/view/test_view/edit/page_1');
  $this
    ->drupalGet('admin/structure/views/view/test_view');
  $this
    ->assertSession()
    ->linkExists(t('Tab: @title', [
    '@title' => 'Test tab title',
  ]));

  // If it's a default tab, it should also have an additional settings link.
  $this
    ->assertLinkByHref('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_parent = $this
    ->xpath('//select[@id="edit-menu-parent"]');
  $menu_options = (array) $menu_parent[0]
    ->findAll('css', 'option');
  unset($menu_options['@attributes']);

  // Convert array to make the next assertion possible.
  $menu_options = array_map(function ($element) {
    return $element
      ->getText();
  }, $menu_options);
  $this
    ->assertEqual([
    '<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');
}