class TrustedHostsTest

Same name in this branch
  1. main core/modules/system/tests/src/Functional/System/TrustedHostsTest.php \Drupal\Tests\system\Functional\System\TrustedHostsTest
Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Functional/System/TrustedHostsTest.php \Drupal\Tests\system\Functional\System\TrustedHostsTest
  2. 10 core/modules/system/tests/src/Functional/System/TrustedHostsTest.php \Drupal\Tests\system\Functional\System\TrustedHostsTest
  3. 9 core/modules/system/tests/src/Functional/System/TrustedHostsTest.php \Drupal\Tests\system\Functional\System\TrustedHostsTest
  4. 8.9.x core/modules/system/tests/src/Functional/System/TrustedHostsTest.php \Drupal\Tests\system\Functional\System\TrustedHostsTest
  5. 11.x core/modules/shortcut/tests/src/Functional/TrustedHostsTest.php \Drupal\Tests\shortcut\Functional\TrustedHostsTest

Tests output on the status overview page.

Attributes

#[Group('shortcut')] #[RunTestsInSeparateProcesses]

Hierarchy

  • class \Drupal\Tests\shortcut\Functional\TrustedHostsTest extends \Drupal\Tests\BrowserTestBase

Expanded class hierarchy of TrustedHostsTest

File

core/modules/shortcut/tests/src/Functional/TrustedHostsTest.php, line 14

Namespace

Drupal\Tests\shortcut\Functional
View source
class TrustedHostsTest extends BrowserTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'block',
    'shortcut',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $admin_user = $this->drupalCreateUser([
      'administer site configuration',
    ]);
    $this->drupalLogin($admin_user);
  }
  
  /**
   * Tests that shortcut module works together with host verification.
   */
  public function testShortcut() : void {
    /** @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' => 'Test Shortcut Label',
      '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.