You are here

public function AdminToolbarSearchTest::testSearchFunctionality in Admin Toolbar 8

Tests search functionality.

File

tests/src/FunctionalJavascript/AdminToolbarSearchTest.php, line 58

Class

AdminToolbarSearchTest
Test the functionality of admin toolbar search.

Namespace

Drupal\Tests\admin_toolbar\FunctionalJavascript

Code

public function testSearchFunctionality() {
  $search_tab = '#toolbar-item-administration-search';
  $search_tray = '#toolbar-item-administration-search-tray';
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->assertSession()
    ->responseContains('admin.toolbar_search.css');
  $this
    ->assertSession()
    ->responseContains('admin_toolbar_search.js');
  $this
    ->assertSession()
    ->waitForElementVisible('css', $search_tab)
    ->click();
  $this
    ->assertSession()
    ->waitForElementVisible('css', $search_tray);
  $this
    ->assertSuggestionContains('basic', 'admin/config/system/site-information');

  // Rebuild menu items.
  drupal_flush_all_caches();
  $this
    ->drupalGet('admin/structure/types/manage/article/fields');
  $this
    ->assertSession()
    ->waitForElementVisible('css', $search_tray);
  $this
    ->assertSuggestionContains('article manage fields', '/admin/structure/types/manage/article/fields');
  $suggestions = $this
    ->assertSession()
    ->waitForElementVisible('css', 'ul.ui-autocomplete');

  // Assert there is only one suggestion with a link to
  // /admin/structure/types/manage/article/fields.
  $count = count($suggestions
    ->findAll('xpath', '//span[contains(text(), "/admin/structure/types/manage/article/fields")]'));
  $this
    ->assertEquals(1, $count);
}