Commit 811bcb96 authored by catch's avatar catch
Browse files

Issue #3131088 by Spokje, longwave: Replace assertions involving calls to...

Issue #3131088 by Spokje, longwave: Replace assertions involving calls to file_exists with assertFileExists()/assertFileNotExists() or assertDirectoryExists()/assertDirectoryNotExists()

(cherry picked from commit 222e1044)
parent 58a7082b
......@@ -33,8 +33,8 @@ public function testNormal() {
$this->assertDifferentFile($source, $result);
$this->assertEqual($result->getFileUri(), $desired_uri, 'The copied file entity has the desired filepath.');
$this->assertTrue(file_exists($source->getFileUri()), 'The original file still exists.');
$this->assertTrue(file_exists($result->getFileUri()), 'The copied file exists.');
$this->assertFileExists($source->getFileUri());
$this->assertFileExists($result->getFileUri());
// Reload the file from the database and check that the changes were
// actually saved.
......
......@@ -22,7 +22,7 @@ public function testUnused() {
$this->assertFileExists($file->getFileUri());
$file->delete();
$this->assertFileHooksCalled(['delete']);
$this->assertFalse(file_exists($file->getFileUri()), 'Test file has actually been deleted.');
$this->assertFileNotExists($file->getFileUri());
$this->assertNull(File::load($file->id()), 'File was removed from the database.');
}
......@@ -43,7 +43,7 @@ public function testInUse() {
$file_usage->delete($file, 'testing', 'test', 1);
$usage = $file_usage->listUsage($file);
$this->assertEqual($usage['testing']['test'], [1 => 1], 'Test file is still in use.');
$this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.');
$this->assertFileExists($file->getFileUri());
$this->assertNotEmpty(File::load($file->id()), 'File still exists in the database.');
// Clear out the call to hook_file_load().
......@@ -53,7 +53,7 @@ public function testInUse() {
$usage = $file_usage->listUsage($file);
$this->assertFileHooksCalled(['load', 'update']);
$this->assertTrue(empty($usage), 'File usage data was removed.');
$this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.');
$this->assertFileExists($file->getFileUri());
$file = File::load($file->id());
$this->assertNotEmpty($file, 'File still exists in the database.');
$this->assertTrue($file->isTemporary(), 'File is temporary.');
......@@ -73,7 +73,7 @@ public function testInUse() {
// file_cron() loads
$this->assertFileHooksCalled(['delete']);
$this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.');
$this->assertFileNotExists($file->getFileUri());
$this->assertNull(File::load($file->id()), 'File was removed from the database.');
}
......@@ -84,7 +84,7 @@ public function testCronDeleteNonExistingTemporary() {
$file = $this->createFile();
// Delete the file, but leave it in the file_managed table.
\Drupal::service('file_system')->delete($file->getFileUri());
$this->assertFalse(file_exists($file->getFileUri()), 'File is deleted from the filesystem.');
$this->assertFileNotExists($file->getFileUri());
$this->assertInstanceOf(File::class, File::load($file->id()));
// Call file_cron() to clean up the file. Make sure the changed timestamp
......
......@@ -27,7 +27,7 @@ public function testNormal() {
// Check the return status and that the contents changed.
$this->assertNotFalse($result, 'File moved successfully.');
$this->assertFalse(file_exists($source->getFileUri()));
$this->assertFileNotExists($source->getFileUri());
$this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of file correctly written.');
// Check that the correct hooks were called.
......@@ -59,7 +59,7 @@ public function testExistingRename() {
// Check the return status and that the contents changed.
$this->assertNotFalse($result, 'File moved successfully.');
$this->assertFalse(file_exists($source->getFileUri()));
$this->assertFileNotExists($source->getFileUri());
$this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of file correctly written.');
// Check that the correct hooks were called.
......@@ -94,7 +94,7 @@ public function testExistingReplace() {
// Look at the results.
$this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of file were overwritten.');
$this->assertFalse(file_exists($source->getFileUri()));
$this->assertFileNotExists($source->getFileUri());
$this->assertNotEmpty($result, 'File moved successfully.');
// Check that the correct hooks were called.
......@@ -147,7 +147,7 @@ public function testExistingError() {
// Check the return status and that the contents did not change.
$this->assertFalse($result, 'File move failed.');
$this->assertTrue(file_exists($source->getFileUri()));
$this->assertFileExists($source->getFileUri());
$this->assertEqual($contents, file_get_contents($target->getFileUri()), 'Contents of file were not altered.');
// Check that no hooks were called while failing.
......
......@@ -163,7 +163,7 @@ public function createTempFiles() {
])
->condition('fid', $temp_old->id())
->execute();
$this->assertTrue(file_exists($temp_old->getFileUri()), 'Old temp file was created correctly.');
$this->assertFileExists($temp_old->getFileUri());
// Temporary file that is new.
$temp_new = file_save_data('');
......@@ -171,7 +171,7 @@ public function createTempFiles() {
->fields(['status' => 0])
->condition('fid', $temp_new->id())
->execute();
$this->assertTrue(file_exists($temp_new->getFileUri()), 'New temp file was created correctly.');
$this->assertFileExists($temp_new->getFileUri());
// Permanent file that is old.
$perm_old = file_save_data('');
......@@ -179,11 +179,11 @@ public function createTempFiles() {
->fields(['changed' => REQUEST_TIME - $this->config('system.file')->get('temporary_maximum_age') - 1])
->condition('fid', $temp_old->id())
->execute();
$this->assertTrue(file_exists($perm_old->getFileUri()), 'Old permanent file was created correctly.');
$this->assertFileExists($perm_old->getFileUri());
// Permanent file that is new.
$perm_new = file_save_data('');
$this->assertTrue(file_exists($perm_new->getFileUri()), 'New permanent file was created correctly.');
$this->assertFileExists($perm_new->getFileUri());
return [$temp_old, $temp_new, $perm_old, $perm_new];
}
......@@ -195,10 +195,10 @@ public function testTempFileCleanupDefault() {
// Run cron and then ensure that only the old, temp file was deleted.
$this->container->get('cron')->run();
$this->assertFalse(file_exists($temp_old->getFileUri()), 'Old temp file was correctly removed.');
$this->assertTrue(file_exists($temp_new->getFileUri()), 'New temp file was correctly ignored.');
$this->assertTrue(file_exists($perm_old->getFileUri()), 'Old permanent file was correctly ignored.');
$this->assertTrue(file_exists($perm_new->getFileUri()), 'New permanent file was correctly ignored.');
$this->assertFileNotExists($temp_old->getFileUri());
$this->assertFileExists($temp_new->getFileUri());
$this->assertFileExists($perm_old->getFileUri());
$this->assertFileExists($perm_new->getFileUri());
}
/**
......@@ -214,10 +214,10 @@ public function testTempFileNoCleanup() {
// Run cron and then ensure that no file was deleted.
$this->container->get('cron')->run();
$this->assertTrue(file_exists($temp_old->getFileUri()), 'Old temp file was correctly ignored.');
$this->assertTrue(file_exists($temp_new->getFileUri()), 'New temp file was correctly ignored.');
$this->assertTrue(file_exists($perm_old->getFileUri()), 'Old permanent file was correctly ignored.');
$this->assertTrue(file_exists($perm_new->getFileUri()), 'New permanent file was correctly ignored.');
$this->assertFileExists($temp_old->getFileUri());
$this->assertFileExists($temp_new->getFileUri());
$this->assertFileExists($perm_old->getFileUri());
$this->assertFileExists($perm_new->getFileUri());
}
/**
......@@ -233,10 +233,10 @@ public function testTempFileCustomCleanup() {
// Run cron and then ensure that more files were deleted.
$this->container->get('cron')->run();
$this->assertTrue(file_exists($temp_old->getFileUri()), 'Old temp file was correctly ignored.');
$this->assertTrue(file_exists($temp_new->getFileUri()), 'New temp file was correctly ignored.');
$this->assertTrue(file_exists($perm_old->getFileUri()), 'Old permanent file was correctly ignored.');
$this->assertTrue(file_exists($perm_new->getFileUri()), 'New permanent file was correctly ignored.');
$this->assertFileExists($temp_old->getFileUri());
$this->assertFileExists($temp_new->getFileUri());
$this->assertFileExists($perm_old->getFileUri());
$this->assertFileExists($perm_new->getFileUri());
}
/**
......
......@@ -56,11 +56,11 @@ public function testFileValidateExtensions() {
* This ensures a specific file is actually an image.
*/
public function testFileValidateIsImage() {
$this->assertTrue(file_exists($this->image->getFileUri()), 'The image being tested exists.', 'File');
$this->assertFileExists($this->image->getFileUri());
$errors = file_validate_is_image($this->image);
$this->assertEqual(count($errors), 0, 'No error reported for our image file.', 'File');
$this->assertTrue(file_exists($this->nonImage->getFileUri()), 'The non-image being tested exists.', 'File');
$this->assertFileExists($this->nonImage->getFileUri());
$errors = file_validate_is_image($this->nonImage);
$this->assertEqual(count($errors), 1, 'An error reported for our non-image file.', 'File');
}
......
......@@ -47,7 +47,7 @@ public function testNormal() {
$style->createDerivative($original_uri, $derivative_uri);
// Check if derivative image exists.
$this->assertTrue(file_exists($derivative_uri), 'Make sure derivative image is generated successfully.');
$this->assertFileExists($derivative_uri);
// Clone the object so we don't have to worry about the function changing
// our reference copy.
......@@ -55,10 +55,10 @@ public function testNormal() {
$result = file_move(clone $file, $desired_filepath, FileSystemInterface::EXISTS_ERROR);
// Check if image has been moved.
$this->assertTrue(file_exists($result->getFileUri()), 'Make sure image is moved successfully.');
$this->assertFileExists($result->getFileUri());
// Check if derivative image has been flushed.
$this->assertFalse(file_exists($derivative_uri), 'Make sure derivative image has been flushed.');
$this->assertFileNotExists($derivative_uri);
}
}
......@@ -78,10 +78,10 @@ public function testImageDimensions() {
$style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="120" height="60" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
$this->assertEqual($image_file->getWidth(), 120);
$this->assertEqual($image_file->getHeight(), 60);
......@@ -99,10 +99,10 @@ public function testImageDimensions() {
$style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="60" height="120" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
$this->assertEqual($image_file->getWidth(), 60);
$this->assertEqual($image_file->getHeight(), 120);
......@@ -121,10 +121,10 @@ public function testImageDimensions() {
$style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="45" height="90" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
$this->assertEqual($image_file->getWidth(), 45);
$this->assertEqual($image_file->getHeight(), 90);
......@@ -143,10 +143,10 @@ public function testImageDimensions() {
$style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="45" height="90" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
$this->assertEqual($image_file->getWidth(), 45);
$this->assertEqual($image_file->getHeight(), 90);
......@@ -161,10 +161,10 @@ public function testImageDimensions() {
$style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="45" height="90" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
$this->assertEqual($image_file->getWidth(), 45);
$this->assertEqual($image_file->getHeight(), 90);
......@@ -182,10 +182,10 @@ public function testImageDimensions() {
$style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
// Add a crop effect.
$effect = [
......@@ -201,10 +201,10 @@ public function testImageDimensions() {
$style->addImageEffect($effect);
$style->save();
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="30" height="30" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
$this->assertEqual($image_file->getWidth(), 30);
$this->assertEqual($image_file->getHeight(), 30);
......@@ -224,10 +224,10 @@ public function testImageDimensions() {
// @todo Uncomment this once
// https://www.drupal.org/project/drupal/issues/2670966 is resolved.
// $this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="41" height="41" alt="" class="image-style-test" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
// @todo Uncomment this once
// https://www.drupal.org/project/drupal/issues/2670966 is resolved.
......@@ -268,10 +268,10 @@ public function testImageDimensions() {
$generated_uri = 'public://styles/test_uri/public/' . $file_system->basename($original_uri);
$url = file_url_transform_relative($style->buildUrl($original_uri));
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="100" height="100" alt="" class="image-style-test-uri" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
$this->assertEqual($image_file->getWidth(), 100);
$this->assertEqual($image_file->getHeight(), 100);
......@@ -282,10 +282,10 @@ public function testImageDimensions() {
$url = file_url_transform_relative($style->buildUrl($original_uri));
$variables['#uri'] = $original_uri;
$this->assertEqual($this->getImageTag($variables), '<img src="' . $url . '" width="50" height="50" alt="" class="image-style-test-uri" />');
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$this->drupalGet($this->getAbsoluteUrl($url));
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
$image_file = $image_factory->get($generated_uri);
$this->assertEqual($image_file->getWidth(), 50);
$this->assertEqual($image_file->getHeight(), 50);
......
......@@ -38,7 +38,7 @@ public function testValid() {
// Create a node with a valid image.
$node = $this->uploadNodeImage($image_files[0], $field_name, 'article', $alt);
$this->assertTrue(file_exists($expected_path . '/' . $image_files[0]->filename));
$this->assertFileExists($expected_path . '/' . $image_files[0]->filename);
// Remove the image.
$this->drupalPostForm('node/' . $node . '/edit', [], t('Remove'));
......@@ -61,7 +61,7 @@ public function testValid() {
'files[' . $field_name . '_0]' => $file_system->realpath($zero_size_image->uri),
];
$this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
$this->assertFalse(file_exists($expected_path . '/' . $zero_size_image->filename));
$this->assertFileNotExists($expected_path . '/' . $zero_size_image->filename);
// Try uploading an invalid image.
$invalid_image = $invalid_image_files['invalid-img-test.png'];
......@@ -69,7 +69,7 @@ public function testValid() {
'files[' . $field_name . '_0]' => $file_system->realpath($invalid_image->uri),
];
$this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
$this->assertFalse(file_exists($expected_path . '/' . $invalid_image->filename));
$this->assertFileNotExists($expected_path . '/' . $invalid_image->filename);
// Upload a valid image again.
$valid_image = $image_files[0];
......@@ -77,7 +77,7 @@ public function testValid() {
'files[' . $field_name . '_0]' => $file_system->realpath($valid_image->uri),
];
$this->drupalPostForm('node/' . $node . '/edit', $edit, t('Upload'));
$this->assertTrue(file_exists($expected_path . '/' . $valid_image->filename));
$this->assertFileExists($expected_path . '/' . $valid_image->filename);
}
/**
......
......@@ -164,7 +164,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
// Get the URL of a file that has not been generated and try to create it.
$generated_uri = $this->style->buildUri($original_uri);
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$generate_url = $this->style->buildUrl($original_uri, $clean_url);
// Make sure that language prefix is never added to the image style URL.
......@@ -203,7 +203,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
// Fetch the URL that generates the file.
$this->drupalGet($generate_url);
$this->assertResponse(200, 'Image was generated at the URL.');
$this->assertTrue(file_exists($generated_uri), 'Generated file does exist after we accessed it.');
$this->assertFileExists($generated_uri);
// assertRaw can't be used with string containing non UTF-8 chars.
$this->assertNotEmpty(file_get_contents($generated_uri), 'URL returns expected file.');
$image = $this->container->get('image.factory')->get($generated_uri);
......@@ -243,7 +243,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
$file_noaccess = array_shift($files);
$original_uri_noaccess = $file_system->copy($file_noaccess->uri, $scheme . '://', FileSystemInterface::EXISTS_RENAME);
$generated_uri_noaccess = $scheme . '://styles/' . $this->style->id() . '/' . $scheme . '/' . $file_system->basename($original_uri_noaccess);
$this->assertFalse(file_exists($generated_uri_noaccess), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri_noaccess);
$generate_url_noaccess = $this->style->buildUrl($original_uri_noaccess);
$this->drupalGet($generate_url_noaccess);
......@@ -291,7 +291,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
// is not present in the URL but that the image is still accessible.
$this->config('image.settings')->set('suppress_itok_output', TRUE)->save();
$generated_uri = $this->style->buildUri($original_uri);
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$this->assertFileNotExists($generated_uri);
$generate_url = $this->style->buildUrl($original_uri, $clean_url);
$this->assertStringNotContainsString(IMAGE_DERIVATIVE_TOKEN . '=', $generate_url, 'The security token does not appear in the image style URL.');
$this->drupalGet($generate_url);
......@@ -324,7 +324,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
// directories in the file system.
$directory = $scheme . '://styles/' . $this->style->id() . '/' . $scheme . '/' . $this->randomMachineName();
$this->drupalGet(file_create_url($directory . '/' . $this->randomString()));
$this->assertFalse(file_exists($directory), 'New directory was not created in the filesystem when requesting an unauthorized image.');
$this->assertDirectoryNotExists($directory);
}
}
......@@ -501,7 +501,7 @@ public function testFileUploadStrippedFilePath() {
// Check the actual file data. It should have been written to the configured
// directory, not /foobar/directory/example.txt.
$this->assertSame($this->testFileData, file_get_contents('public://foobar/example_2.txt'));
$this->assertFalse(file_exists('../../example_2.txt'));
$this->assertFileNotExists('../../example_2.txt');
// Check a path from the root. Extensions have to be empty to allow a file
// with no extension to pass validation.
......@@ -575,7 +575,7 @@ public function testFileUploadInvalidFileType() {
// Make sure that no file was saved.
$this->assertEmpty(File::load(1));
$this->assertFalse(file_exists('public://foobar/example.txt'));
$this->assertFileNotExists('public://foobar/example.txt');
}
/**
......@@ -598,7 +598,7 @@ public function testFileUploadLargerFileSize() {
// Make sure that no file was saved.
$this->assertEmpty(File::load(1));
$this->assertFalse(file_exists('public://foobar/example.txt'));
$this->assertFileNotExists('public://foobar/example.txt');
}
/**
......@@ -625,7 +625,7 @@ public function testFileUploadMaliciousExtension() {
// Override the expected filesize.
$expected['data']['attributes']['filesize'] = strlen($php_string);
$this->assertResponseData($expected, $response);
$this->assertTrue(file_exists('public://foobar/example.php.txt'));
$this->assertFileExists('public://foobar/example.php.txt');
// Add php as an allowed format. Allow insecure uploads still being FALSE
// should still not allow this. So it should still have a .txt extension
......@@ -639,8 +639,8 @@ public function testFileUploadMaliciousExtension() {
// Override the expected filesize.
$expected['data']['attributes']['filesize'] = strlen($php_string);
$this->assertResponseData($expected, $response);
$this->assertTrue(file_exists('public://foobar/example_2.php.txt'));
$this->assertFalse(file_exists('public://foobar/example_2.php'));
$this->assertFileExists('public://foobar/example_2.php.txt');
$this->assertFileNotExists('public://foobar/example_2.php');
// Allow .doc file uploads and ensure even a mis-configured apache will not
// fallback to php because the filename will be munged.
......@@ -656,8 +656,8 @@ public function testFileUploadMaliciousExtension() {
// The file mime should be 'application/msword'.
$expected['data']['attributes']['filemime'] = 'application/msword';
$this->assertResponseData($expected, $response);
$this->assertTrue(file_exists('public://foobar/example_3.php_.doc'));
$this->assertFalse(file_exists('public://foobar/example_3.php.doc'));
$this->assertFileExists('public://foobar/example_3.php_.doc');
$this->assertFileNotExists('public://foobar/example_3.php.doc');
// Now allow insecure uploads.
\Drupal::configFactory()
......@@ -675,7 +675,7 @@ public function testFileUploadMaliciousExtension() {
// The file mime should also now be PHP.
$expected['data']['attributes']['filemime'] = 'application/x-httpd-php';
$this->assertResponseData($expected, $response);
$this->assertTrue(file_exists('public://foobar/example_4.php'));
$this->assertFileExists('public://foobar/example_4.php');
}
/**
......@@ -695,7 +695,7 @@ public function testFileUploadNoExtensionSetting() {
$expected = $this->getExpectedDocument(1, 'example.txt', TRUE);
$this->assertResponseData($expected, $response);
$this->assertTrue(file_exists('public://foobar/example.txt'));
$this->assertFileExists('public://foobar/example.txt');
}
/**
......
......@@ -62,8 +62,8 @@ public function testUpdateImportSourceRemote() {
$result = locale_translation_download_source($source_file, 'translations://');
$this->assertEquals('translations://contrib_module_one-8.x-1.1.de._po', $result->uri);
$this->assertFalse(file_exists('translations://contrib_module_one-8.x-1.1.de_0._po'));
$this->assertTrue(file_exists('translations://contrib_module_one-8.x-1.1.de._po'));
$this->assertFileNotExists('translations://contrib_module_one-8.x-1.1.de_0._po');
$this->assertFileExists('translations://contrib_module_one-8.x-1.1.de._po');
$this->assertStringNotContainsString('__old_content__', file_get_contents('translations://contrib_module_one-8.x-1.1.de._po'));
}
......
......@@ -7,7 +7,6 @@
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Component\Render\FormattableMarkup;
/**
* Adds a new locale and translates its name. Checks the validation of
......@@ -266,13 +265,13 @@ public function testJavaScriptTranslation() {
$locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
$js_file = 'public://' . $config->get('javascript.directory') . '/' . $langcode . '_' . $locale_javascripts[$langcode] . '.js';
$this->assertTrue($result = file_exists($js_file), new FormattableMarkup('JavaScript file created: %file', ['%file' => $result ? $js_file : 'not found']));
$this->assertFileExists($js_file);
// Test JavaScript translation rebuilding.
\Drupal::service('file_system')->delete($js_file);
$this->assertTrue($result = !file_exists($js_file), new FormattableMarkup('JavaScript file deleted: %file', ['%file' => $result ? $js_file : 'found']));
$this->assertFileNotExists($js_file);
_locale_rebuild_js($langcode);
$this->assertTrue($result = file_exists($js_file), new FormattableMarkup('JavaScript file rebuilt: %file', ['%file' => $result ? $js_file : 'not found']));
$this->assertFileExists($js_file);
}
/**
......
......@@ -370,7 +370,7 @@ public function testFileUploadStrippedFilePath() {
// Check the actual file data. It should have been written to the configured
// directory, not /foobar/directory/example.txt.
$this->assertSame($this->testFileData, file_get_contents('public://foobar/example_2.txt'));
$this->assertFalse(file_exists('../../example_2.txt'));
$this->assertFileNotExists('../../example_2.txt');
// Check a path from the root. Extensions have to be empty to allow a file
// with no extension to pass validation.
......@@ -453,7 +453,7 @@ public function testFileUploadInvalidFileType() {
// Make sure that no file was saved.
$this->assertEmpty(File::load(1));
$this->assertFalse(file_exists('public://foobar/example.txt'));
$this->assertFileNotExists('public://foobar/example.txt');
}
/**
......@@ -479,7 +479,7 @@ public function testFileUploadLargerFileSize() {
// Make sure that no file was saved.
$this->assertEmpty(File::load(1));
$this->assertFalse(file_exists('public://foobar/example.txt'));
$this->assertFileNotExists('public://foobar/example.txt');
}
/**
......@@ -508,7 +508,7 @@ public function testFileUploadMaliciousExtension() {
// Override the expected filesize.
$expected['filesize'][0]['value'] = strlen($php_string);
$this->assertResponseData($expected, $response);
$this->assertTrue(file_exists('public://foobar/example.php.txt'));
$this->assertFileExists('public://foobar/example.php.txt');
// Add php as an allowed format. Allow insecure uploads still being FALSE
// should still not allow this. So it should still have a .txt extension
......@@ -522,8 +522,8 @@ public function testFileUploadMaliciousExtension() {
// Override the expected filesize.
$expected['filesize'][0]['value'] = strlen($php_string);
$this->assertResponseData($expected, $response);
$this->assertTrue(file_exists('public://foobar/example_2.php.txt'));