diff --git a/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php b/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php index 435c9766806ba5aceba123f4f1458e0158041f10..1e8205e420bc8568d951c4c5d395863b4720970e 100644 --- a/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php +++ b/core/modules/file/tests/src/Kernel/FileSaveUploadTest.php @@ -33,9 +33,8 @@ class FileSaveUploadTest extends KernelTestBase { * {@inheritdoc} */ protected function setUp(): void { - \file_put_contents('test.bbb', 'test'); - parent::setUp(); + \file_put_contents('test.bbb', 'test'); $request = new Request(); $request->files->set('files', [ 'file' => new UploadedFile( @@ -53,6 +52,14 @@ 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 a8f590b33d2e92b73f7403faf2f20cc0e45170d2..564f0ddc80c5320ce2d378127545116ee71c3e74 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificKernelTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Database/DriverSpecificKernelTestBase.php @@ -31,6 +31,7 @@ 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 94ee7a7d8746a6a03605cabe88432b90b24d3705..c10ca038928ad2898e25dad39a652a142386bf8b 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -242,6 +242,7 @@ 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 f9efa6d3427e0135d70d4a8662d279d630fd0dcf..6abba5431e11cd757de8e22e997a2eebd8d1404e 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -351,6 +351,7 @@ 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 535b1d8c3168dc7dd4f0a6664c84150000fefac2..688b54b753f512c73c060a4b2a28b85a4838d13b 100644 --- a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php +++ b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php @@ -56,6 +56,7 @@ 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/Core/Recipe/RecipeQuickStartTest.php b/core/tests/Drupal/Tests/Core/Recipe/RecipeQuickStartTest.php index 35505fe1fe5b294c9bf1b8f617644ebabffd674c..c71cd91bff0586c64a54ca4e549fc7d45b2b9626 100644 --- a/core/tests/Drupal/Tests/Core/Recipe/RecipeQuickStartTest.php +++ b/core/tests/Drupal/Tests/Core/Recipe/RecipeQuickStartTest.php @@ -92,14 +92,17 @@ public function testQuickStartRecipeCommand(): void { // Install a site using the standard recipe to ensure the one time login // link generation works. + $script = $this->root . '/core/scripts/drupal'; $install_command = [ $this->php, - 'core/scripts/drupal', + $script, 'quick-start', 'core/recipes/standard', "--site-name='Test site {$this->testDb->getDatabasePrefix()}'", '--suppress-login', ]; + $this->assertFileExists($script, "Install script is found in $script"); + $process = new Process($install_command, NULL, ['DRUPAL_DEV_SITE_PATH' => $this->testDb->getTestSitePath()]); $process->setTimeout(500); $process->start(); @@ -123,7 +126,7 @@ public function testQuickStartRecipeCommand(): void { // Generate a cookie so we can make a request against the installed site. define('DRUPAL_TEST_IN_CHILD_SITE', FALSE); - chmod($this->testDb->getTestSitePath(), 0755); + chmod($this->root . '/' . $this->testDb->getTestSitePath(), 0755); $cookieJar = CookieJar::fromArray([ 'SIMPLETEST_USER_AGENT' => drupal_generate_test_ua($this->testDb->getDatabasePrefix()), ], '127.0.0.1'); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 9d00d0a77826c55abe8fc8836fdc29fb6daad387..73a2925cc6d0541e51926135d456a5e1903d1cb0 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -62,6 +62,7 @@ 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 0d663410407d569f287db099b6a3730ccf9adf27..ae4ffac1a518a8e4291843b5813babfe11b7e9e8 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -183,7 +183,3 @@ 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));