Commit de052f01 authored by catch's avatar catch
Browse files

Issue #3130396 by longwave, jungle, dww, mondrake: Replace assertions...

Issue #3130396 by longwave, jungle, dww, mondrake: Replace assertions involving calls to is_file with assertFileExists()/assertFileNotExists()
parent 4d02fe7c
......@@ -194,7 +194,7 @@ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
}
file_put_contents($filepath, $contents);
$this->assertTrue(is_file($filepath), t('The test file exists on the disk.'), 'Create test file');
$this->assertFileExists($filepath);
return $filepath;
}
......
......@@ -71,10 +71,10 @@ protected function setUp(): void {
$this->image = File::create((array) current($image_files));
list(, $this->imageExtension) = explode('.', $this->image->getFilename());
$this->assertTrue(is_file($this->image->getFileUri()), "The image file we're going to upload exists.");
$this->assertFileExists($this->image->getFileUri());
$this->phpfile = current($this->drupalGetTestFiles('php'));
$this->assertTrue(is_file($this->phpfile->uri), 'The PHP file we are going to upload exists.');
$this->assertFileExists($this->phpfile->uri);
$this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
......@@ -143,7 +143,7 @@ public function testNormal() {
$this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
$this->assertRaw(t('You WIN!'));
$this->assertTrue(is_file('temporary://' . $dir . '/' . trim(\Drupal::service('file_system')->basename($image3_realpath))));
$this->assertFileExists('temporary://' . $dir . '/' . trim(\Drupal::service('file_system')->basename($image3_realpath)));
}
/**
......@@ -456,7 +456,7 @@ public function testErrorMessagesAreNotChanged() {
*/
public function testCombinedErrorMessages() {
$textfile = current($this->drupalGetTestFiles('text'));
$this->assertTrue(is_file($textfile->uri), 'The text file we are going to upload exists.');
$this->assertFileExists($textfile->uri);
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
......
......@@ -68,10 +68,10 @@ protected function setUp(): void {
$this->image = File::create((array) current($image_files));
list(, $this->imageExtension) = explode('.', $this->image->getFilename());
$this->assertTrue(is_file($this->image->getFileUri()), "The image file we're going to upload exists.");
$this->assertFileExists($this->image->getFileUri());
$this->phpfile = current($this->drupalGetTestFiles('php'));
$this->assertTrue(is_file($this->phpfile->uri), 'The PHP file we are going to upload exists.');
$this->assertFileExists($this->phpfile->uri);
$this->maxFidBefore = (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
......@@ -136,7 +136,7 @@ public function testNormal() {
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
$this->assertRaw(t('You WIN!'));
$this->assertTrue(is_file('temporary://' . $dir . '/' . trim(\Drupal::service('file_system')->basename($image3_realpath))));
$this->assertFileExists('temporary://' . $dir . '/' . trim(\Drupal::service('file_system')->basename($image3_realpath)));
}
/**
......
......@@ -19,7 +19,7 @@ public function testUnused() {
$file = $this->createFile();
// Check that deletion removes the file and database record.
$this->assertTrue(is_file($file->getFileUri()), 'File exists.');
$this->assertFileExists($file->getFileUri());
$file->delete();
$this->assertFileHooksCalled(['delete']);
$this->assertFalse(file_exists($file->getFileUri()), 'Test file has actually been deleted.');
......
......@@ -207,7 +207,7 @@ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
}
file_put_contents($filepath, $contents);
$this->assertTrue(is_file($filepath), t('The test file exists on the disk.'), 'Create test file');
$this->assertFileExists($filepath);
return $filepath;
}
......
......@@ -47,7 +47,7 @@ public function testFormStateValuesCleanAdvanced() {
$this->image = current($image_files);
// Check if the physical file is there.
$this->assertTrue(is_file($this->image->uri), "The image file we're going to upload exists.");
$this->assertFileExists($this->image->uri);
// "Browse" for the desired file.
$edit = ['files[image]' => \Drupal::service('file_system')->realpath($this->image->uri)];
......
......@@ -38,7 +38,7 @@ public function testFileRetrieving() {
$encoded_filename = rawurlencode($filename);
$this->assertEqual($retrieved_file, 'public://' . $encoded_filename, 'Sane path for downloaded file returned (public:// scheme).');
$this->assertTrue(is_file($retrieved_file), 'Downloaded file does exist (public:// scheme).');
$this->assertFileExists($retrieved_file);
$this->assertEqual(filesize($retrieved_file), 7, 'File size of downloaded file is correct (public:// scheme).');
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
......@@ -48,7 +48,7 @@ public function testFileRetrieving() {
$file_system->mkdir($targetdir = 'temporary://' . $this->randomMachineName());
$retrieved_file = system_retrieve_file($url, $targetdir);
$this->assertEqual($retrieved_file, "$targetdir/$encoded_filename", 'Sane path for downloaded file returned (temporary:// scheme).');
$this->assertTrue(is_file($retrieved_file), 'Downloaded file does exist (temporary:// scheme).');
$this->assertFileExists($retrieved_file);
$this->assertEqual(filesize($retrieved_file), 7, 'File size of downloaded file is correct (temporary:// scheme).');
$file_system->delete($retrieved_file);
......
......@@ -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->assertFalse(is_file($file->getFileUri()), 'File was removed from the file system.');
$this->assertFileNotExists($file->getFileUri(), 'File was removed from the file system.');
}
/**
......
......@@ -173,7 +173,7 @@ protected function verifyLibraryFilesExist($library_definitions) {
$path = $this->root . '/' . $file;
// Only check and assert each file path once.
if (!isset($this->pathsChecked[$path])) {
$this->assertTrue(is_file($path), "$file file referenced from the $extension/$library_name library exists.");
$this->assertFileExists($path, "$file file referenced from the $extension/$library_name library does not exist.");
$this->pathsChecked[$path] = TRUE;
}
}
......
......@@ -110,15 +110,15 @@ public function testFileCheckDirectoryHandling() {
// Remove .htaccess file to then test that it gets re-created.
@$file_system->unlink($default_scheme . '://.htaccess');
$this->assertFalse(is_file($default_scheme . '://.htaccess'), 'Successfully removed the .htaccess file in the files directory.', 'File');
$this->assertFileNotExists($default_scheme . '://.htaccess');
$this->container->get('file.htaccess_writer')->ensure();
$this->assertTrue(is_file($default_scheme . '://.htaccess'), 'Successfully re-created the .htaccess file in the files directory.', 'File');
$this->assertFileExists($default_scheme . '://.htaccess');
// Remove .htaccess file again to test that it is re-created by a cron run.
@$file_system->unlink($default_scheme . '://.htaccess');
$this->assertFalse(is_file($default_scheme . '://.htaccess'), 'Successfully removed the .htaccess file in the files directory.', 'File');
$this->assertFileNotExists($default_scheme . '://.htaccess');
system_cron();
$this->assertTrue(is_file($default_scheme . '://.htaccess'), 'Successfully re-created the .htaccess file in the files directory.', 'File');
$this->assertFileExists($default_scheme . '://.htaccess');
// Verify contents of .htaccess file.
$file = file_get_contents($default_scheme . '://.htaccess');
......
......@@ -196,7 +196,7 @@ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) {
}
file_put_contents($filepath, $contents);
$this->assertTrue(is_file($filepath), t('The test file exists on the disk.'), 'Create test file');
$this->assertFileExists($filepath);
return $filepath;
}
......
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