diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 27da150..1527ac6 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -195,8 +195,8 @@ protected function doLoadMultiple(array $ids = NULL) { * {@inheritdoc} */ protected function doCreate(array $values) { - // Set default language to current language if not provided. - $values += array($this->langcodeKey => $this->languageManager->getCurrentLanguage()->getId()); + // Set default language to site default if not provided. + $values += array($this->langcodeKey => $this->languageManager->getDefaultLanguage()->getId()); $entity = new $this->entityClass($values, $this->entityTypeId); return $entity; diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php index b2fed13..a5dff1f 100644 --- a/core/modules/editor/src/Form/EditorImageDialog.php +++ b/core/modules/editor/src/Form/EditorImageDialog.php @@ -8,13 +8,15 @@ namespace Drupal\editor\Form; use Drupal\Component\Utility\Bytes; -use Drupal\Core\Form\FormBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\filter\Entity\FilterFormat; use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\CloseModalDialogCommand; use Drupal\Core\Ajax\HtmlCommand; +use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; use Drupal\editor\Ajax\EditorDialogSave; -use Drupal\Core\Ajax\CloseModalDialogCommand; +use Drupal\filter\Entity\FilterFormat; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides an image dialog for text editors. @@ -22,6 +24,29 @@ class EditorImageDialog extends FormBase { /** + * @var EntityStorageInterface $file_storage + */ + protected $fileStorage; + + /** + * The constructor. + * + * @param EntityStorageInterface $file_storage + */ + public function __construct(EntityStorageInterface $file_storage) { + $this->fileStorage = $file_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity.manager')->getStorage('file') + ); + } + + /** * {@inheritdoc} */ public function getFormId() { @@ -208,7 +233,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // attributes and set data-entity-type to 'file'. $fid = $form_state->getValue(array('fid', 0)); if (!empty($fid)) { - $file = file_load($fid); + $file = $this->fileStorage->load($fid); $file_url = file_create_url($file->getFileUri()); // Transform absolute image URLs to relative image URLs: prevent problems // on multisite set-ups and prevent mixed content errors. diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 0bc0584..4c74d91 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -618,6 +618,7 @@ function file_file_download($uri) { */ function file_cron() { $age = \Drupal::config('system.file')->get('temporary_maximum_age'); + $file_storage = \Drupal::entityManager()->getStorage('file'); // Only delete temporary files if older than $age. Note that automatic cleanup // is disabled if $age set to 0. @@ -627,9 +628,10 @@ function file_cron() { ->condition('changed', REQUEST_TIME - $age, '<') ->range(0, 100) ->execute(); - $files = file_load_multiple($fids); + $files = $file_storage->loadMultiple($fids); + $file_usage = \Drupal::service('file.usage'); foreach ($files as $file) { - $references = \Drupal::service('file.usage')->listUsage($file); + $references = $file_usage->listUsage($file); if (empty($references)) { if (file_exists($file->getFileUri())) { $file->delete(); @@ -1213,7 +1215,8 @@ function template_preprocess_file_link(&$variables) { $file = $variables['file']; $options = array(); - $file_entity = ($file instanceof File) ? $file : file_load($file->fid); + $file_storage = \Drupal::entityManager()->getStorage('file'); + $file_entity = ($file instanceof FileInterface) ? $file : $file_storage->load($file->fid); $url = file_create_url($file_entity->getFileUri()); $mime_type = $file->getMimeType(); diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index 1ad5a1f..5f8c95b 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -16,6 +16,7 @@ use Drupal\Core\Render\Element; use Drupal\file\Element\ManagedFile; use Drupal\Core\Url; +use Drupal\file\Entity\File; /** * Plugin implementation of the 'file_generic' widget. @@ -327,7 +328,7 @@ public static function validateMultipleCount($element, FormStateInterface $form_ $removed_files = array_slice($values['fids'], $keep); $removed_names = array(); foreach ($removed_files as $fid) { - $file = file_load($fid); + $file = File::load($fid); $removed_names[] = $file->getFilename(); } $args = array('%field' => $field_storage->getFieldName(), '@max' => $field_storage->getCardinality(), '@count' => $keep, '%list' => implode(', ', $removed_names)); diff --git a/core/modules/file/src/Tests/CopyTest.php b/core/modules/file/src/Tests/CopyTest.php index 3a3a727..3556b93 100644 --- a/core/modules/file/src/Tests/CopyTest.php +++ b/core/modules/file/src/Tests/CopyTest.php @@ -17,6 +17,7 @@ class CopyTest extends FileManagedUnitTestBase { * Test file copying in the normal, base case. */ function testNormal() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $contents = $this->randomMachineName(10); $source = $this->createFile(NULL, $contents); $desired_uri = 'public://' . $this->randomMachineName(); @@ -39,7 +40,7 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -64,11 +65,12 @@ function testExistingRename() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array('copy', 'insert')); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); // Load all the affected files to check the changes that actually made it // to the database. - $loaded_source = file_load($source->id(), TRUE); - $loaded_target = file_load($target->id(), TRUE); - $loaded_result = file_load($result->id(), TRUE); + $loaded_source = $file_storage->load($source->id()); + $loaded_target = $file_storage->load($target->id()); + $loaded_result = $file_storage->load($result->id()); // Verify that the source file wasn't changed. $this->assertFileUnchanged($source, $loaded_source); @@ -104,11 +106,12 @@ function testExistingReplace() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array('load', 'copy', 'update')); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); // Load all the affected files to check the changes that actually made it // to the database. - $loaded_source = file_load($source->id(), TRUE); - $loaded_target = file_load($target->id(), TRUE); - $loaded_result = file_load($result->id(), TRUE); + $loaded_source = $file_storage->load($source->id()); + $loaded_target = $file_storage->load($target->id()); + $loaded_result = $file_storage->load($result->id()); // Verify that the source file wasn't changed. $this->assertFileUnchanged($source, $loaded_source); @@ -141,7 +144,8 @@ function testExistingError() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array()); - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->assertFileUnchanged($source, $file_storage->load($source->id())); + $this->assertFileUnchanged($target, $file_storage->load($target->id())); } } diff --git a/core/modules/file/src/Tests/DeleteTest.php b/core/modules/file/src/Tests/DeleteTest.php index 5f0acc8..707712d 100644 --- a/core/modules/file/src/Tests/DeleteTest.php +++ b/core/modules/file/src/Tests/DeleteTest.php @@ -17,6 +17,7 @@ class DeleteTest extends FileManagedUnitTestBase { * Tries deleting a normal file (as opposed to a directory, symlink, etc). */ function testUnused() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $file = $this->createFile(); // Check that deletion removes the file and database record. @@ -24,13 +25,14 @@ function testUnused() { $file->delete(); $this->assertFileHooksCalled(array('delete')); $this->assertFalse(file_exists($file->getFileUri()), 'Test file has actually been deleted.'); - $this->assertFalse(file_load($file->id()), 'File was removed from the database.'); + $this->assertFalse($file_storage->load($file->id()), 'File was removed from the database.'); } /** * Tries deleting a file that is in use. */ function testInUse() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $file = $this->createFile(); $file_usage = $this->container->get('file.usage'); $file_usage->add($file, 'testing', 'test', 1); @@ -40,9 +42,9 @@ function testInUse() { $usage = $file_usage->listUsage($file); $this->assertEqual($usage['testing']['test'], array(1 => 1), 'Test file is still in use.'); $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.'); - $this->assertTrue(file_load($file->id()), 'File still exists in the database.'); + $this->assertTrue($file_storage->load($file->id()), 'File still exists in the database.'); - // Clear out the call to hook_file_load(). + // Reset the call to load('file'). file_test_reset(); $file_usage->delete($file, 'testing', 'test', 1); @@ -50,7 +52,7 @@ function testInUse() { $this->assertFileHooksCalled(array('load', 'update')); $this->assertTrue(empty($usage), 'File usage data was removed.'); $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.'); - $file = file_load($file->id()); + $file = $file_storage->load($file->id()); $this->assertTrue($file, 'File still exists in the database.'); $this->assertTrue($file->isTemporary(), 'File is temporary.'); file_test_reset(); @@ -69,6 +71,6 @@ function testInUse() { // file_cron() loads $this->assertFileHooksCalled(array('delete')); $this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.'); - $this->assertFalse(file_load($file->id()), 'File was removed from the database.'); + $this->assertFalse($file_storage->load($file->id()), 'File was removed from the database.'); } } diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/src/Tests/FileFieldDisplayTest.php index f1a3f8a..eb3dafc 100644 --- a/core/modules/file/src/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php @@ -57,7 +57,8 @@ function testNodeDisplay() { $node_storage = $this->container->get('entity.manager')->getStorage('node'); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $node_file = $file_storage->load($node->{$field_name}->target_id); $file_link = array( '#theme' => 'file_link', '#file' => $node_file, diff --git a/core/modules/file/src/Tests/FileFieldPathTest.php b/core/modules/file/src/Tests/FileFieldPathTest.php index bf166ed..a22df25 100644 --- a/core/modules/file/src/Tests/FileFieldPathTest.php +++ b/core/modules/file/src/Tests/FileFieldPathTest.php @@ -17,6 +17,7 @@ class FileFieldPathTest extends FileFieldTestBase { * Tests the normal formatter display on node display. */ function testUploadPath() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $field_name = strtolower($this->randomMachineName()); $type_name = 'article'; @@ -29,7 +30,7 @@ function testUploadPath() { // Check that the file was uploaded to the file root. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Change the path to contain multiple subdirectories. @@ -41,7 +42,8 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id, TRUE); + $file_storage->resetCache(array($node->{$field_name}->target_id)); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri()))); // Check the path when used with tokens. @@ -54,7 +56,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); // Do token replacement using the same user which uploaded the file, not // the user running the test case. $data = array('user' => $this->admin_user); diff --git a/core/modules/file/src/Tests/FileFieldRSSContentTest.php b/core/modules/file/src/Tests/FileFieldRSSContentTest.php index 7f04ac2..a655c33 100644 --- a/core/modules/file/src/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/src/Tests/FileFieldRSSContentTest.php @@ -63,7 +63,8 @@ function testFileFieldRSSContent() { // Get the uploaded file from the node. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $node_file = $file_storage->load($node->{$field_name}->target_id); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); diff --git a/core/modules/file/src/Tests/FileFieldRevisionTest.php b/core/modules/file/src/Tests/FileFieldRevisionTest.php index 3c26f59..be22cf5 100644 --- a/core/modules/file/src/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/src/Tests/FileFieldRevisionTest.php @@ -25,6 +25,7 @@ class FileFieldRevisionTest extends FileFieldTestBase { * should be deleted also. */ function testRevisions() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -40,7 +41,7 @@ function testRevisions() { // Check that the file exists on disk and in the database. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file_r1 = file_load($node->{$field_name}->target_id); + $node_file_r1 = $file_storage->load($node->{$field_name}->target_id); $node_vid_r1 = $node->getRevisionId(); $this->assertFileExists($node_file_r1, 'New file saved to disk on node creation.'); $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.'); @@ -50,7 +51,7 @@ function testRevisions() { $this->replaceNodeFile($test_file, $field_name, $nid); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file_r2 = file_load($node->{$field_name}->target_id); + $node_file_r2 = $file_storage->load($node->{$field_name}->target_id); $node_vid_r2 = $node->getRevisionId(); $this->assertFileExists($node_file_r2, 'Replacement file exists on disk after creating new revision.'); $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.'); @@ -58,7 +59,7 @@ function testRevisions() { // Check that the original file is still in place on the first revision. $node = node_revision_load($node_vid_r1); - $current_file = file_load($node->{$field_name}->target_id); + $current_file = $file_storage->load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $current_file->id(), 'Original file still in place after replacing file in new revision.'); $this->assertFileExists($node_file_r1, 'Original file still in place after replacing file in new revision.'); $this->assertFileEntryExists($node_file_r1, 'Original file entry still in place after replacing file in new revision'); @@ -69,7 +70,7 @@ function testRevisions() { $this->drupalPostForm('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file_r3 = file_load($node->{$field_name}->target_id); + $node_file_r3 = $file_storage->load($node->{$field_name}->target_id); $node_vid_r3 = $node->getRevisionId(); $this->assertEqual($node_file_r2->id(), $node_file_r3->id(), 'Previous revision file still in place after creating a new revision without a new file.'); $this->assertFileIsPermanent($node_file_r3, 'New revision file is permanent.'); @@ -78,7 +79,7 @@ function testRevisions() { $this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file_r4 = file_load($node->{$field_name}->target_id); + $node_file_r4 = $file_storage->load($node->{$field_name}->target_id); $this->assertEqual($node_file_r1->id(), $node_file_r4->id(), 'Original revision file still in place after reverting to the original revision.'); $this->assertFileIsPermanent($node_file_r4, 'Original revision file still permanent after reverting to the original revision.'); diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index 0cf36c3..4e8547b 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -40,7 +40,10 @@ function getTestFile($type_name, $size = NULL) { // Get a file to upload. $file = current($this->drupalGetTestFiles($type_name, $size)); - // Add a filesize property to files as would be read by file_load(). + /** + * Add a filesize property to files as would be read by + * \Drupal\Core\Entity\EntityInterface::load(). + */ $file->filesize = filesize($file->uri); return entity_create('file', (array) $file); @@ -216,7 +219,8 @@ function assertFileExists($file, $message = NULL) { */ function assertFileEntryExists($file, $message = NULL) { $this->container->get('entity.manager')->getStorage('file')->resetCache(); - $db_file = file_load($file->id()); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $db_file = $file_storage->load($file->id()); $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); $this->assertEqual($db_file->getFileUri(), $file->getFileUri(), $message); } @@ -235,7 +239,8 @@ function assertFileNotExists($file, $message = NULL) { function assertFileEntryNotExists($file, $message) { $this->container->get('entity.manager')->getStorage('file')->resetCache(); $message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); - $this->assertFalse(file_load($file->id()), $message); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->assertFalse($file_storage->load($file->id()), $message); } /** diff --git a/core/modules/file/src/Tests/FileFieldValidateTest.php b/core/modules/file/src/Tests/FileFieldValidateTest.php index 21d93af..44d072e 100644 --- a/core/modules/file/src/Tests/FileFieldValidateTest.php +++ b/core/modules/file/src/Tests/FileFieldValidateTest.php @@ -24,6 +24,7 @@ class FileFieldValidateTest extends FileFieldTestBase { * Tests the required property on file fields. */ function testRequired() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -45,7 +46,7 @@ function testRequired() { $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.'); @@ -63,7 +64,7 @@ function testRequired() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.'); } @@ -72,6 +73,7 @@ function testRequired() { * Tests the max file size validator. */ function testFileMaxSize() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -95,7 +97,7 @@ function testFileMaxSize() { $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%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).', array('%filesize' => format_size($small_file->getSize()), '%maxsize' => $max_filesize))); @@ -112,7 +114,7 @@ function testFileMaxSize() { $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, format_string('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); $this->assertFileEntryExists($node_file, format_string('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->getSize())))); } @@ -121,6 +123,7 @@ function testFileMaxSize() { * Tests file extension checking. */ function testFileExtension() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -136,7 +139,7 @@ function testFileExtension() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, '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.'); @@ -155,7 +158,7 @@ function testFileExtension() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'File exists after uploading a file with extension checking.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.'); } diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index f3ae0c4..2503392 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -43,6 +43,7 @@ protected function setUp() { * Tests upload and remove buttons for a single-valued File field. */ function testSingleValuedWidget() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -58,7 +59,7 @@ function testSingleValuedWidget() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the file can be downloaded. @@ -219,6 +220,7 @@ function testMultiValuedWidget() { * Tests a file field with a "Private files" upload destination setting. */ function testPrivateFileSetting() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Grant the admin user required permissions. user_role_grant_permissions($this->admin_user->roles[0]->target_id, array('administer node fields')); @@ -236,7 +238,7 @@ function testPrivateFileSetting() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = file_load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); // Ensure the private file is available to the user who uploaded it. diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php index 38293ec..cb238b0 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -56,6 +56,7 @@ protected function sumUsages($usage) { * Tests file overview with different user permissions. */ function testFileListingPages() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $file_usage = $this->container->get('file.usage'); // Users without sufficient permissions should not see file listing. $this->drupalLogin($this->base_user); @@ -96,7 +97,7 @@ function testFileListingPages() { $this->drupalGet('admin/content/files'); foreach ($nodes as $node) { - $file = entity_load('file', $node->file->target_id); + $file = $file_storage->load($node->file->target_id); $this->assertText($file->getFilename()); $this->assertLinkByHref(file_create_url($file->getFileUri())); $this->assertLinkByHref('admin/content/files/usage/' . $file->id()); @@ -110,11 +111,11 @@ function testFileListingPages() { $nodes[1]->save(); $this->drupalGet('admin/content/files'); - $file = entity_load('file', $orphaned_file); + $file = $file_storage->load($orphaned_file); $usage = $this->sumUsages($file_usage->listUsage($file)); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); - $file = entity_load('file', $used_file); + $file = $file_storage->load($used_file); $usage = $this->sumUsages($file_usage->listUsage($file)); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); @@ -123,7 +124,7 @@ function testFileListingPages() { // Test file usage page. foreach ($nodes as $node) { - $file = entity_load('file', $node->file->target_id); + $file = $file_storage->load($node->file->target_id); $usage = $file_usage->listUsage($file); $this->drupalGet('admin/content/files/usage/' . $file->id()); $this->assertResponse(200); diff --git a/core/modules/file/src/Tests/FilePrivateTest.php b/core/modules/file/src/Tests/FilePrivateTest.php index 4ff4ea7..63f9100 100644 --- a/core/modules/file/src/Tests/FilePrivateTest.php +++ b/core/modules/file/src/Tests/FilePrivateTest.php @@ -37,6 +37,7 @@ protected function setUp() { * Tests file access for file uploaded to a private node. */ function testPrivateFile() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; $field_name = strtolower($this->randomMachineName()); @@ -46,7 +47,7 @@ function testPrivateFile() { $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); \Drupal::entityManager()->getStorage('node')->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = File::load($node->{$field_name}->target_id); + $node_file = $file_storage->load($node->{$field_name}->target_id); // Ensure the file can be viewed. $this->drupalGet('node/' . $node->id()); $this->assertRaw($node_file->getFilename(), 'File reference is displayed after attaching it'); @@ -66,7 +67,7 @@ function testPrivateFile() { $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); \Drupal::entityManager()->getStorage('node')->resetCache(array($nid)); $node = $node_storage->load($nid); - $node_file = File::load($node->{$no_access_field_name}->target_id); + $node_file = $file_storage->load($node->{$no_access_field_name}->target_id); // Ensure the file cannot be downloaded. $this->drupalGet(file_create_url($node_file->getFileUri())); diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php index 84d599f..4aea78f 100644 --- a/core/modules/file/src/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php @@ -20,6 +20,7 @@ class FileTokenReplaceTest extends FileFieldTestBase { * Creates a file, then tests the tokens generated from it. */ function testFileTokenReplacement() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $token_service = \Drupal::token(); $language_interface = \Drupal::languageManager()->getCurrentLanguage(); @@ -40,7 +41,7 @@ function testFileTokenReplacement() { // Load the node and the file. $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); - $file = file_load($node->{$field_name}->target_id); + $file = $file_storage->load($node->{$field_name}->target_id); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/file/src/Tests/LoadTest.php b/core/modules/file/src/Tests/LoadTest.php index 7c593cb..a5af2a3 100644 --- a/core/modules/file/src/Tests/LoadTest.php +++ b/core/modules/file/src/Tests/LoadTest.php @@ -8,7 +8,7 @@ namespace Drupal\file\Tests; /** - * Tests the file_load() function. + * Tests the load('file') function. * * @group file */ @@ -17,7 +17,8 @@ class LoadTest extends FileManagedUnitTestBase { * Try to load a non-existent file by fid. */ function testLoadMissingFid() { - $this->assertFalse(file_load(-1), 'Try to load an invalid fid fails.'); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->assertFalse($file_storage->load(-1), 'Try to load an invalid fid fails.'); $this->assertFileHooksCalled(array()); } @@ -45,10 +46,10 @@ function testLoadInvalidStatus() { function testSingleValues() { // Create a new file entity from scratch so we know the values. $file = $this->createFile('druplicon.txt', NULL, 'public'); - - $by_fid_file = file_load($file->id()); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $by_fid_file = $file_storage->load($file->id()); $this->assertFileHookCalled('load'); - $this->assertTrue(is_object($by_fid_file), 'file_load() returned an object.'); + $this->assertTrue(is_object($by_fid_file), 'file_storage->load() returned an object.'); $this->assertEqual($by_fid_file->id(), $file->id(), 'Loading by fid got the same fid.', 'File'); $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File'); $this->assertEqual($by_fid_file->getFilename(), $file->getFilename(), 'Loading by fid got the correct filename.', 'File'); @@ -61,6 +62,7 @@ function testSingleValues() { * This will test loading file data from the database. */ function testMultiple() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); // Create a new file entity. $file = $this->createFile('druplicon.txt', NULL, 'public'); @@ -68,16 +70,16 @@ function testMultiple() { file_test_reset(); $by_path_files = entity_load_multiple_by_properties('file', array('uri' => $file->getFileUri())); $this->assertFileHookCalled('load'); - $this->assertEqual(1, count($by_path_files), 'file_load_multiple() returned an array of the correct size.'); + $this->assertEqual(1, count($by_path_files), 'file_storage->file_load_multiple() returned an array of the correct size.'); $by_path_file = reset($by_path_files); $this->assertTrue($by_path_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.'); $this->assertEqual($by_path_file->id(), $file->id(), 'Loading by filepath got the correct fid.', 'File'); // Load by fid. file_test_reset(); - $by_fid_files = file_load_multiple(array($file->id())); + $by_fid_files = $file_storage->loadMultiple(array($file->id())); $this->assertFileHooksCalled(array()); - $this->assertEqual(1, count($by_fid_files), 'file_load_multiple() returned an array of the correct size.'); + $this->assertEqual(1, count($by_fid_files), 'file_storage->loadMultiple() returned an array of the correct size.'); $by_fid_file = reset($by_fid_files); $this->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.'); $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File'); diff --git a/core/modules/file/src/Tests/MoveTest.php b/core/modules/file/src/Tests/MoveTest.php index 9b1bfc2..89e2459 100644 --- a/core/modules/file/src/Tests/MoveTest.php +++ b/core/modules/file/src/Tests/MoveTest.php @@ -38,7 +38,9 @@ function testNormal() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_file = file_load($result->id(), TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $loaded_file = $file_storage->load($result->id()); $this->assertTrue($loaded_file, 'File can be loaded from the database.'); $this->assertFileUnchanged($result, $loaded_file); } @@ -66,14 +68,18 @@ function testExistingRename() { $this->assertFileHooksCalled(array('move', 'load', 'update')); // Compare the returned value to what made it into the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); // The target file should not have been altered. - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $file_storage->resetCache(array($target->id())); + $this->assertFileUnchanged($target, $file_storage->load($target->id())); // Make sure we end up with two distinct files afterwards. $this->assertDifferentFile($target, $result); // Compare the source and results. - $loaded_source = file_load($source->id(), TRUE); + $file_storage->resetCache(array($source->id())); + $loaded_source = $file_storage->load($source->id()); $this->assertEqual($loaded_source->id(), $result->id(), "Returned file's id matches the source."); $this->assertNotEqual($loaded_source->getFileUri(), $source->getFileUri(), 'Returned file path has changed from the original.'); } @@ -102,7 +108,9 @@ function testExistingReplace() { // Reload the file from the database and check that the changes were // actually saved. - $loaded_result = file_load($result->id(), TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $loaded_result = $file_storage->load($result->id()); $this->assertFileUnchanged($result, $loaded_result); // Check that target was re-used. $this->assertSameFile($target, $loaded_result); @@ -129,7 +137,9 @@ function testExistingReplaceSelf() { // Load the file from the database and make sure it is identical to what // was returned. - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($source->id())); + $this->assertFileUnchanged($source, $file_storage->load($source->id())); } /** @@ -156,7 +166,10 @@ function testExistingError() { // Load the file from the database and make sure it is identical to what // was returned. - $this->assertFileUnchanged($source, file_load($source->id(), TRUE)); - $this->assertFileUnchanged($target, file_load($target->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($source->id())); + $this->assertFileUnchanged($source, $file_storage->load($source->id())); + $file_storage->resetCache(array($target->id())); + $this->assertFileUnchanged($target, $file_storage->load($target->id())); } } diff --git a/core/modules/file/src/Tests/SaveDataTest.php b/core/modules/file/src/Tests/SaveDataTest.php index 8368e0b..43caa4b 100644 --- a/core/modules/file/src/Tests/SaveDataTest.php +++ b/core/modules/file/src/Tests/SaveDataTest.php @@ -32,7 +32,9 @@ function testWithoutFilename() { $this->assertFileHooksCalled(array('insert')); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -57,7 +59,9 @@ function testWithFilename() { $this->assertFileHooksCalled(array('insert')); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -81,11 +85,14 @@ function testExistingRename() { $this->assertFileHooksCalled(array('insert')); // Ensure that the existing file wasn't overwritten. + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($existing->id())); $this->assertDifferentFile($existing, $result); - $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE)); + $this->assertFileUnchanged($existing, $file_storage->load($existing->id())); // Verify that was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -112,7 +119,9 @@ function testExistingReplace() { $this->assertSameFile($existing, $result); // Verify that what was returned is what's in the database. - $this->assertFileUnchanged($result, file_load($result->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($result->id())); + $this->assertFileUnchanged($result, $file_storage->load($result->id())); } /** @@ -131,6 +140,8 @@ function testExistingError() { $this->assertFileHooksCalled(array()); // Ensure that the existing file wasn't overwritten. - $this->assertFileUnchanged($existing, file_load($existing->id(), TRUE)); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($existing->id())); + $this->assertFileUnchanged($existing, $file_storage->load($existing->id())); } } diff --git a/core/modules/file/src/Tests/SaveTest.php b/core/modules/file/src/Tests/SaveTest.php index cc12515..0bac285 100644 --- a/core/modules/file/src/Tests/SaveTest.php +++ b/core/modules/file/src/Tests/SaveTest.php @@ -16,6 +16,7 @@ */ class SaveTest extends FileManagedUnitTestBase { function testFileSave() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); // Create a new file entity. $file = File::create(array( 'uid' => 1, @@ -35,7 +36,7 @@ function testFileSave() { $this->assertFileHooksCalled(array('insert')); $this->assertTrue($file->id() > 0, 'A new file ID is set when saving a new file to the database.', 'File'); - $loaded_file = file_load($file->id()); + $loaded_file = $file_storage->load($file->id()); $this->assertNotNull($loaded_file, 'Record exists in the database.'); $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.'); $this->assertEqual($file->getSize(), filesize($file->getFileUri()), 'File size was set correctly.', 'File'); @@ -52,7 +53,7 @@ function testFileSave() { $this->assertEqual($file->id(), $file->id(), 'The file ID of an existing file is not changed when updating the database.', 'File'); $this->assertTrue($file->getChangedTime() >= $file->getChangedTime(), "Timestamp didn't go backwards.", 'File'); - $loaded_file = file_load($file->id()); + $loaded_file = $file_storage->load($file->id()); $this->assertNotNull($loaded_file, 'Record still exists in the database.', 'File'); $this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.'); $this->assertEqual($loaded_file->langcode->value, 'en', 'Langcode was saved correctly.'); diff --git a/core/modules/file/src/Tests/SaveUploadTest.php b/core/modules/file/src/Tests/SaveUploadTest.php index 032a3d4..8b6a03b 100644 --- a/core/modules/file/src/Tests/SaveUploadTest.php +++ b/core/modules/file/src/Tests/SaveUploadTest.php @@ -70,9 +70,10 @@ protected function setUp() { * Test the file_save_upload() function. */ function testNormal() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $max_fid_after = db_query('SELECT MAX(fid) AS fid FROM {file_managed}')->fetchField(); $this->assertTrue($max_fid_after > $this->maxFidBefore, 'A new file was created.'); - $file1 = file_load($max_fid_after); + $file1 = $file_storage->load($max_fid_after); $this->assertTrue($file1, 'Loaded the file.'); // MIME type of the uploaded image may be either image/jpeg or image/png. $this->assertEqual(substr($file1->getMimeType(), 0, 5), 'image', 'A MIME type was set.'); @@ -91,13 +92,13 @@ function testNormal() { // Check that the correct hooks were called. $this->assertFileHooksCalled(array('validate', 'insert')); - $file2 = file_load($max_fid_after); + $file2 = $file_storage->load($max_fid_after); $this->assertTrue($file2, 'Loaded the file'); // MIME type of the uploaded image may be either image/jpeg or image/png. $this->assertEqual(substr($file2->getMimeType(), 0, 5), 'image', 'A MIME type was set.'); - // Load both files using file_load_multiple(). - $files = file_load_multiple(array($file1->id(), $file2->id())); + // Load both files using $file_storage->loadMultiple(). + $files = $file_storage->loadMultiple(array($file1->id(), $file2->id())); $this->assertTrue(isset($files[$file1->id()]), 'File was loaded successfully'); $this->assertTrue(isset($files[$file2->id()]), 'File was loaded successfully'); diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php index 38a163c..2b4b31f 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php @@ -14,6 +14,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; use Drupal\Core\Utility\LinkGeneratorInterface; +use Drupal\file\FileStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Form\FormStateInterface; @@ -85,7 +86,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration['view_mode'], $configuration['third_party_settings'], $container->get('current_user'), - $container->get('link_generator') + $container->get('link_generator'), + $container->get('entity.manager')->getStorage('file') ); } diff --git a/core/modules/image/src/Tests/ImageAdminStylesTest.php b/core/modules/image/src/Tests/ImageAdminStylesTest.php index df068ee..d0e6ed5 100644 --- a/core/modules/image/src/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/src/Tests/ImageAdminStylesTest.php @@ -301,7 +301,8 @@ function testStyleReplacement() { // Get node field original image URI. $fid = $node->get($field_name)->target_id; - $original_uri = file_load($fid)->getFileUri(); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $original_uri = $file_storage->load($fid)->getFileUri(); // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); @@ -435,7 +436,8 @@ function testConfigImport() { // Get node field original image URI. $fid = $node->get($field_name)->target_id; - $original_uri = file_load($fid)->getFileUri(); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $original_uri = $file_storage->load($fid)->getFileUri(); // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index 6efc84d..830f97f 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -253,7 +253,8 @@ public function testDefaultImages() { ); // Confirm the default image is shown on the node form. - $file = File::load($default_images['field_new']->id()); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file = $file_storage->load($default_images['field_new']->id()); $this->drupalGet('node/add/article'); $this->assertRaw($file->getFilename()); @@ -297,7 +298,7 @@ public function testDefaultImages() { $this->assertText(t('The specified file text-0.txt could not be uploaded. Only files with the following extensions are allowed: png gif jpg jpeg.'), 'Non-image file cannot be used as default image.'); // Confirm the default image is shown on the node form. - $file = File::load($default_images['field_new']->id()); + $file = $file_storage->load($default_images['field_new']->id()); $this->drupalGet('node/add/article'); $this->assertRaw($file->getFilename()); } diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index 4fef5f5..75e03a1 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -83,7 +83,8 @@ function _testImageFieldFormatters($scheme) { $node = $node_storage->load($nid); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}->target_id)->getFileUri(); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $image_uri = $file_storage->load($node->{$field_name}->target_id)->getFileUri(); $image = array( '#theme' => 'image', '#uri' => $image_uri, @@ -188,6 +189,7 @@ function _testImageFieldFormatters($scheme) { * Tests for image field settings. */ function testImageFieldSettings() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $test_image = current($this->drupalGetTestFiles('image')); list(, $test_image_extension) = explode('.', $test_image->filename); @@ -230,7 +232,7 @@ function testImageFieldSettings() { $node = $node_storage->load($nid); $image_style = array( '#theme' => 'image_style', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => $file_storage->load($node->{$field_name}->target_id)->getFileUri(), '#width' => 40, '#height' => 20, '#style_name' => 'medium', @@ -241,7 +243,7 @@ function testImageFieldSettings() { // Add alt/title fields to the image and verify that they are displayed. $image = array( '#theme' => 'image', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => $file_storage->load($node->{$field_name}->target_id)->getFileUri(), '#alt' => $this->randomMachineName(), '#title' => $this->randomMachineName(), '#width' => 40, @@ -348,9 +350,10 @@ function testImageFieldDefaultImage() { $nid = $this->uploadNodeImage($images[1], $field_name, 'article'); $node_storage->resetCache(array($nid)); $node = $node_storage->load($nid); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); $image = array( '#theme' => 'image', - '#uri' => file_load($node->{$field_name}->target_id)->getFileUri(), + '#uri' => $file_storage->load($node->{$field_name}->target_id)->getFileUri(), '#width' => 40, '#height' => 20, ); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php index 4adbcb2..f9cd13c 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFileTest.php @@ -52,8 +52,9 @@ protected function setUp() { * Tests the Drupal 6 files to Drupal 8 migration. */ public function testFiles() { + $file_storage = $this->container->get('entity.manager')->getStorage('file'); /** @var \Drupal\file\FileInterface $file */ - $file = entity_load('file', 1); + $file = $file_storage->load(1); $this->assertIdentical($file->getFilename(), 'Image1.png'); $this->assertIdentical($file->getSize(), '39325'); $this->assertIdentical($file->getFileUri(), 'public://image-1.png'); @@ -85,11 +86,11 @@ public function testFiles() { $executable = new MigrateExecutable($migration, $this); $executable->import(); - $file = entity_load('file', 2); + $file = $file_storage->load(2); $this->assertIdentical($file->getFileUri(), 'public://core/modules/simpletest/files/image-2.jpg'); // Ensure that a temporary file has been migrated. - $file = entity_load('file', 6); + $file = $file_storage->load(6); $this->assertIdentical($file->getFileUri(), 'temporary://some-temp-file.jpg'); } diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php index be028c0..c5a7bc4 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserPictureFileTest.php @@ -53,8 +53,8 @@ public function testUserPictures() { foreach (entity_load('migration', 'd6_user_picture_file')->getIdMap() as $destination_ids) { $file_ids[] = reset($destination_ids); } - $files = entity_load_multiple('file', $file_ids); - /** @var \Drupal\file\FileInterface $file */ + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $files = $file_storage->loadMultiple($file_ids); $file = array_shift($files); $this->assertIdentical($file->getFilename(), 'image-test.jpg'); $this->assertIdentical($file->getFileUri(), 'public://image-test.jpg'); diff --git a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php index e6aea38..5ae4926 100644 --- a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php @@ -68,8 +68,8 @@ protected function setUp() { $node_storage->resetCache(array($nid)); $this->node = $node_storage->load($nid); - $this->file = file_load($this->node->{$this->fieldName}->target_id); - + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->file = $file_storage->load($this->node->{$this->fieldName}->target_id); } /** diff --git a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php index ec41a77..2f9b3e0 100644 --- a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php @@ -68,7 +68,8 @@ protected function setUp() { // Save a node with the image. $nid = $this->uploadNodeImage($image, $this->fieldName, 'article'); $this->node = Node::load($nid); - $this->file = file_load($this->node->{$this->fieldName}->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $this->file = $file_storage->load($this->node->{$this->fieldName}->target_id); } /** diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index e31d0ba..74d4dbd 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -172,7 +172,8 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles = $node = $node_storage->load($nid); // Test that the default formatter is being used. - $image_uri = File::load($node->{$field_name}->target_id)->getFileUri(); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $image_uri = $file_storage->load($node->{$field_name}->target_id)->getFileUri(); $image = array( '#theme' => 'image', '#uri' => $image_uri, diff --git a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php index bfff89e..3ab6f79 100644 --- a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php @@ -293,19 +293,6 @@ public function testLivePreview() { } /** - * Tests the views interface for rest export displays. - */ - public function testSerializerViewsUI() { - $this->drupalLogin($this->adminUser); - // Click the "Update preview button". - $this->drupalPostForm('admin/structure/views/view/test_serializer_display_field/edit/rest_export_1', $edit = array(), t('Update preview')); - $this->assertResponse(200); - // Check if we receive the expected result. - $result = $this->xpath('//div[@id="views-live-preview"]/pre'); - $this->assertIdentical($this->drupalGet('test/serialize/field'), (string) $result[0], 'The expected JSON preview output was found.'); - } - - /** * Tests the field row style using fieldapi fields. */ public function testFieldapiField() { diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index 9386983..ee3764d 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -255,7 +255,8 @@ public function testFileHooks() { )); $GLOBALS['entity_crud_hook_test'] = array(); - $file = file_load($file->id()); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file = $file_storage->load($file->id()); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_entity_load called for type file', diff --git a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php index 9cb3372..91c59de 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyImageTest.php @@ -83,7 +83,8 @@ public function testTaxonomyImageAccess() { // Create a user that should have access to the file and one that doesn't. $access_user = $this->drupalCreateUser(array('access content')); $no_access_user = $this->drupalCreateUser(); - $image = file_load($term->field_test->target_id); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $image = $file_storage->load($term->field_test->target_id); $this->drupalLogin($access_user); $this->drupalGet(file_create_url($image->getFileUri())); $this->assertResponse(200, 'Private image on term is accessible with right permission'); diff --git a/core/modules/taxonomy/src/Tests/TermTest.php b/core/modules/taxonomy/src/Tests/TermTest.php index 083e28b..0cd7618 100644 --- a/core/modules/taxonomy/src/Tests/TermTest.php +++ b/core/modules/taxonomy/src/Tests/TermTest.php @@ -265,15 +265,6 @@ function testNodeTermCreationAndDeletion() { $term_objects[$key] = reset($term_objects[$key]); } - // Get the node. - $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); - - // Test editing the node. - $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); - foreach ($terms as $term) { - $this->assertText($term, 'The term was retained after edit and still appears on the node page.'); - } - // Delete term 1 from the term edit page. $this->drupalGet('taxonomy/term/' . $term_objects['term1']->id() . '/edit'); $this->clickLink(t('Delete')); @@ -284,6 +275,8 @@ function testNodeTermCreationAndDeletion() { $this->drupalPostForm(NULL, array(), t('Delete')); $term_names = array($term_objects['term3']->getName(), $term_objects['term4']->getName()); + // Get the node. + $node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $this->drupalGet('node/' . $node->id()); foreach ($term_names as $term_name) { diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php index 2938e67..b84d51f 100644 --- a/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -76,7 +76,9 @@ function testCreateDeletePicture() { \Drupal::service('cron')->run(); // Verify that the image has been deleted. - $this->assertFalse(file_load($file->id(), TRUE), 'File was removed from the database.'); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($file->id())); + $this->assertFalse($file_storage->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.'); @@ -132,6 +134,8 @@ function saveUserPicture($image) { // Load actual user data from database. $account = user_load($this->webUser->id(), TRUE); - return file_load($account->user_picture->target_id, TRUE); + $file_storage = $this->container->get('entity.manager')->getStorage('file'); + $file_storage->resetCache(array($account->user_picture->target_id)); + return $file_storage->load($account->user_picture->target_id); } } diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php index 415b704..c4cc43f 100644 --- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php @@ -502,7 +502,7 @@ public function getRouteName() { // Check for overridden route names. $view_route_names = $this->getAlteredRouteNames(); - return (isset($view_route_names[$view_route_key]) ? $view_route_names[$view_route_key] : "view.$view_route_key"); + return (isset($view_route_names[$view_route_key]) ? $view_route_names[$view_route_key] : "views.$view_route_key"); } /** diff --git a/core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php b/core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php index 0cc643a..56ec973 100644 --- a/core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/display/PathPluginBaseTest.php @@ -312,24 +312,6 @@ public function testAlterRoutesWithOptionalParameters() { } /** - * Tests the getRouteName method. - */ - public function testGetRouteName() { - list($view) = $this->setupViewExecutableAccessPlugin(); - - $display = array(); - $display['display_plugin'] = 'page'; - $display['id'] = 'page_1'; - $display['display_options'] = array( - 'path' => 'test_route', - ); - $this->pathPlugin->initDisplay($view, $display); - $route_name = $this->pathPlugin->getRouteName(); - // Ensure that the expected routename is returned. - $this->assertEquals('view.test_id.page_1', $route_name); - } - - /** * Returns some mocked view entity, view executable, and access plugin. */ protected function setupViewExecutableAccessPlugin() { diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 2302eaa..f754615 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -139,8 +139,8 @@ protected function setUp() { $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface'); $this->languageManager->expects($this->any()) - ->method('getCurrentLanguage') - ->willReturn(new Language(array('id' => 'hu'))); + ->method('getDefaultLanguage') + ->will($this->returnValue(new Language(array('langcode' => 'en')))); $this->configFactory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface'); @@ -175,7 +175,6 @@ protected function setUp() { $container->set('config.typed', $this->typedConfigManager); $container->set('cache_tags.invalidator', $this->cacheTagsInvalidator); $container->set('config.manager', $this->configManager); - $container->set('language_manager', $this->languageManager); \Drupal::setContainer($container); } @@ -231,34 +230,6 @@ public function testCreate() { } /** - * @covers ::create - * @covers ::doCreate - */ - public function testCreateWithCurrentLanguage() { - $this->languageManager->expects($this->any()) - ->method('getLanguage') - ->with('hu') - ->willReturn(new Language(array('id' => 'hu'))); - - $entity = $this->entityStorage->create(array('id' => 'foo')); - $this->assertSame('hu', $entity->language()->getId()); - } - - /** - * @covers ::create - * @covers ::doCreate - */ - public function testCreateWithExplicitLanguage() { - $this->languageManager->expects($this->any()) - ->method('getLanguage') - ->with('en') - ->willReturn(new Language(array('id' => 'en'))); - - $entity = $this->entityStorage->create(array('id' => 'foo', 'langcode' => 'en')); - $this->assertSame('en', $entity->language()->getId()); - } - - /** * @covers ::save * @covers ::doSave *