diff --git a/composer.lock b/composer.lock index e35ae902ebc..41296cb5274 100644 --- a/composer.lock +++ b/composer.lock @@ -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": { diff --git a/core/assets/scaffold/files/update.php b/core/assets/scaffold/files/update.php index 59e808ed24c..b65649cb874 100644 --- a/core/assets/scaffold/files/update.php +++ b/core/assets/scaffold/files/update.php @@ -16,7 +16,6 @@ $autoloader = require_once 'autoload.php'; // 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(); diff --git a/core/composer.json b/core/composer.json index 4ef79995f56..671a37e8d66 100644 --- a/core/composer.json +++ b/core/composer.json @@ -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" diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 1d65db263df..77d3df7bad9 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -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 diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index a19197f4adf..fb65d1bbba2 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -984,9 +984,6 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { $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); diff --git a/core/lib/Drupal/Core/Test/TestKernel.php b/core/lib/Drupal/Core/Test/TestKernel.php index f7eed629d41..124dff402b2 100644 --- a/core/lib/Drupal/Core/Test/TestKernel.php +++ b/core/lib/Drupal/Core/Test/TestKernel.php @@ -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'); diff --git a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php index a88b019bcca..2338d469c32 100644 --- a/core/modules/views/tests/src/Unit/EntityViewsDataTest.php +++ b/core/modules/views/tests/src/Unit/EntityViewsDataTest.php @@ -1195,24 +1195,3 @@ class TestEntityType extends ContentEntityType { } } - -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); - } - -} diff --git a/core/rebuild.php b/core/rebuild.php index 612df7c3eea..0c4d0d91c08 100644 --- a/core/rebuild.php +++ b/core/rebuild.php @@ -25,7 +25,6 @@ require_once __DIR__ . '/includes/utility.inc'; $request = Request::createFromGlobals(); // Manually resemble early bootstrap of DrupalKernel::boot(). -require_once __DIR__ . '/includes/bootstrap.inc'; DrupalKernel::bootEnvironment(); try { diff --git a/core/scripts/db-tools.php b/core/scripts/db-tools.php index 618402199e2..dccd69ce218 100644 --- a/core/scripts/db-tools.php +++ b/core/scripts/db-tools.php @@ -17,7 +17,6 @@ if (PHP_SAPI !== 'cli') { // 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(); diff --git a/core/scripts/dump-database-d8-mysql.php b/core/scripts/dump-database-d8-mysql.php index 8c7766947f7..bce5d549bc4 100644 --- a/core/scripts/dump-database-d8-mysql.php +++ b/core/scripts/dump-database-d8-mysql.php @@ -17,7 +17,6 @@ if (PHP_SAPI !== 'cli') { // 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(); diff --git a/core/scripts/generate-proxy-class.php b/core/scripts/generate-proxy-class.php index 80aa1917ff6..d277c34d5ee 100644 --- a/core/scripts/generate-proxy-class.php +++ b/core/scripts/generate-proxy-class.php @@ -18,7 +18,6 @@ if (PHP_SAPI !== 'cli') { // 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(); diff --git a/core/scripts/rebuild_token_calculator.sh b/core/scripts/rebuild_token_calculator.sh index 362be3d5fda..0e495b37528 100755 --- a/core/scripts/rebuild_token_calculator.sh +++ b/core/scripts/rebuild_token_calculator.sh @@ -16,7 +16,6 @@ if (PHP_SAPI !== 'cli') { } $autoloader = require __DIR__ . '/../../autoload.php'; -require_once __DIR__ . '/../includes/bootstrap.inc'; $request = Request::createFromGlobals(); Settings::initialize(DRUPAL_ROOT, DrupalKernel::findSitePath($request), $autoloader); diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index 2627d73dac8..a5edce16dfa 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -258,8 +258,6 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa $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(); diff --git a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php index 594f29eabc0..89612cc8ea6 100644 --- a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php +++ b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php @@ -60,7 +60,6 @@ class QuickStartTest extends TestCase { } // Get a lock and a valid site path. $this->testDb = new TestDatabase(); - include $this->root . '/core/includes/bootstrap.inc'; } /** diff --git a/core/tests/Drupal/Tests/Core/CronTest.php b/core/tests/Drupal/Tests/Core/CronTest.php index c414c86bed7..835eb74fab5 100644 --- a/core/tests/Drupal/Tests/Core/CronTest.php +++ b/core/tests/Drupal/Tests/Core/CronTest.php @@ -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()); diff --git a/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php b/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php index 20b9f399f41..7c7dcd25752 100644 --- a/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php +++ b/core/tests/Drupal/Tests/Core/Database/DatabaseTest.php @@ -82,11 +82,6 @@ class DatabaseTest extends UnitTestCase { */ 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); diff --git a/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php b/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php index e77d2e25eb7..881b270390c 100644 --- a/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php +++ b/core/tests/Drupal/Tests/Core/DrupalKernel/DrupalKernelTest.php @@ -1,195 +1,183 @@ 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); + if (!empty($host)) { + $request->headers->set('HOST', $host); } - /** - * Provides test data for testTrustedHosts(). - */ - public function providerTestTrustedHosts() { - $data = []; + $request->server->set('SERVER_NAME', $server_name); - // Tests canonical URL. - $data[] = [ - 'www.example.com', - 'www.example.com', - 'canonical URL is trusted', - TRUE, - ]; + $method = new \ReflectionMethod('Drupal\Core\DrupalKernel', 'setupTrustedHosts'); + $method->setAccessible(TRUE); + $valid_host = $method->invoke(NULL, $request, $trusted_host_patterns); - // Tests missing hostname for HTTP/1.0 compatibility where the Host - // header is optional. - $data[] = [NULL, 'www.example.com', 'empty Host is valid', TRUE]; + $this->assertSame($expected, $valid_host, $message); - // 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, - ]; + // 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); + } - // Tests mismatch. - $data[] = [ - 'www.blackhat.com', - 'www.example.com', - 'unspecified host is untrusted', - FALSE, - ]; + /** + * Provides test data for testTrustedHosts(). + */ + public function providerTestTrustedHosts() { + $data = []; - return $data; - } + // Tests canonical URL. + $data[] = [ + 'www.example.com', + 'www.example.com', + 'canonical URL is trusted', + TRUE, + ]; - /** - * 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' + // 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' [ - 'sites.php' => $sites_php, - 'example' => [ - 'settings.php' => 'test', - ], + // 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'))); - } + $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'))); + } +} + +/** + * A fake autoloader for testing + */ +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); } /** - * A fake autoloader for testing + * Unregisters this instance as an autoloader. */ - 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; - } - - /** - * Finds a file by class name while caching lookups to APC. - * - * @return null - * This class never finds. - */ - public function findFile() { - return NULL; - } - + public function unregister() { + spl_autoload_unregister([$this, 'loadClass']); } -} - -namespace { - - if (!function_exists('drupal_valid_test_ua')) { - - function drupal_valid_test_ua($new_prefix = NULL) { - return FALSE; - } + /** + * 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; + } + } diff --git a/core/tests/Drupal/Tests/Core/Error/DrupalLogErrorTest.php b/core/tests/Drupal/Tests/Core/Error/DrupalLogErrorTest.php index 8b252491319..a867cd196b0 100644 --- a/core/tests/Drupal/Tests/Core/Error/DrupalLogErrorTest.php +++ b/core/tests/Drupal/Tests/Core/Error/DrupalLogErrorTest.php @@ -23,7 +23,6 @@ if (PHP_SAPI !== 'cli') { } $autoloader = require_once 'autoload.php'; -require_once 'core/includes/bootstrap.inc'; require_once 'core/includes/errors.inc'; define('DRUPAL_TEST_IN_CHILD_SITE', FALSE); diff --git a/core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php b/core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php index 10a1d567402..df22664e590 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ExtensionSerializationTest.php @@ -44,8 +44,6 @@ class ExtensionSerializationTest extends UnitTestCase { * @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 @@ class ExtensionSerializationTest extends UnitTestCase { $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)); } /** diff --git a/core/tests/Drupal/Tests/Core/Render/Element/MachineNameTest.php b/core/tests/Drupal/Tests/Core/Render/Element/MachineNameTest.php index 51f84615f4f..adc70ee2e27 100644 --- a/core/tests/Drupal/Tests/Core/Render/Element/MachineNameTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Element/MachineNameTest.php @@ -111,13 +111,3 @@ class MachineNameTest extends UnitTestCase { } } - -namespace Drupal\Core\Render\Element; - -if (!function_exists('t')) { - - function t($string, array $args = []) { - return strtr($string, $args); - } - -} diff --git a/core/tests/Drupal/Tests/TestRequirementsTrait.php b/core/tests/Drupal/Tests/TestRequirementsTrait.php index 924eb84e5c2..ee5ac350901 100644 --- a/core/tests/Drupal/Tests/TestRequirementsTrait.php +++ b/core/tests/Drupal/Tests/TestRequirementsTrait.php @@ -77,9 +77,6 @@ trait TestRequirementsTrait { * 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) { diff --git a/update.php b/update.php index 59e808ed24c..b65649cb874 100644 --- a/update.php +++ b/update.php @@ -16,7 +16,6 @@ $autoloader = require_once 'autoload.php'; // 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();