Unverified Commit 83b3db44 authored by alexpott's avatar alexpott
Browse files

Issue #3131258 by longwave, mondrake, dww: Remove redundant $message from...

Issue #3131258 by longwave, mondrake, dww: Remove redundant $message from assertFile(Not)Exists and assertDirectory(Not)Exists calls

(cherry picked from commit 023ef041)
parent 7e25c77a
......@@ -93,7 +93,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)->getFileUri(), 'The image was uploaded successfully.');
$this->assertFileExists(File::load($node->field_image->target_id)->getFileUri());
}
}
......@@ -167,7 +167,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)->getFileUri(), 'The image was uploaded successfully.');
$this->assertFileExists(File::load($node->field_image->target_id)->getFileUri());
}
}
......
......@@ -51,7 +51,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->getFileUri(), 'New file saved to disk on node creation.');
$this->assertFileExists($node_file_r1->getFileUri());
$this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.');
$this->assertFileIsPermanent($node_file_r1, 'File is permanent.');
......@@ -61,7 +61,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->getFileUri(), 'Replacement file exists on disk after creating new revision.');
$this->assertFileExists($node_file_r2->getFileUri());
$this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.');
$this->assertFileIsPermanent($node_file_r2, 'Replacement file is permanent.');
......@@ -69,7 +69,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->getFileUri(), 'Original file still in place after replacing file in new revision.');
$this->assertFileExists($node_file_r1->getFileUri());
$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.');
......@@ -94,7 +94,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->getFileUri(), 'Second file is still available after deleting second revision, since it is being used by the third revision.');
$this->assertFileExists($node_file_r3->getFileUri());
$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.');
......@@ -107,7 +107,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->getFileUri(), 'Second file is still available after deleting third revision, since it is being used by the user.');
$this->assertFileExists($node_file_r3->getFileUri());
$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.');
......@@ -134,7 +134,7 @@ public function testRevisions() {
->execute();
\Drupal::service('cron')->run();
$this->assertFileNotExists($node_file_r3->getFileUri(), 'Second file is now deleted after deleting third revision, since it is no longer being used by any other nodes.');
$this->assertFileNotExists($node_file_r3->getFileUri());
$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.
......@@ -150,7 +150,7 @@ public function testRevisions() {
->condition('fid', $node_file_r1->id())
->execute();
\Drupal::service('cron')->run();
$this->assertFileNotExists($node_file_r1->getFileUri(), 'Original file is deleted after deleting the entire node with two revisions remaining.');
$this->assertFileNotExists($node_file_r1->getFileUri());
$this->assertFileEntryNotExists($node_file_r1, 'Original file entry is deleted after deleting the entire node with two revisions remaining.');
}
......
......@@ -46,7 +46,7 @@ public function testRequired() {
$node = $node_storage->load($nid);
$node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file->getFileUri(), 'File exists after uploading to the required field.');
$this->assertFileExists($node_file->getFileUri());
$this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.');
// Try again with a multiple value field.
......@@ -64,7 +64,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->getFileUri(), 'File exists after uploading to the required multiple value field.');
$this->assertFileExists($node_file->getFileUri());
$this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.');
}
......@@ -98,7 +98,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->getFileUri(), new FormattableMarkup('File exists after uploading a file (%filesize) under the max limit (%maxsize).', ['%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize]));
$this->assertFileExists($node_file->getFileUri());
$this->assertFileEntryExists($node_file, new FormattableMarkup('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).
......@@ -115,7 +115,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->getFileUri(), new FormattableMarkup('File exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())]));
$this->assertFileExists($node_file->getFileUri());
$this->assertFileEntryExists($node_file, new FormattableMarkup('File entry exists after uploading a file (%filesize) with no max limit.', ['%filesize' => format_size($large_file->getSize())]));
}
......@@ -139,7 +139,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->getFileUri(), 'File exists after uploading a file with no extension checking.');
$this->assertFileExists($node_file->getFileUri());
$this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.');
// Enable extension checking for text files.
......@@ -158,7 +158,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->getFileUri(), 'File exists after uploading a file with extension checking.');
$this->assertFileExists($node_file->getFileUri());
$this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.');
}
......@@ -181,7 +181,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->getFileUri(), 'File exists after uploading a file with no extension checking.');
$this->assertFileExists($node_file->getFileUri());
$this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.');
// Enable extension checking for text files.
......
......@@ -89,7 +89,7 @@ public function testSingleValuedWidget() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = $node_storage->loadUnchanged($nid);
$node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file->getFileUri(), 'New file saved to disk on node creation.');
$this->assertFileExists($node_file->getFileUri());
// Ensure the file can be downloaded.
$this->drupalGet($node_file->createFileUrl());
......@@ -263,7 +263,7 @@ public function testPrivateFileSetting() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node = $node_storage->loadUnchanged($nid);
$node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file->getFileUri(), 'New file saved to disk on node creation.');
$this->assertFileExists($node_file->getFileUri());
// Ensure the private file is available to the user who uploaded it.
$this->drupalGet($node_file->createFileUrl());
......@@ -330,7 +330,7 @@ public function testPrivateFileComment() {
$comment = Comment::load($cid);
$comment_file = $comment->{'field_' . $name}->entity;
$this->assertFileExists($comment_file->getFileUri(), 'New file saved to disk on node creation.');
$this->assertFileExists($comment_file->getFileUri());
// Test authenticated file download.
$url = $comment_file->createFileUrl();
$this->assertNotEqual($url, NULL, 'Confirmed that the URL is valid');
......@@ -507,7 +507,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->getFileUri(), 'A file was saved to disk on node creation');
$this->assertFileExists($node_file->getFileUri());
$this->assertEqual($attacker_user->id(), $node_file->getOwnerId(), 'New file belongs to the attacker.');
// Ensure the file can be downloaded.
......
......@@ -40,7 +40,7 @@ public function testOverwritingDownload() {
// Test destructive download.
$actual_destination = $this->doTransform($destination_uri);
$this->assertSame($destination_uri, $actual_destination, 'Import returned a destination that was not renamed');
$this->assertFileNotExists('public://existing_file_0.txt', 'Import did not rename the file');
$this->assertFileNotExists('public://existing_file_0.txt');
}
/**
......@@ -53,7 +53,7 @@ public function testNonDestructiveDownload() {
// Test non-destructive download.
$actual_destination = $this->doTransform($destination_uri, ['file_exists' => 'rename']);
$this->assertSame('public://another_existing_file_0.txt', $actual_destination, 'Import returned a renamed destination');
$this->assertFileExists($actual_destination, 'Downloaded file was created');
$this->assertFileExists($actual_destination);
}
/**
......
......@@ -67,10 +67,9 @@ public function testSuccessfulCopies() {
foreach ($data_sets as $data) {
list($source_path, $destination_path) = $data;
$actual_destination = $this->doTransform($source_path, $destination_path);
$message = sprintf('File %s exists', $destination_path);
$this->assertFileExists($destination_path, $message);
$this->assertFileExists($destination_path);
// Make sure we didn't accidentally do a move.
$this->assertFileExists($source_path, $message);
$this->assertFileExists($source_path);
$this->assertSame($actual_destination, $destination_path, 'The import returned the copied filename.');
}
}
......@@ -152,10 +151,8 @@ public function testSuccessfulMoves() {
foreach ($data_sets as $data) {
list($source_path, $destination_path) = $data;
$actual_destination = $this->doTransform($source_path, $destination_path, ['move' => TRUE]);
$message = sprintf('File %s exists', $destination_path);
$this->assertFileExists($destination_path, $message);
$message = sprintf('File %s does not exist', $source_path);
$this->assertFileNotExists($source_path, $message);
$this->assertFileExists($destination_path);
$this->assertFileNotExists($source_path);
$this->assertSame($actual_destination, $destination_path, 'The importer returned the moved filename.');
}
}
......@@ -205,7 +202,7 @@ public function testRenameFile() {
$destination = $this->createUri('foo.txt', NULL, 'public');
$expected_destination = 'public://foo_0.txt';
$actual_destination = $this->doTransform($source, $destination, ['file_exists' => 'rename']);
$this->assertFileExists($expected_destination, 'File was renamed on import');
$this->assertFileExists($expected_destination);
$this->assertSame($actual_destination, $expected_destination, 'The importer returned the renamed filename.');
}
......
......@@ -94,7 +94,7 @@ public function testCreateDeletePicture() {
$this->assertNull(File::load($file->id()), 'File was removed from the database.');
// Clear out PHP's file stat cache so we see the current value.
clearstatcache(TRUE, $file->getFileUri());
$this->assertFileNotExists($file->getFileUri(), 'File was removed from the file system.');
$this->assertFileNotExists($file->getFileUri());
}
/**
......
......@@ -125,8 +125,8 @@ public function testStable9LibraryOverrides() {
$assert_path = str_replace("core/modules/$extension/", '', $clean_path);
$this->assertEqual($expected_path, $stable_path, "$assert_path from the $extension/$library_name library is overridden in Stable 9.");
$this->assertFileExists("{$this->root}/$clean_path", "$clean_path exists.");
$this->assertFileExists("{$this->root}/$stable_path", "$stable_path exists.");
$this->assertFileExists("{$this->root}/$clean_path");
$this->assertFileExists("{$this->root}/$stable_path");
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment