Commit faada60f authored by alexpott's avatar alexpott

Issue #2321969 by rpayanm, subhojit777, prics, LinL, JeroenT, Temoor,...

Issue #2321969 by rpayanm, subhojit777, prics, LinL, JeroenT, Temoor, prashantgoel, Mile23, pcambra, Sumi: Replace all instances of file_load(), file_load_multiple(), entity_load('file') and entity_load_multiple('file') with static method calls
parent 08baa72a
...@@ -15,12 +15,40 @@ ...@@ -15,12 +15,40 @@
use Drupal\Core\Ajax\HtmlCommand; use Drupal\Core\Ajax\HtmlCommand;
use Drupal\editor\Ajax\EditorDialogSave; use Drupal\editor\Ajax\EditorDialogSave;
use Drupal\Core\Ajax\CloseModalDialogCommand; use Drupal\Core\Ajax\CloseModalDialogCommand;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
/** /**
* Provides an image dialog for text editors. * Provides an image dialog for text editors.
*/ */
class EditorImageDialog extends FormBase { class EditorImageDialog extends FormBase {
/**
* The file storage service.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $fileStorage;
/**
* Constructs a form object for image dialog.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $file_storage
* The file storage service.
*/
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} * {@inheritdoc}
*/ */
...@@ -208,7 +236,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ...@@ -208,7 +236,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// attributes and set data-entity-type to 'file'. // attributes and set data-entity-type to 'file'.
$fid = $form_state->getValue(array('fid', 0)); $fid = $form_state->getValue(array('fid', 0));
if (!empty($fid)) { if (!empty($fid)) {
$file = file_load($fid); $file = $this->fileStorage->load($fid);
$file_url = file_create_url($file->getFileUri()); $file_url = file_create_url($file->getFileUri());
// Transform absolute image URLs to relative image URLs: prevent problems // Transform absolute image URLs to relative image URLs: prevent problems
// on multisite set-ups and prevent mixed content errors. // on multisite set-ups and prevent mixed content errors.
......
...@@ -631,6 +631,7 @@ function file_file_download($uri) { ...@@ -631,6 +631,7 @@ function file_file_download($uri) {
*/ */
function file_cron() { function file_cron() {
$age = \Drupal::config('system.file')->get('temporary_maximum_age'); $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 // Only delete temporary files if older than $age. Note that automatic cleanup
// is disabled if $age set to 0. // is disabled if $age set to 0.
...@@ -640,7 +641,7 @@ function file_cron() { ...@@ -640,7 +641,7 @@ function file_cron() {
->condition('changed', REQUEST_TIME - $age, '<') ->condition('changed', REQUEST_TIME - $age, '<')
->range(0, 100) ->range(0, 100)
->execute(); ->execute();
$files = file_load_multiple($fids); $files = $file_storage->loadMultiple($fids);
foreach ($files as $file) { foreach ($files as $file) {
$references = \Drupal::service('file.usage')->listUsage($file); $references = \Drupal::service('file.usage')->listUsage($file);
if (empty($references)) { if (empty($references)) {
...@@ -1225,7 +1226,7 @@ function template_preprocess_file_link(&$variables) { ...@@ -1225,7 +1226,7 @@ function template_preprocess_file_link(&$variables) {
$file = $variables['file']; $file = $variables['file'];
$options = array(); $options = array();
$file_entity = ($file instanceof File) ? $file : file_load($file->fid); $file_entity = ($file instanceof File) ? $file : File::load($file->fid);
$url = file_create_url($file_entity->getFileUri()); $url = file_create_url($file_entity->getFileUri());
$mime_type = $file->getMimeType(); $mime_type = $file->getMimeType();
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\file\Element\ManagedFile; use Drupal\file\Element\ManagedFile;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\file\Entity\File;
/** /**
* Plugin implementation of the 'file_generic' widget. * Plugin implementation of the 'file_generic' widget.
...@@ -346,7 +347,7 @@ public static function validateMultipleCount($element, FormStateInterface $form_ ...@@ -346,7 +347,7 @@ public static function validateMultipleCount($element, FormStateInterface $form_
$removed_files = array_slice($values['fids'], $keep); $removed_files = array_slice($values['fids'], $keep);
$removed_names = array(); $removed_names = array();
foreach ($removed_files as $fid) { foreach ($removed_files as $fid) {
$file = file_load($fid); $file = File::load($fid);
$removed_names[] = $file->getFilename(); $removed_names[] = $file->getFilename();
} }
$args = array('%field' => $field_storage->getFieldName(), '@max' => $field_storage->getCardinality(), '@count' => $keep, '%list' => implode(', ', $removed_names)); $args = array('%field' => $field_storage->getFieldName(), '@max' => $field_storage->getCardinality(), '@count' => $keep, '%list' => implode(', ', $removed_names));
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\file\Entity\File;
/** /**
* Tests the file copy function. * Tests the file copy function.
* *
...@@ -39,7 +41,7 @@ function testNormal() { ...@@ -39,7 +41,7 @@ function testNormal() {
// Reload the file from the database and check that the changes were // Reload the file from the database and check that the changes were
// actually saved. // actually saved.
$this->assertFileUnchanged($result, file_load($result->id(), TRUE)); $this->assertFileUnchanged($result, File::load($result->id()));
} }
/** /**
...@@ -66,9 +68,9 @@ function testExistingRename() { ...@@ -66,9 +68,9 @@ function testExistingRename() {
// Load all the affected files to check the changes that actually made it // Load all the affected files to check the changes that actually made it
// to the database. // to the database.
$loaded_source = file_load($source->id(), TRUE); $loaded_source = File::load($source->id());
$loaded_target = file_load($target->id(), TRUE); $loaded_target = File::load($target->id());
$loaded_result = file_load($result->id(), TRUE); $loaded_result = File::load($result->id());
// Verify that the source file wasn't changed. // Verify that the source file wasn't changed.
$this->assertFileUnchanged($source, $loaded_source); $this->assertFileUnchanged($source, $loaded_source);
...@@ -106,9 +108,9 @@ function testExistingReplace() { ...@@ -106,9 +108,9 @@ function testExistingReplace() {
// Load all the affected files to check the changes that actually made it // Load all the affected files to check the changes that actually made it
// to the database. // to the database.
$loaded_source = file_load($source->id(), TRUE); $loaded_source = File::load($source->id());
$loaded_target = file_load($target->id(), TRUE); $loaded_target = File::load($target->id());
$loaded_result = file_load($result->id(), TRUE); $loaded_result = File::load($result->id());
// Verify that the source file wasn't changed. // Verify that the source file wasn't changed.
$this->assertFileUnchanged($source, $loaded_source); $this->assertFileUnchanged($source, $loaded_source);
...@@ -141,7 +143,7 @@ function testExistingError() { ...@@ -141,7 +143,7 @@ function testExistingError() {
// Check that the correct hooks were called. // Check that the correct hooks were called.
$this->assertFileHooksCalled(array()); $this->assertFileHooksCalled(array());
$this->assertFileUnchanged($source, file_load($source->id(), TRUE)); $this->assertFileUnchanged($source, File::load($source->id()));
$this->assertFileUnchanged($target, file_load($target->id(), TRUE)); $this->assertFileUnchanged($target, File::load($target->id()));
} }
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\file\Entity\File;
/** /**
* Tests the file delete function. * Tests the file delete function.
* *
...@@ -24,7 +26,7 @@ function testUnused() { ...@@ -24,7 +26,7 @@ function testUnused() {
$file->delete(); $file->delete();
$this->assertFileHooksCalled(array('delete')); $this->assertFileHooksCalled(array('delete'));
$this->assertFalse(file_exists($file->getFileUri()), 'Test file has actually been deleted.'); $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::load($file->id()), 'File was removed from the database.');
} }
/** /**
...@@ -40,7 +42,7 @@ function testInUse() { ...@@ -40,7 +42,7 @@ function testInUse() {
$usage = $file_usage->listUsage($file); $usage = $file_usage->listUsage($file);
$this->assertEqual($usage['testing']['test'], array(1 => 1), 'Test file is still in use.'); $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_exists($file->getFileUri()), 'File still exists on the disk.');
$this->assertTrue(file_load($file->id()), 'File still exists in the database.'); $this->assertTrue(File::load($file->id()), 'File still exists in the database.');
// Clear out the call to hook_file_load(). // Clear out the call to hook_file_load().
file_test_reset(); file_test_reset();
...@@ -50,7 +52,7 @@ function testInUse() { ...@@ -50,7 +52,7 @@ function testInUse() {
$this->assertFileHooksCalled(array('load', 'update')); $this->assertFileHooksCalled(array('load', 'update'));
$this->assertTrue(empty($usage), 'File usage data was removed.'); $this->assertTrue(empty($usage), 'File usage data was removed.');
$this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.'); $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.');
$file = file_load($file->id()); $file = File::load($file->id());
$this->assertTrue($file, 'File still exists in the database.'); $this->assertTrue($file, 'File still exists in the database.');
$this->assertTrue($file->isTemporary(), 'File is temporary.'); $this->assertTrue($file->isTemporary(), 'File is temporary.');
file_test_reset(); file_test_reset();
...@@ -69,6 +71,6 @@ function testInUse() { ...@@ -69,6 +71,6 @@ function testInUse() {
// file_cron() loads // file_cron() loads
$this->assertFileHooksCalled(array('delete')); $this->assertFileHooksCalled(array('delete'));
$this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.'); $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::load($file->id()), 'File was removed from the database.');
} }
} }
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\file\Entity\File;
/** /**
* Tests the display of file fields in node and views. * Tests the display of file fields in node and views.
...@@ -57,7 +58,7 @@ function testNodeDisplay() { ...@@ -57,7 +58,7 @@ function testNodeDisplay() {
$node_storage = $this->container->get('entity.manager')->getStorage('node'); $node_storage = $this->container->get('entity.manager')->getStorage('node');
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
$file_link = array( $file_link = array(
'#theme' => 'file_link', '#theme' => 'file_link',
'#file' => $node_file, '#file' => $node_file,
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\file\Entity\File;
/** /**
* Tests that files are uploaded to proper locations. * Tests that files are uploaded to proper locations.
* *
...@@ -29,7 +31,7 @@ function testUploadPath() { ...@@ -29,7 +31,7 @@ function testUploadPath() {
// Check that the file was uploaded to the file root. // Check that the file was uploaded to the file root.
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::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()))); $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. // Change the path to contain multiple subdirectories.
...@@ -41,7 +43,7 @@ function testUploadPath() { ...@@ -41,7 +43,7 @@ function testUploadPath() {
// Check that the file was uploaded into the subdirectory. // Check that the file was uploaded into the subdirectory.
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id, TRUE); $node_file = File::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()))); $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. // Check the path when used with tokens.
...@@ -54,7 +56,7 @@ function testUploadPath() { ...@@ -54,7 +56,7 @@ function testUploadPath() {
// Check that the file was uploaded into the subdirectory. // Check that the file was uploaded into the subdirectory.
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
// Do token replacement using the same user which uploaded the file, not // Do token replacement using the same user which uploaded the file, not
// the user running the test case. // the user running the test case.
$data = array('user' => $this->adminUser); $data = array('user' => $this->adminUser);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\file\Entity\File;
/** /**
* Ensure that files added to nodes appear correctly in RSS feeds. * Ensure that files added to nodes appear correctly in RSS feeds.
...@@ -63,7 +64,7 @@ function testFileFieldRSSContent() { ...@@ -63,7 +64,7 @@ function testFileFieldRSSContent() {
// Get the uploaded file from the node. // Get the uploaded file from the node.
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
// Check that the RSS enclosure appears in the RSS feed. // Check that the RSS enclosure appears in the RSS feed.
$this->drupalGet('rss.xml'); $this->drupalGet('rss.xml');
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\file\Entity\File;
/** /**
* Tests creating and deleting revisions with files attached. * Tests creating and deleting revisions with files attached.
* *
...@@ -40,7 +42,7 @@ function testRevisions() { ...@@ -40,7 +42,7 @@ function testRevisions() {
// Check that the file exists on disk and in the database. // Check that the file exists on disk and in the database.
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file_r1 = file_load($node->{$field_name}->target_id); $node_file_r1 = File::load($node->{$field_name}->target_id);
$node_vid_r1 = $node->getRevisionId(); $node_vid_r1 = $node->getRevisionId();
$this->assertFileExists($node_file_r1, 'New file saved to disk on node creation.'); $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.'); $this->assertFileEntryExists($node_file_r1, 'File entry exists in database on node creation.');
...@@ -50,7 +52,7 @@ function testRevisions() { ...@@ -50,7 +52,7 @@ function testRevisions() {
$this->replaceNodeFile($test_file, $field_name, $nid); $this->replaceNodeFile($test_file, $field_name, $nid);
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file_r2 = file_load($node->{$field_name}->target_id); $node_file_r2 = File::load($node->{$field_name}->target_id);
$node_vid_r2 = $node->getRevisionId(); $node_vid_r2 = $node->getRevisionId();
$this->assertFileExists($node_file_r2, 'Replacement file exists on disk after creating new revision.'); $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.'); $this->assertFileEntryExists($node_file_r2, 'Replacement file entry exists in database after creating new revision.');
...@@ -58,7 +60,7 @@ function testRevisions() { ...@@ -58,7 +60,7 @@ function testRevisions() {
// Check that the original file is still in place on the first revision. // Check that the original file is still in place on the first revision.
$node = node_revision_load($node_vid_r1); $node = node_revision_load($node_vid_r1);
$current_file = file_load($node->{$field_name}->target_id); $current_file = File::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->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->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'); $this->assertFileEntryExists($node_file_r1, 'Original file entry still in place after replacing file in new revision');
...@@ -69,7 +71,7 @@ function testRevisions() { ...@@ -69,7 +71,7 @@ function testRevisions() {
$this->drupalPostForm('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); $this->drupalPostForm('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published'));
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file_r3 = file_load($node->{$field_name}->target_id); $node_file_r3 = File::load($node->{$field_name}->target_id);
$node_vid_r3 = $node->getRevisionId(); $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->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.'); $this->assertFileIsPermanent($node_file_r3, 'New revision file is permanent.');
...@@ -78,7 +80,7 @@ function testRevisions() { ...@@ -78,7 +80,7 @@ function testRevisions() {
$this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); $this->drupalPostForm('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert'));
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file_r4 = file_load($node->{$field_name}->target_id); $node_file_r4 = File::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->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.'); $this->assertFileIsPermanent($node_file_r4, 'Original revision file still permanent after reverting to the original revision.');
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\file\FileInterface; use Drupal\file\FileInterface;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\file\Entity\File;
/** /**
* Provides methods specifically for testing File module's field handling. * Provides methods specifically for testing File module's field handling.
...@@ -45,7 +46,8 @@ function getTestFile($type_name, $size = NULL) { ...@@ -45,7 +46,8 @@ function getTestFile($type_name, $size = NULL) {
// Get a file to upload. // Get a file to upload.
$file = current($this->drupalGetTestFiles($type_name, $size)); $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\file\Entity\File::load().
$file->filesize = filesize($file->uri); $file->filesize = filesize($file->uri);
return entity_create('file', (array) $file); return entity_create('file', (array) $file);
...@@ -221,7 +223,7 @@ function assertFileExists($file, $message = NULL) { ...@@ -221,7 +223,7 @@ function assertFileExists($file, $message = NULL) {
*/ */
function assertFileEntryExists($file, $message = NULL) { function assertFileEntryExists($file, $message = NULL) {
$this->container->get('entity.manager')->getStorage('file')->resetCache(); $this->container->get('entity.manager')->getStorage('file')->resetCache();
$db_file = file_load($file->id()); $db_file = File::load($file->id());
$message = isset($message) ? $message : format_string('File %file exists in database at the correct path.', array('%file' => $file->getFileUri())); $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); $this->assertEqual($db_file->getFileUri(), $file->getFileUri(), $message);
} }
...@@ -240,7 +242,7 @@ function assertFileNotExists($file, $message = NULL) { ...@@ -240,7 +242,7 @@ function assertFileNotExists($file, $message = NULL) {
function assertFileEntryNotExists($file, $message) { function assertFileEntryNotExists($file, $message) {
$this->container->get('entity.manager')->getStorage('file')->resetCache(); $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())); $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); $this->assertFalse(File::load($file->id()), $message);
} }
/** /**
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
/** /**
* Tests validation functions such as file type, max file size, max size per * Tests validation functions such as file type, max file size, max size per
...@@ -44,7 +45,7 @@ function testRequired() { ...@@ -44,7 +45,7 @@ function testRequired() {
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'File exists after uploading to the required field.'); $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.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required field.');
...@@ -63,7 +64,7 @@ function testRequired() { ...@@ -63,7 +64,7 @@ function testRequired() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'File exists after uploading to the required multiple value field.'); $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.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading to the required multiple value field.');
} }
...@@ -95,7 +96,7 @@ function testFileMaxSize() { ...@@ -95,7 +96,7 @@ function testFileMaxSize() {
$nid = $this->uploadNodeFile($small_file, $field_name, $type_name); $nid = $this->uploadNodeFile($small_file, $field_name, $type_name);
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::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->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))); $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 +113,7 @@ function testFileMaxSize() { ...@@ -112,7 +113,7 @@ function testFileMaxSize() {
$nid = $this->uploadNodeFile($large_file, $field_name, $type_name); $nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::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->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())))); $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()))));
} }
...@@ -136,7 +137,7 @@ function testFileExtension() { ...@@ -136,7 +137,7 @@ function testFileExtension() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'File exists after uploading a file with no extension checking.'); $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.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with no extension checking.');
...@@ -155,7 +156,7 @@ function testFileExtension() { ...@@ -155,7 +156,7 @@ function testFileExtension() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'File exists after uploading a file with extension checking.'); $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.'); $this->assertFileEntryExists($node_file, 'File entry exists after uploading a file with extension checking.');
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field_ui\Tests\FieldUiTestTrait; use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\user\RoleInterface; use Drupal\user\RoleInterface;
use Drupal\file\Entity\File;
/** /**
* Tests the file field widget, single and multi-valued, with and without AJAX, * Tests the file field widget, single and multi-valued, with and without AJAX,
...@@ -58,7 +59,7 @@ function testSingleValuedWidget() { ...@@ -58,7 +59,7 @@ function testSingleValuedWidget() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'New file saved to disk on node creation.'); $this->assertFileExists($node_file, 'New file saved to disk on node creation.');
// Ensure the file can be downloaded. // Ensure the file can be downloaded.
...@@ -238,7 +239,7 @@ function testPrivateFileSetting() { ...@@ -238,7 +239,7 @@ function testPrivateFileSetting() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$node_storage->resetCache(array($nid)); $node_storage->resetCache(array($nid));
$node = $node_storage->load($nid); $node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id); $node_file = File::load($node->{$field_name}->target_id);
$this->assertFileExists($node_file, 'New file saved to disk on node creation.'); $this->assertFileExists($node_file, 'New file saved to disk on node creation.');
// Ensure the private file is available to the user who uploaded it. // Ensure the private file is available to the user who uploaded it.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\file\Entity\File;
/** /**
* Tests file listing page functionality. * Tests file listing page functionality.
...@@ -103,7 +104,7 @@ function testFileListingPages() { ...@@ -103,7 +104,7 @@ function testFileListingPages() {
$this->drupalGet('admin/content/files'); $this->drupalGet('admin/content/files');
foreach ($nodes as $node) { foreach ($nodes as $node) {
$file = entity_load('file', $node->file->target_id); $file = File::load($node->file->target_id);
$this->assertText($file->getFilename()); $this->assertText($file->getFilename());
$this->assertLinkByHref(file_create_url($file->getFileUri())); $this->assertLinkByHref(file_create_url($file->getFileUri()));
$this->assertLinkByHref('admin/content/files/usage/' . $file->id()); $this->assertLinkByHref('admin/content/files/usage/' . $file->id());
...@@ -117,11 +118,11 @@ function testFileListingPages() { ...@@ -117,11 +118,11 @@ function testFileListingPages() {
$nodes[1]->save(); $nodes[1]->save();
$this->drupalGet('admin/content/files'); $this->drupalGet('admin/content/files');
$file = entity_load('file', $orphaned_file); $file = File::load($orphaned_file);
$usage = $this->sumUsages($file_usage->listUsage($file)); $usage = $this->sumUsages($file_usage->listUsage($file));
$this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage); $this->assertRaw('admin/content/files/usage/' . $file->id() . '">' . $usage);