TrustedHostsTest.php in Zircon Profile 8.0
File
core/modules/system/src/Tests/System/TrustedHostsTest.php
View source
<?php
namespace Drupal\system\Tests\System;
use Drupal\simpletest\WebTestBase;
class TrustedHostsTest extends WebTestBase {
protected function setUp() {
parent::setUp();
$admin_user = $this
->drupalCreateUser(array(
'administer site configuration',
));
$this
->drupalLogin($admin_user);
}
public function testStatusPageWithoutConfiguration() {
$this
->drupalGet('admin/reports/status');
$this
->assertResponse(200, 'The status page is reachable.');
$this
->assertRaw(t('Trusted Host Settings'));
$this
->assertRaw(t('The trusted_host_patterns setting is not configured in settings.php.'));
}
public function testStatusPageWithConfiguration() {
$settings['settings']['trusted_host_patterns'] = (object) array(
'value' => array(
'^' . preg_quote(\Drupal::request()
->getHost()) . '$',
),
'required' => TRUE,
);
$this
->writeSettings($settings);
$this
->drupalGet('admin/reports/status');
$this
->assertResponse(200, 'The status page is reachable.');
$this
->assertRaw(t('Trusted Host Settings'));
$this
->assertRaw(t('The trusted_host_patterns setting is set to allow'));
}
public function testFakeRequests() {
$this->container
->get('module_installer')
->install([
'trusted_hosts_test',
]);
$this->container
->get('router.builder')
->rebuild();
$host = $this->container
->get('request_stack')
->getCurrentRequest()
->getHost();
$settings['settings']['trusted_host_patterns'] = (object) array(
'value' => array(
'^' . preg_quote($host) . '$',
),
'required' => TRUE,
);
$this
->writeSettings($settings);
$this
->drupalGet('trusted-hosts-test/fake-request');
$this
->assertText('Host: ' . $host);
}
public function testShortcut() {
$this->container
->get('module_installer')
->install([
'block',
'shortcut',
]);
$this
->rebuildContainer();
$this->container
->get('router.builder')
->rebuild();
$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);
$role_storage = $entity_manager
->getStorage('user_role');
$roles = $this->loggedInUser
->getRoles(TRUE);
$role = $role_storage
->load(reset($roles));
$role
->grantPermission('access shortcuts')
->save();
$this
->drupalPlaceBlock('shortcuts');
$this
->drupalGet('');
$this
->assertLink($shortcut
->label());
}
}