diff --git a/core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php b/core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php index 9f004abba7..0bed72fbdc 100644 --- a/core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldAnonymousSubmissionTest.php @@ -88,7 +88,7 @@ public function testAnonymousNodeWithFile() { $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.'); } } @@ -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/tests/src/Functional/FileFieldRevisionTest.php b/core/modules/file/tests/src/Functional/FileFieldRevisionTest.php index e4f7c80fd3..bb389dc0a6 100644 --- a/core/modules/file/tests/src/Functional/FileFieldRevisionTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldRevisionTest.php @@ -39,7 +39,7 @@ public function testRevisions() { $node = $node_storage->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 e946985323..e8f6569f74 100644 --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -264,7 +264,7 @@ public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) /** * Asserts that a file exists physically on disk. */ - public 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()]); $this->assertTrue(is_file($file->getFileUri()), $message); } @@ -282,7 +282,7 @@ public function assertFileEntryExists($file, $message = NULL) { /** * Asserts that a file does not exist on disk. */ - public 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()]); $this->assertFalse(is_file($file->getFileUri()), $message); } diff --git a/core/modules/file/tests/src/Functional/FileFieldValidateTest.php b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php index b2c5d4ecd7..546fed26e0 100644 --- a/core/modules/file/tests/src/Functional/FileFieldValidateTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldValidateTest.php @@ -40,7 +40,7 @@ public function testRequired() { $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 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/tests/src/Functional/FileFieldWidgetTest.php b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php index 97d7eb6d6d..c6cec35814 100644 --- a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php +++ b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php @@ -90,7 +90,7 @@ public function testSingleValuedWidget() { $node_storage->resetCache([$nid]); $node = $node_storage->load($nid); $node_file = File::load($node->{$field_name}->target_id); - $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); + $this->assertFileExistsOnDisk($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->assertFileExists($node_file, 'New file saved to disk on node creation.'); + $this->assertFileExistsOnDisk($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->assertFileExists($comment_file, 'New file saved to disk on node creation.'); + $this->assertFileExistsOnDisk($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->assertFileExists($node_file, 'A file was saved to disk on node creation'); + $this->assertFileExistsOnDisk($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->assertFileExists($victim_tmp_file); + $this->assertFileExistsOnDisk($victim_tmp_file); } } 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. *