You are here

public function TrustedHostsTest::testShortcut in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/System/TrustedHostsTest.php \Drupal\system\Tests\System\TrustedHostsTest::testShortcut()

Tests that shortcut module works together with host verification.

File

core/modules/system/src/Tests/System/TrustedHostsTest.php, line 85
Contains \Drupal\system\Tests\System\TrustedHostsTest.

Class

TrustedHostsTest
Tests output on the status overview page.

Namespace

Drupal\system\Tests\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\EntityManagerInterface $entity_manager */
  $entity_manager = $this->container
    ->get('entity.manager');
  $shortcut_storage = $entity_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_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
    ->assertLink($shortcut
    ->label());
}