class DrupalKernelTest in Zircon Profile 8
Same name in this branch
- 8 core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest
- 8 core/modules/system/src/Tests/DrupalKernel/DrupalKernelTest.php \Drupal\system\Tests\DrupalKernel\DrupalKernelTest
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest
@coversDefaultClass \Drupal\Core\DrupalKernel @group DrupalKernel
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest
Expanded class hierarchy of DrupalKernelTest
File
- core/
tests/ Drupal/ Tests/ Core/ DrupalKernel/ DrupalKernelTest.php, line 19 - Contains \Drupal\Tests\Core\DrupalKernel\DrupalKernelTest.
Namespace
Drupal\Tests\Core\DrupalKernelView source
class DrupalKernelTest extends UnitTestCase {
/**
* Tests hostname validation with settings.
*
* @covers ::setupTrustedHosts
* @dataProvider providerTestTrustedHosts
*/
public function testTrustedHosts($host, $server_name, $message, $expected = FALSE) {
$request = new Request();
$trusted_host_patterns = [
'^example\\.com$',
'^.+\\.example\\.com$',
'^example\\.org',
'^.+\\.example\\.org',
];
if (!empty($host)) {
$request->headers
->set('HOST', $host);
}
$request->server
->set('SERVER_NAME', $server_name);
$method = new \ReflectionMethod('Drupal\\Core\\DrupalKernel', 'setupTrustedHosts');
$method
->setAccessible(TRUE);
$valid_host = $method
->invoke(null, $request, $trusted_host_patterns);
$this
->assertSame($expected, $valid_host, $message);
// Reset the trusted hosts because it is statically stored on the request.
$method
->invoke(null, $request, []);
// Reset the request factory because it is statically stored on the request.
Request::setFactory(NULL);
}
/**
* Provides test data for testTrustedHosts().
*/
public function providerTestTrustedHosts() {
$data = [];
// Tests canonical URL.
$data[] = [
'www.example.com',
'www.example.com',
'canonical URL is trusted',
TRUE,
];
// Tests missing hostname for HTTP/1.0 compatibility where the Host
// header is optional.
$data[] = [
NULL,
'www.example.com',
'empty Host is valid',
TRUE,
];
// Tests the additional patterns from the settings.
$data[] = [
'example.com',
'www.example.com',
'host from settings is trusted',
TRUE,
];
$data[] = [
'subdomain.example.com',
'www.example.com',
'host from settings is trusted',
TRUE,
];
$data[] = [
'www.example.org',
'www.example.com',
'host from settings is trusted',
TRUE,
];
$data[] = [
'example.org',
'www.example.com',
'host from settings is trusted',
TRUE,
];
// Tests mismatch.
$data[] = [
'www.blackhat.com',
'www.example.com',
'unspecified host is untrusted',
FALSE,
];
return $data;
}
/**
* Tests site path finding.
*
* This test is run in a separate process since it defines DRUPAL_ROOT. This
* stops any possible pollution of other tests.
*
* @covers ::findSitePath
* @runInSeparateProcess
*/
public function testFindSitePath() {
$vfs_root = vfsStream::setup('drupal_root');
$sites_php = <<<'EOD'
<?php
$sites['8888.www.example.org'] = 'example';
EOD;
// Create the expected directory structure.
vfsStream::create([
'sites' => [
'sites.php' => $sites_php,
'example' => [
'settings.php' => 'test',
],
],
]);
define('DRUPAL_ROOT', $vfs_root
->url('drupal_root'));
$request = new Request();
$request->server
->set('SERVER_NAME', 'www.example.org');
$request->server
->set('SERVER_PORT', '8888');
$request->server
->set('SCRIPT_NAME', '/index.php');
$this
->assertEquals('sites/example', DrupalKernel::findSitePath($request));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalKernelTest:: |
public | function | Provides test data for testTrustedHosts(). | |
DrupalKernelTest:: |
public | function | Tests site path finding. | |
DrupalKernelTest:: |
public | function | Tests hostname validation with settings. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 259 |