You are here

public function TrustedHostsTest::testShortcut in Drupal 8

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

Class

TrustedHostsTest
Tests output on the status overview page.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testShortcut() {
  $this->container
    ->get('module_installer')
    ->install([
    'block',
    'shortcut',
  ]);
  $this
    ->rebuildContainer();
  $this->container
    ->get('router.builder')
    ->rebuild();

  /** @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());
}