function NavigationBlockUiTest::testNavigationBlockAdminUiPage

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

Tests navigation block admin page exists and functions correctly.

File

core/modules/navigation/tests/src/FunctionalJavascript/NavigationBlockUiTest.php, line 76

Class

NavigationBlockUiTest
Tests that the navigation block UI exists and stores data correctly.

Namespace

Drupal\Tests\navigation\FunctionalJavascript

Code

public function testNavigationBlockAdminUiPage() : void {
  $layout_url = '/admin/config/user-interface/navigation-block';
  $this->drupalGet($layout_url);
  $this->assertSession()
    ->pageTextContains('Access denied');
  // Add at least one shortcut.
  $shortcut_set = \Drupal::entityTypeManager()->getStorage('shortcut_set')
    ->getDisplayedToUser($this->adminUser);
  $shortcut = \Drupal::entityTypeManager()->getStorage('shortcut')
    ->create([
    'title' => 'Run cron',
    'shortcut_set' => $shortcut_set->id(),
    'link' => [
      'uri' => 'internal:/admin/config/system/cron',
    ],
  ]);
  $shortcut->save();
  $this->drupalLogin($this->adminUser);
  $this->drupalGet($layout_url);
  $page = $this->getSession()
    ->getPage();
  // Add section should not be present
  $this->assertSession()
    ->linkNotExists('Add section');
  // Configure section should not be present.
  $this->assertSession()
    ->linkNotExists('Configure Section 1');
  // Remove section should not be present.
  $this->assertSession()
    ->linkNotExists('Remove Section 1');
  // Remove the shortcut block.
  $this->assertSession()
    ->pageTextContains('Shortcuts');
  $this->clickContextualLink('form .block-navigation-shortcuts', 'Remove block');
  $this->assertOffCanvasFormAfterWait('layout_builder_remove_block');
  $this->assertSession()
    ->pageTextContains('Are you sure you want to remove the Shortcuts block?');
  $this->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $page->pressButton('Remove');
  $this->assertSession()
    ->assertWaitOnAjaxRequest();
  $this->assertSession()
    ->assertNoElementAfterWait('css', '#drupal-off-canvas');
  $this->assertSession()
    ->elementNotExists('css', 'form .block-navigation-shortcuts');
  // Add a new block.
  $this->getSession()
    ->getPage()
    ->uncheckField('toggle_content_preview');
  $this->openAddBlockForm('Navigation Shortcuts');
  $page->fillField('settings[label]', 'New Shortcuts');
  $page->checkField('settings[label_display]');
  // Save the new block, and ensure it is displayed on the page.
  $page->pressButton('Add block');
  $this->assertSession()
    ->assertWaitOnAjaxRequest();
  $this->assertSession()
    ->assertNoElementAfterWait('css', '#drupal-off-canvas');
  $this->assertSession()
    ->addressEquals($layout_url);
  $this->assertSession()
    ->pageTextContains('Shortcuts');
  $this->assertSession()
    ->pageTextContains('New Shortcuts');
  // Until the layout is saved, the new block is not visible on the node page.
  $front = Url::fromRoute('<front>');
  $this->drupalGet($front);
  $this->assertSession()
    ->pageTextNotContains('New Shortcuts');
  // When returning to the layout edit mode, the new block is visible.
  $this->drupalGet($layout_url);
  $this->assertSession()
    ->pageTextContains('New Shortcuts');
  // Save the layout, and the new block is visible.
  $page->pressButton('Save');
  $this->drupalGet($front);
  $this->assertSession()
    ->pageTextContains('New Shortcuts');
  // Reconfigure a block and ensure that the layout content is updated.
  $this->drupalGet($layout_url);
  $this->clickContextualLink('form .block-navigation-shortcuts', 'Configure');
  $this->assertOffCanvasFormAfterWait('layout_builder_update_block');
  $page->fillField('settings[label]', 'Newer Shortcuts');
  $page->pressButton('Update');
  $this->assertSession()
    ->assertWaitOnAjaxRequest();
  $this->assertSession()
    ->assertNoElementAfterWait('css', '#drupal-off-canvas');
  $this->assertSession()
    ->addressEquals($layout_url);
  $this->assertSession()
    ->pageTextContains('Newer Shortcuts');
  $this->assertSession()
    ->elementTextNotContains('css', 'form', 'New Shortcuts');
}

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