function TrustedHostsTest::testShortcut

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/TrustedHostsTest.php \Drupal\Tests\system\Functional\System\TrustedHostsTest::testShortcut()
  2. 8.9.x core/modules/system/tests/src/Functional/System/TrustedHostsTest.php \Drupal\Tests\system\Functional\System\TrustedHostsTest::testShortcut()
  3. 11.x core/modules/system/tests/src/Functional/System/TrustedHostsTest.php \Drupal\Tests\system\Functional\System\TrustedHostsTest::testShortcut()

Tests that shortcut module works together with host verification.

File

core/modules/system/tests/src/Functional/System/TrustedHostsTest.php, line 88

Class

TrustedHostsTest
Tests output on the status overview page.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testShortcut() : void {
  $this->container
    ->get('module_installer')
    ->install([
    'block',
    'shortcut',
  ]);
  $this->rebuildContainer();
  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  $shortcut_storage = $entity_type_manager->getStorage('shortcut');
  $shortcut = $shortcut_storage->create([
    'title' => $this->randomString(),
    'link' => 'internal:/admin/reports/status',
    'shortcut_set' => 'default',
  ]);
  $shortcut_storage->save($shortcut);
  // Grant the current user access to see the shortcuts.
  $role_storage = $entity_type_manager->getStorage('user_role');
  $roles = $this->loggedInUser
    ->getRoles(TRUE);
  /** @var \Drupal\user\RoleInterface $role */
  $role = $role_storage->load(reset($roles));
  $role->grantPermission('access shortcuts')
    ->save();
  $this->drupalPlaceBlock('shortcuts');
  $this->drupalGet('');
  $this->assertSession()
    ->linkExists($shortcut->label());
}

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