Unverified Commit 83b3db44 authored by Alex Pott's avatar Alex Pott
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
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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());
    }
  }

+7 −7
Original line number Diff line number Diff line
@@ -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.');
  }

+7 −7
Original line number Diff line number Diff line
@@ -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.
+4 −4
Original line number Diff line number Diff line
@@ -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.
+2 −2
Original line number Diff line number Diff line
@@ -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);
  }

  /**
Loading