$this->assertFileExists($node_file_r3,'Second file is still available after deleting second revision, since it is being used by the third revision.');
$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->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.');
@@ -102,7 +102,7 @@ public function testRevisions() {
// Delete the third revision and check that the file is not deleted yet.
$this->assertFileExists($node_file_r3,'Second file is still available after deleting third revision, since it is being used by the user.');
$this->assertFileExists($node_file_r3->getFileUri(),'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.');
@@ -129,7 +129,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->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->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.
@@ -145,7 +145,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->assertFileNotExists($node_file_r1->getFileUri(),'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.');
@trigger_error('Passing a File entity as $file argument to FileFieldTestBase::assertFileExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326',E_USER_DEPRECATED);
$file=$file->getFileUri();
}
$message=isset($message)?$message:format_string('File %file exists on the disk.',['%file'=>$file]);
parent::assertFileExists($file,$message);
}
/**
@@ -229,18 +234,23 @@ 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.
* Overrides PHPUnit\Framework\Assert::assertFileNotExists() 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.
@trigger_error('Passing a File entity as $file argument to FileFieldTestBase::assertFileNotExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326',E_USER_DEPRECATED);
$file=$file->getFileUri();
}
$message=isset($message)?$message:format_string('File %file exists on the disk.',['%file'=>$file]);
$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->assertFileExists($node_file->getFileUri(),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).
@@ -109,7 +109,7 @@ public function testFileMaxSize() {
$this->assertFileExists($node_file,format_string('File exists after uploading a file (%filesize) with no max limit.',['%filesize'=>format_size($large_file->getSize())]));
$this->assertFileExists($node_file->getFileUri(),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())]));
}
@@ -133,7 +133,7 @@ public function testFileExtension() {
$this->assertFileExists($node_file,'File exists after uploading a file with no extension checking.');
$this->assertFileExists($node_file->getFileUri(),'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.
@@ -187,4 +187,33 @@ public function testFileRemoval() {
$this->assertText('Article '.$node->getTitle().' has been updated.');
}
/**
* Tests deprecation of the assertFileExists and assertFileNotExists methods.
*
* @group legacy
*
* @expectedDeprecation Passing a File entity as $file argument to FileFieldTestBase::assertFileExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326
* @expectedDeprecation Passing a File entity as $file argument to FileFieldTestBase::assertFileNotExists is deprecated in drupal:8.8.0. It will be removed from drupal:9.0.0. Instead, pass the File entity URI via File::getFileUri(). See https://www.drupal.org/node/3057326