diff -u b/core/modules/node/src/Tests/PagePreviewTest.php b/core/modules/node/src/Tests/PagePreviewTest.php --- b/core/modules/node/src/Tests/PagePreviewTest.php +++ b/core/modules/node/src/Tests/PagePreviewTest.php @@ -316,11 +316,13 @@ $this->assertUrl($node->toUrl()); $this->assertResponse(200); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); // Assert multiple items can be added and are not lost when previewing. $test_image_1 = current($this->drupalGetTestFiles('image', 39325)); - $edit_image_1['files[field_image_0][]'] = drupal_realpath($test_image_1->uri); + $edit_image_1['files[field_image_0][]'] = $file_system->realpath($test_image_1->uri); $test_image_2 = current($this->drupalGetTestFiles('image', 39325)); - $edit_image_2['files[field_image_1][]'] = drupal_realpath($test_image_2->uri); + $edit_image_2['files[field_image_1][]'] = $file_system->realpath($test_image_2->uri); $edit['field_image[0][alt]'] = 'Alt 1'; $this->drupalPostForm('node/add/page', $edit_image_1, t('Upload')); only in patch2: unchanged: --- a/core/modules/file/src/Tests/FilePrivateTest.php +++ b/core/modules/file/src/Tests/FilePrivateTest.php @@ -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); only in patch2: unchanged: --- a/core/modules/file/src/Tests/SaveUploadFormTest.php +++ b/core/modules/file/src/Tests/SaveUploadFormTest.php @@ -63,10 +63,12 @@ protected function setUp() { $this->maxFidBefore = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); // 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][]' => $file_system->realpath($this->image->getFileUri()), ]; $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -94,7 +96,9 @@ public function testNormal() { // Upload a second file. $image2 = current($this->drupalGetTestFiles('image')); - $edit = ['files[file_test_upload][]' => drupal_realpath($image2->uri)]; + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); + $edit = ['files[file_test_upload][]' => $file_system->realpath($image2->uri)]; $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!')); @@ -115,7 +119,7 @@ public function testNormal() { // Upload a third file to a subdirectory. $image3 = current($this->drupalGetTestFiles('image')); - $image3_realpath = drupal_realpath($image3->uri); + $image3_realpath = $file_system->realpath($image3->uri); $dir = $this->randomMachineName(); $edit = [ 'files[file_test_upload][]' => $image3_realpath, @@ -131,6 +135,8 @@ public function testNormal() { * Tests extension handling. */ public function testHandleExtension() { + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); // The file being tested is a .gif which is in the default safe list // of extensions to allow when the extension validator isn't used. This is // implicitly tested at the testNormal() test. Here we tell @@ -138,7 +144,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][]' => $file_system->realpath($this->image->getFileUri()), 'extensions' => $extensions, ]; @@ -158,7 +164,7 @@ public function testHandleExtension() { // Now tell _file_save_upload_from_form() 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][]' => $file_system->realpath($this->image->getFileUri()), 'extensions' => $extensions, ]; @@ -176,7 +182,7 @@ public function testHandleExtension() { // Now tell _file_save_upload_from_form() to allow any extension. $edit = [ 'file_test_replace' => FILE_EXISTS_REPLACE, - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()), 'allow_all_extensions' => TRUE, ]; $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); @@ -193,11 +199,13 @@ public function testHandleExtension() { */ public function testHandleDangerousFile() { $config = $this->config('system.file'); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); // Allow the .php extension and make sure it gets renamed to .txt for // 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][]' => $file_system->realpath($this->phpfile->uri), 'is_image_file' => FALSE, 'extensions' => 'php', ]; @@ -235,6 +243,8 @@ public function testHandleDangerousFile() { * Tests file munge handling. */ public function testHandleFileMunge() { + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); // Ensure insecure uploads are disabled for this test. $this->config('system.file')->set('allow_insecure_uploads', 0)->save(); $this->image = file_move($this->image, $this->image->getFileUri() . '.foo.' . $this->imageExtension); @@ -244,7 +254,7 @@ public function testHandleFileMunge() { $extensions = $this->imageExtension; $edit = [ - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()), 'extensions' => $extensions, ]; @@ -266,7 +276,7 @@ public function testHandleFileMunge() { file_test_reset(); $edit = [ - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()), 'allow_all_extensions' => TRUE, ]; @@ -284,9 +294,11 @@ public function testHandleFileMunge() { * Tests renaming when uploading over a file that already exists. */ public function testExistingRename() { + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); $edit = [ 'file_test_replace' => FILE_EXISTS_RENAME, - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()) ]; $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -302,7 +314,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][]' => $file_system->realpath($this->image->getFileUri()) ]; $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -316,9 +328,11 @@ public function testExistingReplace() { * Tests for failure when uploading over a file that already exists. */ public function testExistingError() { + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); $edit = [ 'file_test_replace' => FILE_EXISTS_ERROR, - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()) ]; $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -345,9 +359,11 @@ public function testDrupalMovingUploadedFileError() { drupal_mkdir('temporary://' . $test_directory, 0000); $this->assertTrue(is_dir('temporary://' . $test_directory)); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); $edit = [ 'file_subdir' => $test_directory, - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()) + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()) ]; \Drupal::state()->set('file_test.disable_error_collection', TRUE); @@ -371,8 +387,10 @@ public function testDrupalMovingUploadedFileError() { public function testErrorMessagesAreNotChanged() { $error = 'An error message set before _file_save_upload_from_form()'; + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); $edit = [ - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()), 'error_message' => $error, ]; $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); @@ -387,7 +405,7 @@ public function testErrorMessagesAreNotChanged() { // Test that error messages are preserved when an error occurs. $edit = [ - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()), 'error_message' => $error, 'extensions' => 'foo' ]; @@ -403,7 +421,7 @@ public function testErrorMessagesAreNotChanged() { // Test a successful upload with no messages. $edit = [ - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()), ]; $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); $this->assertResponse(200, 'Received a 200 response for posted test file.'); @@ -423,10 +441,12 @@ public function testCombinedErrorMessages() { $textfile = current($this->drupalGetTestFiles('text')); $this->assertTrue(is_file($textfile->uri), 'The text file we are going to upload exists.'); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); $edit = [ 'files[file_test_upload][]' => [ - drupal_realpath($this->phpfile->uri), - drupal_realpath($textfile->uri), + $file_system->realpath($this->phpfile->uri), + $file_system->realpath($textfile->uri), ], 'allow_all_extensions' => FALSE, 'is_image_file' => TRUE, @@ -447,8 +467,10 @@ public function testCombinedErrorMessages() { public function testUploadFieldIsHighlighted() { $this->assertEqual(0, count($this->cssSelect('input[name="files[file_test_upload][]"].error')), 'Successful file upload has no error.'); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); $edit = [ - 'files[file_test_upload][]' => drupal_realpath($this->image->getFileUri()), + 'files[file_test_upload][]' => $file_system->realpath($this->image->getFileUri()), 'extensions' => 'foo' ]; $this->drupalPostForm('file-test/save_upload_from_form_test', $edit, t('Submit')); only in patch2: unchanged: --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -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, ]; only in patch2: unchanged: --- a/core/modules/image/tests/src/Functional/ImageFieldTestBase.php +++ b/core/modules/image/tests/src/Functional/ImageFieldTestBase.php @@ -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')); if ($alt) { // Add alt text. only in patch2: unchanged: --- a/core/tests/Drupal/FunctionalTests/Entity/ContentEntityFormFieldValidationFilteringTest.php +++ b/core/tests/Drupal/FunctionalTests/Entity/ContentEntityFormFieldValidationFilteringTest.php @@ -139,7 +139,7 @@ public function testFieldWidgetsWithLimitedValidationErrors() { // \Drupal\file\Plugin\Field\FieldWidget\FileWidget::process(). $text_file = current($this->getTestFiles('text')); $edit = [ - 'files[test_file_0]' => drupal_realpath($text_file->uri) + 'files[test_file_0]' => \Drupal::service('file_system')->realpath($text_file->uri) ]; $assert_session->elementNotExists('css', 'input#edit-test-file-0-remove-button'); $this->drupalPostForm(NULL, $edit, 'Upload');