diff --git a/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php b/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php index 1e8205e420bc8568d951c4c5d395863b4720970e..435c9766806ba5aceba123f4f1458e0158041f10 100644 --- a/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php +++ b/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php @@ -33,8 +33,9 @@ class FileSaveUploadTest extends KernelTestBase { * {@inheritdoc} */ protected function setUp(): void { - parent::setUp(); \file_put_contents('test.bbb', 'test'); + + parent::setUp(); $request = new Request(); $request->files->set('files', [ 'file' => new UploadedFile( @@ -52,14 +53,6 @@ protected function setUp(): void { $this->container->set('request_stack', $requestStack); } - /** - * {@inheritdoc} - */ - protected function tearDown(): void { - \unlink('test.bbb'); - parent::tearDown(); - } - /** * Tests file_save_upload() with empty extensions. */ diff --git a/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificKernelTestBase.php b/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificKernelTestBase.php index 564f0ddc80c5320ce2d378127545116ee71c3e74..a8f590b33d2e92b73f7403faf2f20cc0e45170d2 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificKernelTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificKernelTestBase.php @@ -31,7 +31,6 @@ protected function setUp(): void { // is not the one the test requires, skip before test database // initialization so to save cycles. $this->root = static::getDrupalRoot(); - chdir($this->root); $connectionInfo = $this->getDatabaseConnectionInfo(); $test_class_parts = explode('\\', get_class($this)); $expected_provider = $test_class_parts[2] ?? ''; diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index c10ca038928ad2898e25dad39a652a142386bf8b..94ee7a7d8746a6a03605cabe88432b90b24d3705 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -242,7 +242,6 @@ protected function setUp(): void { $this->registerComparator(new MarkupInterfaceComparator()); $this->root = static::getDrupalRoot(); - chdir($this->root); $this->initFileCache(); $this->bootEnvironment(); $this->bootKernel(); diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 9ed02c276ae155ded8c4a8dfbfd65fecb25b3117..486e86def42d1921b31cf88960aad050c3bf4e8d 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -352,7 +352,6 @@ protected function setUp(): void { parent::setUp(); $this->setUpAppRoot(); - chdir($this->root); // Allow tests to compare MarkupInterface objects via assertEquals(). $this->registerComparator(new MarkupInterfaceComparator()); diff --git a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php index 688b54b753f512c73c060a4b2a28b85a4838d13b..535b1d8c3168dc7dd4f0a6664c84150000fefac2 100644 --- a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php +++ b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php @@ -56,7 +56,6 @@ protected function setUp(): void { $php_executable_finder = new PhpExecutableFinder(); $this->php = $php_executable_finder->find(); $this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2); - chdir($this->root); if (!is_writable("{$this->root}/sites/simpletest")) { $this->markTestSkipped('This test requires a writable sites/simpletest directory'); } diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 73a2925cc6d0541e51926135d456a5e1903d1cb0..9d00d0a77826c55abe8fc8836fdc29fb6daad387 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -62,7 +62,6 @@ protected function setUp(): void { FileCacheFactory::setPrefix('prefix'); $this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2); - chdir($this->root); } /** diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index ae4ffac1a518a8e4291843b5813babfe11b7e9e8..0d663410407d569f287db099b6a3730ccf9adf27 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -183,3 +183,7 @@ class_alias('\Drupal\Tests\DocumentElement', '\Behat\Mink\Element\DocumentElemen if ($browserTestOutputDirectory !== FALSE) { HtmlOutputLogger::init($browserTestOutputDirectory, (bool) getenv('BROWSERTEST_OUTPUT_VERBOSE') ?? FALSE); } + +// Drupal expects to be run from its root directory. This ensures all test types +// are consistent. +chdir(dirname(__DIR__, 2));