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. 10 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 55

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->assertTitle('List links | Drupal');
    // Test for the table.
    $element = $this->xpath('//div[@class="layout-content"]//table');
    $this->assertNotEmpty($element, 'Shortcut entity list table found.');
    // Test the table header.
    $elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th');
    $this->assertCount(3, $elements, 'Correct number of table header cells found.');
    // Test the contents of each th cell.
    $expected_items = [
        t('Name'),
        t('Weight'),
        t('Operations'),
    ];
    foreach ($elements as $key => $element) {
        $this->assertEqual($element->getText(), $expected_items[$key]);
    }
    // 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->assertFieldByName('shortcuts[links][' . $shortcut->id() . '][weight]');
        // Change the weight of the shortcut.
        $edit['shortcuts[links][' . $shortcut->id() . '][weight]'] = $weight;
        $weight--;
    }
    $this->drupalPostForm(NULL, $edit, t('Save'));
    $this->assertRaw(t('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->assertIdentical(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.