function NavigationTopBarTest::testTopBarVisibility

Same name and namespace in other branches
  1. 11.x core/modules/navigation/tests/src/Functional/NavigationTopBarTest.php \Drupal\Tests\navigation\Functional\NavigationTopBarTest::testTopBarVisibility()

Tests the top bar visibility.

File

core/modules/navigation/tests/src/Functional/NavigationTopBarTest.php, line 78

Class

NavigationTopBarTest
Tests the top bar functionality.

Namespace

Drupal\Tests\navigation\Functional

Code

public function testTopBarVisibility() : void {
  $this->drupalGet($this->node
    ->toUrl());
  // Top Bar is not visible if the feature flag module is disabled.
  $this->assertSession()
    ->elementNotExists('xpath', "//div[contains(@class, 'top-bar__content')]/button/span");
  $this->assertSession()
    ->elementExists('xpath', '//div[@id="block-tabs"]');
  \Drupal::service('module_installer')->install([
    'navigation_top_bar',
  ]);
  // Top Bar is visible once the feature flag module is enabled.
  $this->drupalGet($this->node
    ->toUrl());
  $this->assertSession()
    ->elementExists('xpath', "//div[contains(@class, 'top-bar__content')]/button/span");
  $this->assertSession()
    ->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/button/span", 'More actions');
  $this->assertSession()
    ->elementNotExists('xpath', '//div[@id="block-tabs"]');
  // Find all the dropdown links and check if the top bar is there as well.
  $toolbar_links = $this->mink
    ->getSession()
    ->getPage()
    ->find('xpath', '//*[@id="admin-local-tasks"]/ul');
  foreach ($toolbar_links->findAll('css', 'li') as $toolbar_link) {
    $this->clickLink($toolbar_link->getText());
    $this->assertSession()
      ->elementExists('xpath', "//div[contains(@class, 'top-bar__content')]/button/span");
    $this->assertSession()
      ->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/button/span", 'More actions');
    $this->assertSession()
      ->elementNotExists('xpath', '//div[@id="block-tabs"]');
  }
}

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