diff --git a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php similarity index 98% rename from core/modules/file/tests/src/Functional/FileFieldWidgetTest.php rename to core/modules/file/src/Tests/FileFieldWidgetTest.php index c6cec35814..ad47d77841 100644 --- a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -1,6 +1,6 @@ resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExistsOnDisk($node_file, 'New file saved to disk on node creation.'); + $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); @@ -320,7 +320,7 @@ public function testPrivateFileSetting() { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExistsOnDisk($node_file, 'New file saved to disk on node creation.'); + $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the private file is available to the user who uploaded it. $this->drupalGet(file_create_url($node_file->getFileUri())); @@ -387,7 +387,7 @@ public function testPrivateFileComment() { $comment = Comment::load($cid); $comment_file = $comment->{'field_' . $name}->entity; - $this->assertFileExistsOnDisk($comment_file, 'New file saved to disk on node creation.'); + $this->assertFileExists($comment_file, 'New file saved to disk on node creation.'); // Test authenticated file download. $url = file_create_url($comment_file->getFileUri()); $this->assertNotEqual($url, NULL, 'Confirmed that the URL is valid'); @@ -572,7 +572,7 @@ protected function doTestTemporaryFileRemovalExploit(UserInterface $victim_user, /** @var \Drupal\file\FileInterface $node_file */ $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExistsOnDisk($node_file, 'A file was saved to disk on node creation'); + $this->assertFileExists($node_file, 'A file was saved to disk on node creation'); $this->assertEqual($attacker_user->id(), $node_file->getOwnerId(), 'New file belongs to the attacker.'); // Ensure the file can be downloaded. @@ -595,7 +595,7 @@ protected function doTestTemporaryFileRemovalExploit(UserInterface $victim_user, // The victim's temporary file should not be removed by the attacker's // POST request. - $this->assertFileExistsOnDisk($victim_tmp_file); + $this->assertFileExists($victim_tmp_file); } } diff --git a/core/modules/file/tests/src/Functional/FileManagedFileElementTest.php b/core/modules/file/src/Tests/FileManagedFileElementTest.php similarity index 99% rename from core/modules/file/tests/src/Functional/FileManagedFileElementTest.php rename to core/modules/file/src/Tests/FileManagedFileElementTest.php index a880461a00..8abff25e45 100644 --- a/core/modules/file/tests/src/Functional/FileManagedFileElementTest.php +++ b/core/modules/file/src/Tests/FileManagedFileElementTest.php @@ -1,6 +1,6 @@ getViaScheme('public')->getDirectoryPath() . '/' . rawurlencode($file->getFilename()); $this->assertEqual($filename, $url, 'Correctly generated a URL for a created file.'); - $this->drupalHead($url); - $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the created file.'); - + $http_client = \Drupal::httpClient(); + $response = $http_client->head($url); + $this->assertEquals(200, $response->getStatusCode(), 'Confirmed that the generated URL is correct by downloading the created file.'); // Test generating a URL to a shipped file (i.e. a file that is part of // Drupal core, a module or a theme, for example a JavaScript file). $filepath = 'core/assets/vendor/jquery/jquery.min.js'; $url = file_create_url($filepath); $this->assertEqual($GLOBALS['base_url'] . '/' . $filepath, $url, 'Correctly generated a URL for a shipped file.'); - $this->drupalHead($url); - $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); + $response = $http_client->head($url); + $this->assertEquals(200, $response->getStatusCode(), 'Confirmed that the generated URL is correct by downloading the shipped file.'); } /** @@ -74,13 +74,14 @@ protected function doPrivateFileTransferTest() { // Deny access to all downloads via a -1 header. file_test_set_return('download', -1); - $this->drupalHead($url); - $this->assertResponse(403, 'Correctly denied access to a file when file_test sets the header to -1.'); + $http_client = \Drupal::httpClient(); + $response = $http_client->head($url); + $this->assertEquals(403, $response->getStatusCode(), 'Correctly denied access to a file when file_test sets the header to -1.'); // Try non-existent file. $url = file_create_url('private://' . $this->randomMachineName()); - $this->drupalHead($url); - $this->assertResponse(404, 'Correctly returned 404 response for a non-existent file.'); + $response = $http_client->head($url); + $this->assertEquals(404, $response->getStatusCode(), 'Correctly returned 404 response for a non-existent file.'); } /** diff --git a/core/modules/file/tests/src/Functional/FileListingTest.php b/core/modules/file/tests/src/Functional/FileListingTest.php index 16e70d07d6..0a9b3875fb 100644 --- a/core/modules/file/tests/src/Functional/FileListingTest.php +++ b/core/modules/file/tests/src/Functional/FileListingTest.php @@ -122,7 +122,7 @@ public function testFileListingPages() { $usage = $this->sumUsages($file_usage->listUsage($file)); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); - $result = $this->xpath("//td[contains(@class, 'views-field-status') and contains(text(), :value)]", [':value' => t('Temporary')]); + $result = $this->xpath("//td[contains(@class, 'views-field-status') and contains(text(), :value)]", [':value' => 'Temporary']); $this->assertEqual(1, count($result), 'Unused file marked as temporary.'); // Test file usage page. diff --git a/core/modules/file/tests/src/Functional/SaveUploadTest.php b/core/modules/file/tests/src/Functional/SaveUploadTest.php index b6405b5bf1..9382c8b4a6 100644 --- a/core/modules/file/tests/src/Functional/SaveUploadTest.php +++ b/core/modules/file/tests/src/Functional/SaveUploadTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\file\Functional; use Drupal\file\Entity\File; +use Drupal\Tests\TestFileCreationTrait; /** * Tests the file_save_upload() function. @@ -10,6 +11,11 @@ * @group file */ class SaveUploadTest extends FileManagedTestBase { + + use TestFileCreationTrait { + getTestFiles as drupalGetTestFiles; + } + /** * Modules to enable. *