Commit b72fe50a authored by catch's avatar catch

Issue #3151118 by alexpott, Beakerboy, kapilkumar0324, anmolgoyal74, jungle,...

Issue #3151118 by alexpott, Beakerboy, kapilkumar0324, anmolgoyal74, jungle, heddn, Mile23, andypost, daffie: Include bootstrap.inc using composer
parent a8ef4362
......@@ -527,7 +527,7 @@
"dist": {
"type": "path",
"url": "core",
"reference": "0809224944e41d0a5d03f65e1f7a179512647923"
"reference": "af5b9453adf15c6831b1f73e322f8c59da877f14"
},
"require": {
"asm89/stack-cors": "^1.1",
......@@ -752,6 +752,9 @@
"lib/Drupal/Core/DrupalKernelInterface.php",
"lib/Drupal/Core/Installer/InstallerRedirectTrait.php",
"lib/Drupal/Core/Site/Settings.php"
],
"files": [
"includes/bootstrap.inc"
]
},
"scripts": {
......
......@@ -16,7 +16,6 @@
// Disable garbage collection during test runs. Under certain circumstances the
// update path will create so many objects that garbage collection causes
// segmentation faults.
require_once 'core/includes/bootstrap.inc';
if (drupal_valid_test_ua()) {
gc_collect_cycles();
gc_disable();
......
......@@ -198,7 +198,8 @@
"lib/Drupal/Core/DrupalKernelInterface.php",
"lib/Drupal/Core/Installer/InstallerRedirectTrait.php",
"lib/Drupal/Core/Site/Settings.php"
]
],
"files": [ "includes/bootstrap.inc" ]
},
"config": {
"preferred-install": "dist"
......
......@@ -311,9 +311,6 @@ function install_begin_request($class_loader, &$install_state) {
$install_state['parameters']['langcode'] = preg_replace('/[^a-zA-Z_0-9\-]/', '', $install_state['parameters']['langcode']);
}
// Allow command line scripts to override server variables used by Drupal.
require_once __DIR__ . '/bootstrap.inc';
// If the hash salt leaks, it becomes possible to forge a valid testing user
// agent, install a new copy of Drupal, and take over the original site.
// The user agent header is used to pass a database prefix in the request when
......
......@@ -984,9 +984,6 @@ public static function bootEnvironment($app_root = NULL) {
$app_root = static::guessApplicationRoot();
}
// Include our bootstrap file.
require_once $app_root . '/core/includes/bootstrap.inc';
// Enforce E_STRICT, but allow users to set levels not part of E_STRICT.
error_reporting(E_STRICT | E_ALL);
......
......@@ -13,9 +13,6 @@ class TestKernel extends DrupalKernel {
* {@inheritdoc}
*/
public function __construct($environment, $class_loader, $allow_dumping = TRUE) {
// Include our bootstrap file.
require_once __DIR__ . '/../../../../includes/bootstrap.inc';
// Exit if we should be in a test environment but aren't.
if (!drupal_valid_test_ua()) {
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
......
......@@ -1195,24 +1195,3 @@ public function setKey($key, $value) {
}
}
namespace Drupal\entity_test\Entity;
if (!function_exists('t')) {
function t($string, array $args = []) {
return strtr($string, $args);
}
}
namespace Drupal\Core\Entity;
if (!function_exists('t')) {
function t($string, array $args = []) {
return strtr($string, $args);
}
}
......@@ -25,7 +25,6 @@
$request = Request::createFromGlobals();
// Manually resemble early bootstrap of DrupalKernel::boot().
require_once __DIR__ . '/includes/bootstrap.inc';
DrupalKernel::bootEnvironment();
try {
......
......@@ -17,7 +17,6 @@
// Bootstrap.
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(__DIR__, 2), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
......
......@@ -17,7 +17,6 @@
// Bootstrap.
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(__DIR__, 2), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
......
......@@ -18,7 +18,6 @@
// Bootstrap.
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(__DIR__, 2), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
......
......@@ -16,7 +16,6 @@
}
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(DRUPAL_ROOT, DrupalKernel::findSitePath($request), $autoloader);
......
......@@ -258,8 +258,6 @@ protected function bootEnvironment() {
$this->classLoader = require $this->root . '/autoload.php';
require_once $this->root . '/core/includes/bootstrap.inc';
// Set up virtual filesystem.
Database::addConnectionInfo('default', 'test-runner', $this->getDatabaseConnectionInfo()['default']);
$test_db = new TestDatabase();
......
......@@ -60,7 +60,6 @@ public function setUp(): void {
}
// Get a lock and a valid site path.
$this->testDb = new TestDatabase();
include $this->root . '/core/includes/bootstrap.inc';
}
/**
......
......@@ -59,13 +59,6 @@ class CronTest extends UnitTestCase {
protected function setUp(): void {
parent::setUp();
// @todo Remove in https://www.drupal.org/project/drupal/issues/2932518
//
// This line is currently needed so that watchdog_exception() is available
// when unit testing Drupal\Core\Cron and can safely be removed once that
// class no longer refers to it.
require_once $this->root . '/core/includes/bootstrap.inc';
// Construct a state object used for testing logger assertions.
$this->state = new State(new KeyValueMemoryFactory());
......
......@@ -82,11 +82,6 @@ public function providerFindDriverAutoloadDirectory() {
*/
public function testFindDriverAutoloadDirectoryException($expected_message, $namespace, $include_tests) {
new Settings(['extension_discovery_scan_tests' => $include_tests]);
if ($include_tests === FALSE) {
// \Drupal\Core\Extension\ExtensionDiscovery::scan() needs
// drupal_valid_test_ua().
include $this->root . '/core/includes/bootstrap.inc';
}
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage($expected_message);
Database::findDriverAutoloadDirectory($namespace, $this->root);
......
<?php
namespace Drupal\Tests\Core\DrupalKernel {
namespace Drupal\Tests\Core\DrupalKernel;
use Drupal\Core\DrupalKernel;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\DrupalKernel;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
use Symfony\Component\HttpFoundation\Request;
/**
* @coversDefaultClass \Drupal\Core\DrupalKernel
* @group DrupalKernel
*/
class DrupalKernelTest extends UnitTestCase {
/**
* @coversDefaultClass \Drupal\Core\DrupalKernel
* @group DrupalKernel
* Tests hostname validation with settings.
*
* @covers ::setupTrustedHosts
* @dataProvider providerTestTrustedHosts
*/
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);
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);
}
/**
* 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;
}
$request->server->set('SERVER_NAME', $server_name);
/**
* 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;
$method = new \ReflectionMethod('Drupal\Core\DrupalKernel', 'setupTrustedHosts');
$method->setAccessible(TRUE);
$valid_host = $method->invoke(NULL, $request, $trusted_host_patterns);
// Create the expected directory structure.
vfsStream::create([
'sites' => [
'sites.php' => $sites_php,
'example' => [
'settings.php' => 'test',
],
],
]);
$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, TRUE, $vfs_root->url('drupal_root')));
$this->assertEquals('sites/example', DrupalKernel::findSitePath($request, FALSE, $vfs_root->url('drupal_root')));
}
$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);
}
/**
* A fake autoloader for testing
* Provides test data for testTrustedHosts().
*/
class FakeAutoloader {
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend
* Whether to prepend the autoloader or not
*/
public function register($prepend = FALSE) {
spl_autoload_register([$this, 'loadClass'], TRUE, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister() {
spl_autoload_unregister([$this, 'loadClass']);
}
/**
* Loads the given class or interface.
*
* @return null
* This class never loads.
*/
public function loadClass() {
return NULL;
}
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;
}
/**
* Finds a file by class name while caching lookups to APC.
*
* @return null
* This class never finds.
*/
public function findFile() {
return NULL;
}
/**
* 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',
],
],
]);
$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, TRUE, $vfs_root->url('drupal_root')));
$this->assertEquals('sites/example', DrupalKernel::findSitePath($request, FALSE, $vfs_root->url('drupal_root')));
}
}
namespace {
/**
* A fake autoloader for testing
*/
class FakeAutoloader {
if (!function_exists('drupal_valid_test_ua')) {
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend
* Whether to prepend the autoloader or not
*/
public function register($prepend = FALSE) {
spl_autoload_register([$this, 'loadClass'], TRUE, $prepend);
}
function drupal_valid_test_ua($new_prefix = NULL) {
return FALSE;
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister() {
spl_autoload_unregister([$this, 'loadClass']);
}
/**
* Loads the given class or interface.
*
* @return null
* This class never loads.
*/
public function loadClass() {
return NULL;
}
/**
* Finds a file by class name while caching lookups to APC.
*
* @return null
* This class never finds.
*/
public function findFile() {
return NULL;
}
}
......@@ -23,7 +23,6 @@ public function testFatalExitCode() {
}
$autoloader = require_once 'autoload.php';
require_once 'core/includes/bootstrap.inc';
require_once 'core/includes/errors.inc';
define('DRUPAL_TEST_IN_CHILD_SITE', FALSE);
......
......@@ -44,8 +44,6 @@ protected function setUp(): void {
* @covers ::__wakeup
*/
public function testServiceAppRouteUsage() {
// The assumption of our test is that DRUPAL_ROOT is not defined.
$this->assertFalse(defined('DRUPAL_ROOT'), 'Constant DRUPAL_ROOT is defined.');
$container = new ContainerBuilder();
// Set a dummy container app.root to test against.
$container->setParameter('app.root', 'vfs://dummy_app_root');
......@@ -56,6 +54,14 @@ public function testServiceAppRouteUsage() {
$reflected_root = new \ReflectionProperty($extension, 'root');
$reflected_root->setAccessible(TRUE);
$this->assertEquals('vfs://dummy_app_root', $reflected_root->getValue($extension));
// Change the app root and test serializing and unserializing again.
$container->setParameter('app.root', 'vfs://dummy_app_root2');
\Drupal::setContainer($container);
$extension = unserialize(serialize($extension));
$reflected_root = new \ReflectionProperty($extension, 'root');
$reflected_root->setAccessible(TRUE);
$this->assertEquals('vfs://dummy_app_root2', $reflected_root->getValue($extension));
}
/**
......
......@@ -111,13 +111,3 @@ public function testProcessMachineName() {
}
}
namespace Drupal\Core\Render\Element;
if (!function_exists('t')) {
function t($string, array $args = []) {
return strtr($string, $args);
}
}
......@@ -77,9 +77,6 @@ protected function checkRequirements() {
* skipped. Callers should not catch this exception.
*/
private function checkModuleRequirements($root, array $annotations) {
// drupal_valid_ua() might not be loaded.
require_once $root . '/core/includes/bootstrap.inc';
// Make a list of required modules.
$required_modules = [];
foreach ($annotations as $requirement) {
......
......@@ -16,7 +16,6 @@
// Disable garbage collection during test runs. Under certain circumstances the
// update path will create so many objects that garbage collection causes
// segmentation faults.
require_once 'core/includes/bootstrap.inc';
if (drupal_valid_test_ua()) {
gc_collect_cycles();
gc_disable();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment