You are here

public function ShortcutSetsTest::testShortcutSetEdit in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php \Drupal\Tests\shortcut\Functional\ShortcutSetsTest::testShortcutSetEdit()
  2. 9 core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php \Drupal\Tests\shortcut\Functional\ShortcutSetsTest::testShortcutSetEdit()

Tests editing a shortcut set.

File

core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php, line 57

Class

ShortcutSetsTest
Create, view, edit, delete, and change shortcut sets.

Namespace

Drupal\Tests\shortcut\Functional

Code

public function testShortcutSetEdit() {
  $set = $this->set;
  $shortcuts = $set
    ->getShortcuts();

  // Visit the shortcut set edit admin ui.
  $this
    ->drupalGet('admin/config/user-interface/shortcut/manage/' . $set
    ->id() . '/customize');

  // Test for the page title.
  $this
    ->assertSession()
    ->titleEquals('List links | Drupal');

  // Test for the table.
  $this
    ->assertSession()
    ->elementExists('xpath', '//div[@class="layout-content"]//table');

  // Test the table header.
  $this
    ->assertSession()
    ->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 3);

  // Test the contents of each th cell.
  $this
    ->assertSession()
    ->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[1]', 'Name');
  $this
    ->assertSession()
    ->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[2]', 'Weight');
  $this
    ->assertSession()
    ->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[3]', 'Operations');

  // Look for test shortcuts in the table.
  $weight = count($shortcuts);
  $edit = [];
  foreach ($shortcuts as $shortcut) {
    $title = $shortcut
      ->getTitle();

    // Confirm that a link to the shortcut is found within the table.
    $this
      ->assertSession()
      ->linkExists($title);

    // Look for a test shortcut weight select form element.
    $this
      ->assertSession()
      ->fieldExists('shortcuts[links][' . $shortcut
      ->id() . '][weight]');

    // Change the weight of the shortcut.
    $edit['shortcuts[links][' . $shortcut
      ->id() . '][weight]'] = $weight;
    $weight--;
  }
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains("The shortcut set has been updated.");
  \Drupal::entityTypeManager()
    ->getStorage('shortcut')
    ->resetCache();

  // Check to ensure that the shortcut weights have changed and that
  // ShortcutSet::.getShortcuts() returns shortcuts in the new order.
  $this
    ->assertSame(array_reverse(array_keys($shortcuts)), array_keys($set
    ->getShortcuts()));
}