diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index b7b90d7d37..91bb58ca7d 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -2,6 +2,8 @@ namespace Drupal\file\Tests; +@trigger_error('The ' . __NAMESPACE__ . '\FileFieldTestBase is scheduled for removal in Drupal 9.0.0. Instead, use \Drupal\Tests\file\Functional\FileFieldTestBase', E_USER_DEPRECATED); + use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldConfig; use Drupal\file\FileInterface; diff --git a/core/modules/file/src/Tests/FileManagedTestBase.php b/core/modules/file/src/Tests/FileManagedTestBase.php index 879e1c4e94..fde651dca6 100644 --- a/core/modules/file/src/Tests/FileManagedTestBase.php +++ b/core/modules/file/src/Tests/FileManagedTestBase.php @@ -2,6 +2,8 @@ namespace Drupal\file\Tests; +@trigger_error('The ' . __NAMESPACE__ . '\FileManagedTestBase is scheduled for removal in Drupal 9.0.0. Instead, use \Drupal\Tests\file\Functional\FileManagedTestBase', E_USER_DEPRECATED); + use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\simpletest\WebTestBase; diff --git a/core/modules/file/src/Tests/DownloadTest.php b/core/modules/file/tests/src/Functional/DownloadTest.php similarity index 89% rename from core/modules/file/src/Tests/DownloadTest.php rename to core/modules/file/tests/src/Functional/DownloadTest.php index c5189fac20..327715ff2d 100644 --- a/core/modules/file/src/Tests/DownloadTest.php +++ b/core/modules/file/tests/src/Functional/DownloadTest.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/src/Tests/FileFieldAnonymousSubmissionTest.php b/core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php similarity index 95% rename from core/modules/file/src/Tests/FileFieldAnonymousSubmissionTest.php rename to core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php index 66d87cd7e8..0bed72fbdc 100644 --- a/core/modules/file/src/Tests/FileFieldAnonymousSubmissionTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php @@ -1,6 +1,6 @@ assertNotEqual($nid, 0, 'The node ID was extracted from the URL.'); $node = Node::load($nid); $this->assertNotEqual($node, NULL, 'The node was loaded successfully.'); - $this->assertFileExists(File::load($node->field_image->target_id), 'The image was uploaded successfully.'); + $this->assertFileExistsOnDisk(File::load($node->field_image->target_id), 'The image was uploaded successfully.'); } } @@ -162,7 +162,7 @@ protected function doTestNodeWithFileWithoutTitle() { $this->assertNotEqual($nid, 0, 'The node ID was extracted from the URL.'); $node = Node::load($nid); $this->assertNotEqual($node, NULL, 'The node was loaded successfully.'); - $this->assertFileExists(File::load($node->field_image->target_id), 'The image was uploaded successfully.'); + $this->assertFileExistsOnDisk(File::load($node->field_image->target_id), 'The image was uploaded successfully.'); } } diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php similarity index 99% rename from core/modules/file/src/Tests/FileFieldDisplayTest.php rename to core/modules/file/tests/src/Functional/FileFieldDisplayTest.php index db9b7dc91b..04af759a6e 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php @@ -1,6 +1,6 @@ load($nid); $node_file_r1 = File::load($node->{$field_name}->target_id); $node_vid_r1 = $node->getRevisionId(); - $this->assertFileExists($node_file_r1, 'New file saved to disk on node creation.'); + $this->assertFileExistsOnDisk($node_file_r1, 'New file saved to disk on node creation.'); $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.'); $this->assertFileIsPermanent($node_file_r1, 'File is permanent.'); @@ -49,7 +49,7 @@ public function testRevisions() { $node = $node_storage->load($nid); $node_file_r2 = File::load($node->{$field_name}->target_id); $node_vid_r2 = $node->getRevisionId(); - $this->assertFileExists($node_file_r2, 'Replacement file exists on disk after creating new revision.'); + $this->assertFileExistsOnDisk($node_file_r2, 'Replacement file exists on disk after creating new revision.'); $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.'); $this->assertFileIsPermanent($node_file_r2, 'Replacement file is permanent.'); @@ -57,7 +57,7 @@ public function testRevisions() { $node = node_revision_load($node_vid_r1); $current_file = File::load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $current_file->id(), 'Original file still in place after replacing file in new revision.'); - $this->assertFileExists($node_file_r1, 'Original file still in place after replacing file in new revision.'); + $this->assertFileExistsOnDisk($node_file_r1, 'Original file still in place after replacing file in new revision.'); $this->assertFileEntryExists($node_file_r1, 'Original file entry still in place after replacing file in new revision'); $this->assertFileIsPermanent($node_file_r1, 'Original file is still permanent.'); @@ -82,7 +82,7 @@ public function testRevisions() { // Delete the second revision and check that the file is kept (since it is // still being used by the third revision). $this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r2 . '/delete', [], t('Delete')); - $this->assertFileExists($node_file_r3, 'Second file is still available after deleting second revision, since it is being used by the third revision.'); + $this->assertFileExistsOnDisk($node_file_r3, 'Second file is still available after deleting second revision, since it is being used by the third revision.'); $this->assertFileEntryExists($node_file_r3, 'Second file entry is still available after deleting second revision, since it is being used by the third revision.'); $this->assertFileIsPermanent($node_file_r3, 'Second file entry is still permanent after deleting second revision, since it is being used by the third revision.'); @@ -95,7 +95,7 @@ public function testRevisions() { // Delete the third revision and check that the file is not deleted yet. $this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r3 . '/delete', [], t('Delete')); - $this->assertFileExists($node_file_r3, 'Second file is still available after deleting third revision, since it is being used by the user.'); + $this->assertFileExistsOnDisk($node_file_r3, 'Second file is still available after deleting third revision, since it is being used by the user.'); $this->assertFileEntryExists($node_file_r3, 'Second file entry is still available after deleting third revision, since it is being used by the user.'); $this->assertFileIsPermanent($node_file_r3, 'Second file entry is still permanent after deleting third revision, since it is being used by the user.'); @@ -120,7 +120,7 @@ public function testRevisions() { ->execute(); \Drupal::service('cron')->run(); - $this->assertFileNotExists($node_file_r3, 'Second file is now deleted after deleting third revision, since it is no longer being used by any other nodes.'); + $this->assertFileNotExistsOnDisk($node_file_r3, 'Second file is now deleted after deleting third revision, since it is no longer being used by any other nodes.'); $this->assertFileEntryNotExists($node_file_r3, 'Second file entry is now deleted after deleting third revision, since it is no longer being used by any other nodes.'); // Delete the entire node and check that the original file is deleted. @@ -135,7 +135,7 @@ public function testRevisions() { ->condition('fid', $node_file_r1->id()) ->execute(); \Drupal::service('cron')->run(); - $this->assertFileNotExists($node_file_r1, 'Original file is deleted after deleting the entire node with two revisions remaining.'); + $this->assertFileNotExistsOnDisk($node_file_r1, 'Original file is deleted after deleting the entire node with two revisions remaining.'); $this->assertFileEntryNotExists($node_file_r1, 'Original file entry is deleted after deleting the entire node with two revisions remaining.'); } diff --git a/core/modules/file/tests/src/Functional/FileFieldTestBase.php b/core/modules/file/tests/src/Functional/FileFieldTestBase.php index d6096874d6..e8f6569f74 100644 --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -7,12 +7,17 @@ use Drupal\file\FileInterface; use Drupal\Tests\BrowserTestBase; use Drupal\file\Entity\File; +use Drupal\Tests\TestFileCreationTrait; /** * Provides methods specifically for testing File module's field handling. */ abstract class FileFieldTestBase extends BrowserTestBase { + use TestFileCreationTrait { + getTestFiles as drupalGetTestFiles; + } + /** * Modules to enable. * @@ -224,7 +229,7 @@ public function uploadNodeFiles(array $files, $field_name, $nid_or_type, $new_re $edit[$name][] = $file_path; } } - $this->drupalPostForm("node/$nid/edit", $edit, t('Save and keep published')); + $this->drupalPostForm("node/$nid/edit", $edit, t('Save')); return $nid; } @@ -240,7 +245,7 @@ public function removeNodeFile($nid, $new_revision = TRUE) { ]; $this->drupalPostForm('node/' . $nid . '/edit', [], t('Remove')); - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); } /** @@ -253,24 +258,15 @@ public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) ]; $this->drupalPostForm('node/' . $nid . '/edit', [], t('Remove')); - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); } /** * Asserts that a file exists physically on disk. - * - * Overrides PHPUnit\Framework\Assert::assertFileExists() to also work with - * file entities. - * - * @param \Drupal\File\FileInterface|string $file - * Either the file entity or the file URI. - * @param string $message - * (optional) A message to display with the assertion. */ - public static function assertFileExists($file, $message = NULL) { + public function assertFileExistsOnDisk($file, $message = NULL) { $message = isset($message) ? $message : format_string('File %file exists on the disk.', ['%file' => $file->getFileUri()]); - $filename = $file instanceof FileInterface ? $file->getFileUri() : $file; - parent::assertFileExists($filename, $message); + $this->assertTrue(is_file($file->getFileUri()), $message); } /** @@ -285,19 +281,10 @@ public function assertFileEntryExists($file, $message = NULL) { /** * Asserts that a file does not exist on disk. - * - * Overrides PHPUnit\Framework\Assert::assertFileExists() to also work with - * file entities. - * - * @param \Drupal\File\FileInterface|string $file - * Either the file entity or the file URI. - * @param string $message - * (optional) A message to display with the assertion. */ - public static function assertFileNotExists($file, $message = NULL) { + public function assertFileNotExistsOnDisk($file, $message = NULL) { $message = isset($message) ? $message : format_string('File %file exists on the disk.', ['%file' => $file->getFileUri()]); - $filename = $file instanceof FileInterface ? $file->getFileUri() : $file; - parent::assertFileNotExists($filename, $message); + $this->assertFalse(is_file($file->getFileUri()), $message); } /** diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php similarity index 89% rename from core/modules/file/src/Tests/FileFieldValidateTest.php rename to core/modules/file/tests/src/Functional/FileFieldValidateTest.php index 422bf68282..546fed26e0 100644 --- a/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php @@ -1,6 +1,6 @@ load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file, 'File exists after uploading to the required field.'); + $this->assertFileExistsOnDisk($node_file, 'File exists after uploading to the required field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.'); // Try again with a multiple value field. @@ -58,7 +58,7 @@ public function testRequired() { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.'); + $this->assertFileExistsOnDisk($node_file, 'File exists after uploading to the required multiple value field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.'); } @@ -90,7 +90,7 @@ public function testFileMaxSize() { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', ['%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize])); + $this->assertFileExistsOnDisk($node_file, format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', ['%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize])); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', ['%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize])); // Check that uploading the large file fails (1M limit). @@ -107,7 +107,7 @@ public function testFileMaxSize() { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())])); + $this->assertFileExistsOnDisk($node_file, format_string('File exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())])); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())])); } @@ -131,7 +131,7 @@ public function testFileExtension() { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file, 'File exists after uploading a file with no extension checking.'); + $this->assertFileExistsOnDisk($node_file, 'File exists after uploading a file with no extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.'); // Enable extension checking for text files. @@ -150,7 +150,7 @@ public function testFileExtension() { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file, 'File exists after uploading a file with extension checking.'); + $this->assertFileExistsOnDisk($node_file, 'File exists after uploading a file with extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.'); } @@ -173,7 +173,7 @@ public function testFileRemoval() { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file, 'File exists after uploading a file with no extension checking.'); + $this->assertFileExistsOnDisk($node_file, 'File exists after uploading a file with no extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.'); // Enable extension checking for text files. diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/tests/src/Functional/FileListingTest.php similarity index 98% rename from core/modules/file/src/Tests/FileListingTest.php rename to core/modules/file/tests/src/Functional/FileListingTest.php index e348949a73..0a9b3875fb 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/tests/src/Functional/FileListingTest.php @@ -1,6 +1,6 @@ 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/src/Tests/FileOnTranslatedEntityTest.php b/core/modules/file/tests/src/Functional/FileOnTranslatedEntityTest.php similarity index 99% rename from core/modules/file/src/Tests/FileOnTranslatedEntityTest.php rename to core/modules/file/tests/src/Functional/FileOnTranslatedEntityTest.php index 5f1e7073df..f92ae4325e 100644 --- a/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php +++ b/core/modules/file/tests/src/Functional/FileOnTranslatedEntityTest.php @@ -1,6 +1,6 @@