Commit 700a72fa authored by catch's avatar catch

Issue #1472946 by gnuget, andypost, mmrares, sidharthap, kiamlaluno,...

Issue #1472946 by gnuget, andypost, mmrares, sidharthap, kiamlaluno, Himanshu5050, dineshkumares, amit.drupal: Remove usages of deprecated function drupal_realpath() throughout core functions
parent 839d67fa
......@@ -1260,7 +1260,7 @@ function archiver_get_extensions() {
*/
function archiver_get_archiver($file) {
// Archivers can only work on local paths
$filepath = drupal_realpath($file);
$filepath = \Drupal::service('file_system')->realpath($file);
if (!is_file($filepath)) {
throw new Exception(t('Archivers can only operate on local files: %file not supported', ['%file' => $file]));
}
......
......@@ -462,8 +462,9 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
}
// Attempt to resolve the URIs. This is necessary in certain configurations
// (see above).
$real_source = drupal_realpath($source) ?: $source;
$real_destination = drupal_realpath($destination) ?: $destination;
$file_system = \Drupal::service('file_system');
$real_source = $file_system->realpath($source) ?: $source;
$real_destination = $file_system->realpath($destination) ?: $destination;
// Perform the copy operation.
if (!@copy($real_source, $real_destination)) {
\Drupal::logger('file')->error('The specified file %file could not be copied to %destination.', ['%file' => $source, '%destination' => $destination]);
......@@ -507,12 +508,13 @@ function file_unmanaged_copy($source, $destination = NULL, $replace = FILE_EXIST
function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_EXISTS_RENAME) {
$original_source = $source;
$logger = \Drupal::logger('file');
$file_system = \Drupal::service('file_system');
// Assert that the source file actually exists.
if (!file_exists($source)) {
// @todo Replace drupal_set_message() calls with exceptions instead.
drupal_set_message(t('The specified file %file could not be moved/copied because no file by that name exists. Please check that you supplied the correct filename.', ['%file' => $original_source]), 'error');
if (($realpath = drupal_realpath($original_source)) !== FALSE) {
if (($realpath = $file_system->realpath($original_source)) !== FALSE) {
$logger->notice('File %file (%realpath) could not be moved/copied because it does not exist.', ['%file' => $original_source, '%realpath' => $realpath]);
}
else {
......@@ -551,8 +553,8 @@ function file_unmanaged_prepare($source, &$destination = NULL, $replace = FILE_E
}
// Assert that the source and destination filenames are not the same.
$real_source = drupal_realpath($source);
$real_destination = drupal_realpath($destination);
$real_source = $file_system->realpath($source);
$real_destination = $file_system->realpath($destination);
if ($source == $destination || ($real_source !== FALSE) && ($real_source == $real_destination)) {
drupal_set_message(t('The specified file %file was not moved/copied because it would overwrite itself.', ['%file' => $source]), 'error');
$logger->notice('File %file could not be moved/copied because it would overwrite itself.', ['%file' => $source]);
......@@ -652,8 +654,9 @@ function file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXIST
}
// Attempt to resolve the URIs. This is necessary in certain configurations
// (see above) and can also permit fast moves across local schemes.
$real_source = drupal_realpath($source) ?: $source;
$real_destination = drupal_realpath($destination) ?: $destination;
$file_system = \Drupal::service('file_system');
$real_source = $file_system->realpath($source) ?: $source;
$real_destination = $file_system->realpath($destination) ?: $destination;
// Perform the move operation.
if (!@rename($real_source, $real_destination)) {
// Fall back to slow copy and unlink procedure. This is necessary for
......
......@@ -1379,7 +1379,7 @@ function install_download_translation(&$install_state) {
*/
function install_retrieve_file($uri, $destination) {
$parsed_url = parse_url($uri);
if (is_dir(drupal_realpath($destination))) {
if (is_dir(\Drupal::service('file_system')->realpath($destination))) {
// Prevent URIs with triple slashes when gluing parts together.
$path = str_replace('///', '//', "$destination/") . drupal_basename($parsed_url['path']);
}
......
......@@ -207,7 +207,8 @@ public function __get($name) {
*/
final protected function checkPath($path) {
$full_jail = $this->chroot . $this->jail;
$full_path = drupal_realpath(substr($this->chroot . $path, 0, strlen($full_jail)));
$full_path = \Drupal::service('file_system')
->realpath(substr($this->chroot . $path, 0, strlen($full_jail)));
$full_path = $this->fixRemotePath($full_path, FALSE);
if ($full_jail !== $full_path) {
throw new FileTransferException('@directory is outside of the @jail', NULL, ['@directory' => $path, '@jail' => $this->jail]);
......
......@@ -635,7 +635,7 @@ function _color_render_images($theme, &$info, &$paths, $palette) {
foreach ($info['slices'] as $file => $coord) {
list($x, $y, $width, $height) = $coord;
$base = drupal_basename($file);
$image = drupal_realpath($paths['target'] . $base);
$image = \Drupal::service('file_system')->realpath($paths['target'] . $base);
// Cut out slice.
if ($file == 'screenshot.png') {
......
......@@ -141,7 +141,7 @@ public function _testColor($theme, $test_values) {
$stylesheets = \Drupal::state()->get('drupal_css_cache_files') ?: [];
$stylesheet_content = '';
foreach ($stylesheets as $uri) {
$stylesheet_content .= implode("\n", file(drupal_realpath($uri)));
$stylesheet_content .= implode("\n", file(\Drupal::service('file_system')->realpath($uri)));
}
$this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
$config->set('css.preprocess', 0);
......
......@@ -60,7 +60,7 @@ public function testCommentPreview() {
// Add a user picture.
$image = current($this->drupalGetTestFiles('image'));
$user_edit['files[user_picture_0]'] = drupal_realpath($image->uri);
$user_edit['files[user_picture_0]'] = \Drupal::service('file_system')->realpath($image->uri);
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $user_edit, t('Save'));
// As the web user, fill in the comment form and preview the comment.
......
......@@ -45,7 +45,7 @@ public function testImport() {
// Attempt to upload a non-tar file.
$text_file = $this->getTestFiles('text')[0];
$edit = ['files[import_tarball]' => drupal_realpath($text_file->uri)];
$edit = ['files[import_tarball]' => \Drupal::service('file_system')->realpath($text_file->uri)];
$this->drupalPostForm('admin/config/development/configuration/full/import', $edit, t('Upload'));
$this->assertText(t('Could not extract the contents of the tar file'));
......
......@@ -188,7 +188,7 @@ protected function setMaxDimensions($width, $height) {
*/
protected function uploadImage($uri) {
$edit = [
'files[fid]' => drupal_realpath($uri),
'files[fid]' => \Drupal::service('file_system')->realpath($uri),
];
$this->drupalGet('editor/dialog/image/basic_html');
$this->drupalPostForm('editor/dialog/image/basic_html', $edit, t('Upload'));
......
......@@ -114,7 +114,7 @@ public function testFileUpload() {
$this->drupalLogin($user1);
$test_file = current($this->drupalGetTestFiles('text'));
$edit['files[file_field_0]'] = drupal_realpath($test_file->uri);
$edit['files[file_field_0]'] = \Drupal::service('file_system')->realpath($test_file->uri);
$this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload');
$this->assertResponse(200);
$edit = [
......
......@@ -140,7 +140,7 @@ function file_load($fid, $reset = FALSE) {
*/
function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
if (!file_valid_uri($destination)) {
if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) {
if (($realpath = \Drupal::service('file_system')->realpath($source->getFileUri())) !== FALSE) {
\Drupal::logger('file')->notice('File %file (%realpath) could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', ['%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination]);
}
else {
......@@ -215,7 +215,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E
*/
function file_move(FileInterface $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
if (!file_valid_uri($destination)) {
if (($realpath = drupal_realpath($source->getFileUri())) !== FALSE) {
if (($realpath = \Drupal::service('file_system')->realpath($source->getFileUri())) !== FALSE) {
\Drupal::logger('file')->notice('File %file (%realpath) could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', ['%file' => $source->getFileUri(), '%realpath' => $realpath, '%destination' => $destination]);
}
else {
......
......@@ -97,7 +97,7 @@ public function testNodeDisplay() {
// Test that fields appear as expected after during the preview.
// Add a second file.
$name = 'files[' . $field_name . '_1][]';
$edit[$name] = drupal_realpath($test_file->getFileUri());
$edit[$name] = \Drupal::service('file_system')->realpath($test_file->getFileUri());
// Uncheck the display checkboxes and go to the preview.
$edit[$field_name . '[0][display]'] = FALSE;
......@@ -166,7 +166,7 @@ public function testDescToggle() {
$title = $this->randomString();
$edit = [
'title[0][value]' => $title,
'files[field_' . $field_name . '_0]' => drupal_realpath($file->uri),
'files[field_' . $field_name . '_0]' => \Drupal::service('file_system')->realpath($file->uri),
];
$this->drupalPostForm('node/add/' . $type_name, $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($title);
......
......@@ -251,7 +251,7 @@ public function removeNodeFile($nid, $new_revision = TRUE) {
*/
public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) {
$edit = [
'files[' . $field_name . '_0]' => drupal_realpath($file->getFileUri()),
'files[' . $field_name . '_0]' => \Drupal::service('file_system')->realpath($file->getFileUri()),
'revision' => (string) (int) $new_revision,
];
......
......@@ -160,7 +160,7 @@ public function testMultiValuedWidget() {
$this->drupalGet("node/add/$type_name");
foreach ([$field_name2, $field_name] as $each_field_name) {
for ($delta = 0; $delta < 3; $delta++) {
$edit = ['files[' . $each_field_name . '_' . $delta . '][]' => drupal_realpath($test_file->getFileUri())];
$edit = ['files[' . $each_field_name . '_' . $delta . '][]' => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
// If the Upload button doesn't exist, drupalPostForm() will automatically
// fail with an assertion message.
$this->drupalPostForm(NULL, $edit, t('Upload'));
......@@ -373,7 +373,7 @@ public function testPrivateFileComment() {
// Add a comment with a file.
$text_file = $this->getTestFile('text');
$edit = [
'files[field_' . $name . '_' . 0 . ']' => drupal_realpath($text_file->getFileUri()),
'files[field_' . $name . '_' . 0 . ']' => \Drupal::service('file_system')->realpath($text_file->getFileUri()),
'comment_body[0][value]' => $comment_body = $this->randomMachineName(),
];
$this->drupalPostForm('node/' . $node->id(), $edit, t('Save'));
......@@ -429,7 +429,7 @@ public function testWidgetValidation() {
$name = 'files[' . $field_name . '_0]';
// Upload file with incorrect extension, check for validation error.
$edit[$name] = drupal_realpath($test_file_image->getFileUri());
$edit[$name] = \Drupal::service('file_system')->realpath($test_file_image->getFileUri());
switch ($type) {
case 'nojs':
$this->drupalPostForm(NULL, $edit, t('Upload'));
......@@ -443,7 +443,7 @@ public function testWidgetValidation() {
$this->assertRaw($error_message, t('Validation error when file with wrong extension uploaded (JSMode=%type).', ['%type' => $type]));
// Upload file with correct extension, check that error message is removed.
$edit[$name] = drupal_realpath($test_file_text->getFileUri());
$edit[$name] = \Drupal::service('file_system')->realpath($test_file_text->getFileUri());
switch ($type) {
case 'nojs':
$this->drupalPostForm(NULL, $edit, t('Upload'));
......
......@@ -96,7 +96,7 @@ public function testFileListingPages() {
$file = $this->getTestFile('image');
$edit = [
'files[file_0]' => drupal_realpath($file->getFileUri()),
'files[file_0]' => \Drupal::service('file_system')->realpath($file->getFileUri()),
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$node = Node::load($node->id());
......
......@@ -36,7 +36,7 @@ public function testManagedFile() {
// was not saved.
$last_fid_prior = $this->getLastFileId();
$edit = [
$file_field_name => drupal_realpath($test_file->getFileUri()),
$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri()),
'form_token' => 'invalid token',
];
$this->drupalPostForm($path, $edit, t('Save'));
......@@ -46,7 +46,7 @@ public function testManagedFile() {
// Submit a new file, without using the Upload button.
$last_fid_prior = $this->getLastFileId();
$edit = [$file_field_name => drupal_realpath($test_file->getFileUri())];
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
$this->drupalPostForm($path, $edit, t('Save'));
$last_fid = $this->getLastFileId();
$this->assertTrue($last_fid > $last_fid_prior, 'New file got saved.');
......@@ -61,7 +61,7 @@ public function testManagedFile() {
// Upload, then Submit.
$last_fid_prior = $this->getLastFileId();
$this->drupalGet($path);
$edit = [$file_field_name => drupal_realpath($test_file->getFileUri())];
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
if ($ajax) {
$this->drupalPostAjaxForm(NULL, $edit, $input_base_name . '_upload_button');
}
......@@ -92,7 +92,7 @@ public function testManagedFile() {
// Upload, then Remove, then Submit.
$this->drupalGet($path);
$edit = [$file_field_name => drupal_realpath($test_file->getFileUri())];
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
if ($ajax) {
$this->drupalPostAjaxForm(NULL, $edit, $input_base_name . '_upload_button');
}
......@@ -120,7 +120,7 @@ public function testManagedFile() {
// The multiple file upload has additional conditions that need checking.
$path = 'file/test/1/1/1';
$edit = ['files[nested_file][]' => drupal_realpath($test_file->getFileUri())];
$edit = ['files[nested_file][]' => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
$fid_list = [];
$this->drupalGet($path);
......@@ -158,7 +158,7 @@ public function testManagedFileRemoved() {
$test_file = $this->getTestFile('text');
$file_field_name = 'files[nested_file][]';
$edit = [$file_field_name => drupal_realpath($test_file->getFileUri())];
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
$this->drupalPostForm(NULL, $edit, t('Upload'));
$fid = $this->getLastFileId();
......@@ -179,7 +179,7 @@ public function testFileRemovedFromDisk() {
$test_file = $this->getTestFile('text');
$file_field_name = 'files[nested_file][]';
$edit = [$file_field_name => drupal_realpath($test_file->getFileUri())];
$edit = [$file_field_name => \Drupal::service('file_system')->realpath($test_file->getFileUri())];
$this->drupalPostForm(NULL, $edit, t('Upload'));
$this->drupalPostForm(NULL, [], t('Save'));
......
......@@ -91,7 +91,7 @@ public function testSyncedFiles() {
// Edit the node to upload a file.
$edit = [];
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[0]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('text')[0]->uri);
$this->drupalPostForm('node/' . $default_language_node->id() . '/edit', $edit, t('Save'));
$first_fid = $this->getLastFileId();
......@@ -102,7 +102,7 @@ public function testSyncedFiles() {
$edit = [];
$edit['title[0][value]'] = 'Bill Murray';
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[1]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('text')[1]->uri);
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
// This inspects the HTML after the post of the translation, the file
// should be displayed on the original node.
......@@ -128,7 +128,7 @@ public function testSyncedFiles() {
$edit = [];
$edit['title[0][value]'] = 'Scarlett Johansson';
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[2]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('text')[2]->uri);
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
$third_fid = $this->getLastFileId();
......@@ -156,7 +156,7 @@ public function testSyncedFiles() {
$edit = [];
$edit['title[0][value]'] = 'David Bowie';
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[3]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('text')[3]->uri);
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
$replaced_second_fid = $this->getLastFileId();
......
......@@ -38,6 +38,8 @@ protected function setUp() {
*/
public function testPrivateFile() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$type_name = 'article';
$field_name = strtolower($this->randomMachineName());
$this->createFileField($field_name, 'node', $type_name, ['uri_scheme' => 'private']);
......@@ -128,7 +130,7 @@ public function testPrivateFile() {
);
$test_file = $this->getTestFile('text');
$this->drupalGet('node/add/' . $type_name);
$edit = ['files[' . $field_name . '_0]' => drupal_realpath($test_file->getFileUri())];
$edit = ['files[' . $field_name . '_0]' => $file_system->realpath($test_file->getFileUri())];
$this->drupalPostForm(NULL, $edit, t('Upload'));
/** @var \Drupal\file\FileStorageInterface $file_storage */
$file_storage = $this->container->get('entity.manager')->getStorage('file');
......@@ -155,7 +157,7 @@ public function testPrivateFile() {
$this->drupalGet('node/add/' . $type_name);
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['files[' . $field_name . '_0]'] = drupal_realpath($test_file->getFileUri());
$edit['files[' . $field_name . '_0]'] = $file_system->realpath($test_file->getFileUri());
$this->drupalPostForm(NULL, $edit, t('Save'));
$new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$file_id = $new_node->{$field_name}->target_id;
......@@ -184,7 +186,7 @@ public function testPrivateFile() {
$this->drupalGet('node/add/' . $type_name);
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['files[' . $field_name . '_0]'] = drupal_realpath($test_file->getFileUri());
$edit['files[' . $field_name . '_0]'] = $file_system->realpath($test_file->getFileUri());
$this->drupalPostForm(NULL, $edit, t('Save'));
$new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$file = File::load($new_node->{$field_name}->target_id);
......@@ -209,7 +211,7 @@ public function testPrivateFile() {
$this->drupalGet('node/add/' . $type_name);
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['files[' . $field_name . '_0]'] = drupal_realpath($test_file->getFileUri());
$edit['files[' . $field_name . '_0]'] = $file_system->realpath($test_file->getFileUri());
$this->drupalPostForm(NULL, $edit, t('Save'));
$new_node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$new_node->setPublished(FALSE);
......
......@@ -80,7 +80,7 @@ public function testPrivateLanguageFile() {
// Edit the node to upload a file.
$edit = [];
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[0]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('text')[0]->uri);
$this->drupalPostForm('node/' . $default_language_node->id() . '/edit', $edit, t('Save'));
$last_fid_prior = $this->getLastFileId();
......@@ -105,7 +105,7 @@ public function testPrivateLanguageFile() {
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('text')[1]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('text')[1]->uri);
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
$last_fid = $this->getLastFileId();
......
......@@ -60,7 +60,7 @@ protected function setUp() {
// Upload with replace to guarantee there's something there.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
......@@ -88,7 +88,7 @@ public function testNormal() {
// Upload a second file.
$image2 = current($this->drupalGetTestFiles('image'));
$edit = ['files[file_test_upload]' => drupal_realpath($image2->uri)];
$edit = ['files[file_test_upload]' => \Drupal::service('file_system')->realpath($image2->uri)];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
$this->assertRaw(t('You WIN!'));
......@@ -109,7 +109,7 @@ public function testNormal() {
// Upload a third file to a subdirectory.
$image3 = current($this->drupalGetTestFiles('image'));
$image3_realpath = drupal_realpath($image3->uri);
$image3_realpath = \Drupal::service('file_system')->realpath($image3->uri);
$dir = $this->randomMachineName();
$edit = [
'files[file_test_upload]' => $image3_realpath,
......@@ -132,7 +132,7 @@ public function testHandleExtension() {
$extensions = 'foo';
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
'extensions' => $extensions,
];
......@@ -152,7 +152,7 @@ public function testHandleExtension() {
// Now tell file_save_upload() to allow the extension of our test image.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
'extensions' => $extensions,
];
......@@ -170,7 +170,7 @@ public function testHandleExtension() {
// Now tell file_save_upload() to allow any extension.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
'allow_all_extensions' => TRUE,
];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
......@@ -191,7 +191,7 @@ public function testHandleDangerousFile() {
// safety. Also check to make sure its MIME type was changed.
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => drupal_realpath($this->phpfile->uri),
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->phpfile->uri),
'is_image_file' => FALSE,
'extensions' => 'php',
];
......@@ -238,7 +238,7 @@ public function testHandleFileMunge() {
$extensions = $this->imageExtension;
$edit = [
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
'extensions' => $extensions,
];
......@@ -260,7 +260,7 @@ public function testHandleFileMunge() {
file_test_reset();
$edit = [
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri()),
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri()),
'allow_all_extensions' => TRUE,
];
......@@ -280,7 +280,7 @@ public function testHandleFileMunge() {
public function testExistingRename() {
$edit = [
'file_test_replace' => FILE_EXISTS_RENAME,
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri())
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri())
];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
......@@ -296,7 +296,7 @@ public function testExistingRename() {
public function testExistingReplace() {
$edit = [
'file_test_replace' => FILE_EXISTS_REPLACE,
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri())
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri())
];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
......@@ -312,7 +312,7 @@ public function testExistingReplace() {
public function testExistingError() {
$edit = [
'file_test_replace' => FILE_EXISTS_ERROR,
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri())
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri())
];
$this->drupalPostForm('file-test/upload', $edit, t('Submit'));
$this->assertResponse(200, 'Received a 200 response for posted test file.');
......@@ -341,7 +341,7 @@ public function testDrupalMovingUploadedFileError() {
$edit = [
'file_subdir' => $test_directory,
'files[file_test_upload]' => drupal_realpath($this->image->getFileUri())
'files[file_test_upload]' => \Drupal::service('file_system')->realpath($this->image->getFileUri())
];
\Drupal::state()->set('file_test.disable_error_collection', TRUE);
......
......@@ -248,7 +248,7 @@ public function removeNodeFile($nid, $new_revision = TRUE) {
*/
public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) {
$edit = [
'files[' . $field_name . '_0]' => drupal_realpath($file->getFileUri()),
'files[' . $field_name . '_0]' => \Drupal::service('file_system')->realpath($file->getFileUri()),
'revision' => (string) (int) $new_revision,
];
......
......@@ -345,7 +345,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
$tmp_file = drupal_tempnam('temporary://', 'generateImage_');
$destination = $tmp_file . '.' . $extension;
file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY);
if ($path = $random->image(drupal_realpath($destination), $min_resolution, $max_resolution)) {
if ($path = $random->image(\Drupal::service('file_system')->realpath($destination), $min_resolution, $max_resolution)) {
$image = File::create();
$image->setFileUri($path);
$image->setOwnerId(\Drupal::currentUser()->id());
......
......@@ -305,7 +305,7 @@ public function testDefaultImages() {
);
$non_image = $this->drupalGetTestFiles('text');
$this->drupalPostForm(NULL, ['files[settings_default_image_uuid]' => drupal_realpath($non_image[0]->uri)], t("Upload"));
$this->drupalPostForm(NULL, ['files[settings_default_image_uuid]' => \Drupal::service('file_system')->realpath($non_image[0]->uri)], t("Upload"));
$this->assertText('The specified file text-0.txt could not be uploaded.');
$this->assertText('Only files with the following extensions are allowed: png gif jpg jpeg.');
......
......@@ -312,7 +312,7 @@ public function testImageFieldSettings() {
// @see FileWidget::formMultipleElements().
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/storage', ['cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED], t('Save field settings'));
$edit = [
'files[' . $field_name . '_1][]' => drupal_realpath($test_image->uri),
'files[' . $field_name . '_1][]' => \Drupal::service('file_system')->realpath($test_image->uri),
];
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Add the required alt text.
......@@ -322,7 +322,7 @@ public function testImageFieldSettings() {
// Assert ImageWidget::process() calls FieldWidget::process().
$this->drupalGet('node/' . $node->id() . '/edit');
$edit = [
'files[' . $field_name . '_2][]' => drupal_realpath($test_image->uri),
'files[' . $field_name . '_2][]' => \Drupal::service('file_system')->realpath($test_image->uri),
];
$this->drupalPostAjaxForm(NULL, $edit, $field_name . '_2_upload_button');
$this->assertNoRaw('<input multiple type="file" id="edit-' . strtr($field_name, '_', '-') . '-2-upload" name="files[' . $field_name . '_2][]" size="22" class="js-form-file form-file">');
......@@ -357,7 +357,7 @@ public function testImageFieldDefaultImage() {
$title = $this->randomString(1024);
$edit = [
// Get the path of the 'image-test.png' file.
'files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri),
'files[settings_default_image_uuid]' => \Drupal::service('file_system')->realpath($images[0]->uri),
'settings[default_image][alt]' => $alt,
'settings[default_image][title]' => $title,
];
......@@ -426,7 +426,7 @@ public function testImageFieldDefaultImage() {
// Add a default image to the new field.
$edit = [
// Get the path of the 'image-test.gif' file.
'files[settings_default_image_uuid]' => drupal_realpath($images[2]->uri),
'files[settings_default_image_uuid]' => \Drupal::service('file_system')->realpath($images[2]->uri),
'settings[default_image][alt]' => $alt,
'settings[default_image][title]' => $title,
];
......
......@@ -69,7 +69,7 @@ public function previewNodeImage($image, $field_name, $type) {
$edit = [
'title[0][value]' => $this->randomMachineName(),
];
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
$this->drupalPostForm('node/add/' . $type, $edit, t('Preview'));
}
......@@ -89,7 +89,7 @@ public function uploadNodeImage($image, $field_name, $type, $alt = '') {
$edit = [
'title[0][value]' => $this->randomMachineName(),
];
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
$this->drupalPostForm('node/add/' . $type, $edit, t('Save'));
if ($alt) {
// Add alt text.
......
......@@ -95,7 +95,7 @@ public function testSyncedImages() {
// Edit the node to upload a file.
$edit = [];
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[0]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[0]->uri);
$this->drupalPostForm('node/' . $default_language_node->id() . '/edit', $edit, t('Save'));
$edit = [$this->fieldName . '[0][alt]' => 'Lost in translation image', $this->fieldName . '[0][title]' => 'Lost in translation image title'];
$this->drupalPostForm(NULL, $edit, t('Save'));
......@@ -108,7 +108,7 @@ public function testSyncedImages() {
$edit = [];
$edit['title[0][value]'] = 'Scarlett Johansson';
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[1]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[1]->uri);
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
$edit = [$this->fieldName . '[0][alt]' => 'Scarlett Johansson image', $this->fieldName . '[0][title]' => 'Scarlett Johansson image title'];
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
......@@ -140,7 +140,7 @@ public function testSyncedImages() {
$edit = [];
$edit['title[0][value]'] = 'Akiko Takeshita';
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[2]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[2]->uri);
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
$edit = [$this->fieldName . '[0][alt]' => 'Akiko Takeshita image', $this->fieldName . '[0][title]' => 'Akiko Takeshita image title'];
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
......@@ -175,7 +175,7 @@ public function testSyncedImages() {
$edit = [];
$edit['title[0][value]'] = 'Giovanni Ribisi';
$name = 'files[' . $this->fieldName . '_0]';
$edit[$name] = drupal_realpath($this->drupalGetTestFiles('image')[3]->uri);
$edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[3]->uri);
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
$name = $this->fieldName . '[0][alt]';
......
......@@ -66,7 +66,7 @@ public function previewNodeImage($image, $field_name, $type) {
$edit = [
'title[0][value]' => $this->randomMachineName(),
];
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
$this->drupalPostForm('node/add/' . $type, $edit, t('Preview'));
}
......@@ -86,7 +86,7 @@ public function uploadNodeImage($image, $field_name, $type, $alt = '') {
$edit = [
'title[0][value]' => $this->randomMachineName(),
];
$edit['files[' . $field_name . '_0]'] = drupal_realpath($image->uri);
$edit['files[' . $field_name . '_0]'] = \Drupal::service('file_system')->realpath($image->uri);
$this->drupalPostForm('node/add/' . $type, $edit, t('Save and publish'));