function ShortcutSetsTest::testShortcutSetEdit

Same name in other branches
  1. 9 core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php \Drupal\Tests\shortcut\Functional\ShortcutSetsTest::testShortcutSetEdit()
  2. 8.9.x core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php \Drupal\Tests\shortcut\Functional\ShortcutSetsTest::testShortcutSetEdit()
  3. 11.x 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 58

Class

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

Namespace

Drupal\Tests\shortcut\Functional

Code

public function testShortcutSetEdit() : void {
    $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()));
}

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