You are here

public function DisplayPathTest::testMenuOptions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views_ui/src/Tests/DisplayPathTest.php \Drupal\views_ui\Tests\DisplayPathTest::testMenuOptions()

Tests the menu and tab option form.

File

core/modules/views_ui/src/Tests/DisplayPathTest.php, line 123
Contains \Drupal\views_ui\Tests\DisplayPathTest.

Class

DisplayPathTest
Tests the UI of generic display path plugin.

Namespace

Drupal\views_ui\Tests

Code

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

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

  // Add an invalid path (only fragment).
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/test_view/page_1/path', array(
    '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', array(
    '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', array(
    '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', array(
    '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', array(
    'menu[type]' => 'default tab',
    'menu[title]' => 'Test tab title',
  ), t('Apply'));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl('admin/structure/views/nojs/display/test_view/page_1/tab_options');
  $this
    ->drupalPostForm(NULL, array(
    'tab_options[type]' => 'tab',
    'tab_options[title]' => $this
      ->randomString(),
  ), t('Apply'));
  $this
    ->assertResponse(200);
  $this
    ->assertUrl('admin/structure/views/view/test_view/edit/page_1');
  $this
    ->drupalGet('admin/structure/views/view/test_view');
  $this
    ->assertLink(t('Tab: @title', array(
    '@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
    ->assertResponse(200);
  $menu_parent = $this
    ->xpath('//select[@id="edit-menu-parent"]');
  $menu_options = (array) $menu_parent[0]->option;
  unset($menu_options['@attributes']);
  $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');
}