Issue #2641588 by naveenvalecha, Mac_Weber, dimaro, heykarthikwithu: Replace deprecated usage of entity_create('file') with a direct call to File::create()

8.1.x
Nathaniel Catchpole 2016-02-17 15:25:46 +09:00
parent c7af20e47f
commit dc111b405e
25 changed files with 69 additions and 51 deletions

View File

@ -10,6 +10,7 @@ namespace Drupal\content_translation\Tests;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
/** /**
* Tests the field synchronization behavior for the image field. * Tests the field synchronization behavior for the image field.
@ -139,7 +140,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
'uid' => \Drupal::currentUser()->id(), 'uid' => \Drupal::currentUser()->id(),
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
); );
$file = entity_create('file', $field_values); $file = File::create($field_values);
$file->save(); $file->save();
$fid = $file->id(); $fid = $file->id();
$this->files[$index]->fid = $fid; $this->files[$index]->fid = $fid;

View File

@ -8,6 +8,7 @@
namespace Drupal\editor\Tests; namespace Drupal\editor\Tests;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\file\Entity\File;
use Drupal\simpletest\KernelTestBase; use Drupal\simpletest\KernelTestBase;
use Drupal\filter\FilterPluginCollection; use Drupal\filter\FilterPluginCollection;
@ -55,14 +56,14 @@ class EditorFileReferenceFilterTest extends KernelTestBase {
}; };
file_put_contents('public://llama.jpg', $this->randomMachineName()); file_put_contents('public://llama.jpg', $this->randomMachineName());
$image = entity_create('file', array('uri' => 'public://llama.jpg')); $image = File::create(['uri' => 'public://llama.jpg']);
$image->save(); $image->save();
$id = $image->id(); $id = $image->id();
$uuid = $image->uuid(); $uuid = $image->uuid();
$cache_tag = ['file:' . $id]; $cache_tag = ['file:' . $id];
file_put_contents('public://alpaca.jpg', $this->randomMachineName()); file_put_contents('public://alpaca.jpg', $this->randomMachineName());
$image_2 = entity_create('file', array('uri' => 'public://alpaca.jpg')); $image_2 = File::create(['uri' => 'public://alpaca.jpg']);
$image_2->save(); $image_2->save();
$id_2 = $image_2->id(); $id_2 = $image_2->id();
$uuid_2 = $image_2->uuid(); $uuid_2 = $image_2->uuid();

View File

@ -9,6 +9,7 @@ namespace Drupal\editor\Tests;
use Drupal\editor\Entity\Editor; use Drupal\editor\Entity\Editor;
use Drupal\node\Entity\NodeType; use Drupal\node\Entity\NodeType;
use Drupal\file\Entity\File;
use Drupal\system\Tests\Entity\EntityUnitTestBase; use Drupal\system\Tests\Entity\EntityUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
@ -74,7 +75,7 @@ class EditorFileUsageTest extends EntityUnitTestBase {
$image_entities = array(); $image_entities = array();
foreach ($image_paths as $key => $image_path) { foreach ($image_paths as $key => $image_path) {
$image = entity_create('file'); $image = File::create();
$image->setFileUri($image_path); $image->setFileUri($image_path);
$image->setFilename(drupal_basename($image->getFileUri())); $image->setFilename(drupal_basename($image->getFileUri()));
$image->save(); $image->save();

View File

@ -504,11 +504,11 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
if ($uri = file_unmanaged_save_data($data, $destination, $replace)) { if ($uri = file_unmanaged_save_data($data, $destination, $replace)) {
// Create a file entity. // Create a file entity.
$file = entity_create('file', array( $file = File::create([
'uri' => $uri, 'uri' => $uri,
'uid' => $user->id(), 'uid' => $user->id(),
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
)); ]);
// If we are replacing an existing file re-use its database record. // If we are replacing an existing file re-use its database record.
// @todo Do not create a new entity in order to update it. See // @todo Do not create a new entity in order to update it. See
// https://www.drupal.org/node/2241865. // https://www.drupal.org/node/2241865.
@ -772,7 +772,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination
'filesize' => $file_info->getSize(), 'filesize' => $file_info->getSize(),
); );
$values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['filename']); $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['filename']);
$file = entity_create('file', $values); $file = File::create($values);
$extensions = ''; $extensions = '';
if (isset($validators['file_validate_extensions'])) { if (isset($validators['file_validate_extensions'])) {

View File

@ -50,7 +50,7 @@ abstract class FileFieldTestBase extends WebTestBase {
// \Drupal\file\Entity\File::load(). // \Drupal\file\Entity\File::load().
$file->filesize = filesize($file->uri); $file->filesize = filesize($file->uri);
return entity_create('file', (array) $file); return File::create((array) $file);
} }
/** /**

View File

@ -13,6 +13,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase; use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
/** /**
* Tests using entity fields of the file field type. * Tests using entity fields of the file field type.
@ -62,9 +63,9 @@ class FileItemTest extends FieldUnitTestBase {
'settings' => array('file_directory' => $this->directory), 'settings' => array('file_directory' => $this->directory),
])->save(); ])->save();
file_put_contents('public://example.txt', $this->randomMachineName()); file_put_contents('public://example.txt', $this->randomMachineName());
$this->file = entity_create('file', array( $this->file = File::create([
'uri' => 'public://example.txt', 'uri' => 'public://example.txt',
)); ]);
$this->file->save(); $this->file->save();
} }
@ -99,9 +100,9 @@ class FileItemTest extends FieldUnitTestBase {
// Make sure the computed files reflects updates to the file. // Make sure the computed files reflects updates to the file.
file_put_contents('public://example-2.txt', $this->randomMachineName()); file_put_contents('public://example-2.txt', $this->randomMachineName());
$file2 = entity_create('file', array( $file2 = File::create([
'uri' => 'public://example-2.txt', 'uri' => 'public://example-2.txt',
)); ]);
$file2->save(); $file2->save();
$entity->file_test->target_id = $file2->id(); $entity->file_test->target_id = $file2->id();
@ -124,9 +125,9 @@ class FileItemTest extends FieldUnitTestBase {
// Make sure the computed files reflects updates to the file. // Make sure the computed files reflects updates to the file.
file_put_contents('public://example-3.txt', $this->randomMachineName()); file_put_contents('public://example-3.txt', $this->randomMachineName());
// Test unsaved file entity. // Test unsaved file entity.
$file3 = entity_create('file', array( $file3 = File::create([
'uri' => 'public://example-3.txt', 'uri' => 'public://example-3.txt',
)); ]);
$display = entity_get_display('entity_test', 'entity_test', 'default'); $display = entity_get_display('entity_test', 'entity_test', 'default');
$display->setComponent('file_test', [ $display->setComponent('file_test', [
'label' => 'above', 'label' => 'above',

View File

@ -157,7 +157,7 @@ class FileListingTest extends FileFieldTestBase {
*/ */
protected function createFile() { protected function createFile() {
// Create a new file entity. // Create a new file entity.
$file = entity_create('file', array( $file = File::create([
'uid' => 1, 'uid' => 1,
'filename' => 'druplicon.txt', 'filename' => 'druplicon.txt',
'uri' => 'public://druplicon.txt', 'uri' => 'public://druplicon.txt',
@ -165,7 +165,7 @@ class FileListingTest extends FileFieldTestBase {
'created' => 1, 'created' => 1,
'changed' => 1, 'changed' => 1,
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
)); ]);
file_put_contents($file->getFileUri(), 'hello world'); file_put_contents($file->getFileUri(), 'hello world');
// Save it, inserting a new record. // Save it, inserting a new record.

View File

@ -7,6 +7,7 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface; use Drupal\file\FileInterface;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
@ -152,10 +153,10 @@ abstract class FileManagedTestBase extends WebTestBase {
function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) {
// Don't count hook invocations caused by creating the file. // Don't count hook invocations caused by creating the file.
\Drupal::state()->set('file_test.count_hook_invocations', FALSE); \Drupal::state()->set('file_test.count_hook_invocations', FALSE);
$file = entity_create('file', array( $file = File::create([
'uri' => $this->createUri($filepath, $contents, $scheme), 'uri' => $this->createUri($filepath, $contents, $scheme),
'uid' => 1, 'uid' => 1,
)); ]);
$file->save(); $file->save();
// Write the record directly rather than using the API so we don't invoke // Write the record directly rather than using the API so we don't invoke
// the hooks. // the hooks.

View File

@ -7,6 +7,7 @@
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface; use Drupal\file\FileInterface;
use Drupal\simpletest\KernelTestBase; use Drupal\simpletest\KernelTestBase;
use Drupal\user\Entity\User; use Drupal\user\Entity\User;
@ -165,10 +166,10 @@ abstract class FileManagedUnitTestBase extends KernelTestBase {
function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) {
// Don't count hook invocations caused by creating the file. // Don't count hook invocations caused by creating the file.
\Drupal::state()->set('file_test.count_hook_invocations', FALSE); \Drupal::state()->set('file_test.count_hook_invocations', FALSE);
$file = entity_create('file', array( $file = File::create([
'uri' => $this->createUri($filepath, $contents, $scheme), 'uri' => $this->createUri($filepath, $contents, $scheme),
'uid' => 1, 'uid' => 1,
)); ]);
$file->save(); $file->save();
// Write the record directly rather than using the API so we don't invoke // Write the record directly rather than using the API so we don't invoke
// the hooks. // the hooks.

View File

@ -52,7 +52,7 @@ class SaveUploadTest extends FileManagedTestBase {
$this->drupalLogin($account); $this->drupalLogin($account);
$image_files = $this->drupalGetTestFiles('image'); $image_files = $this->drupalGetTestFiles('image');
$this->image = entity_create('file', (array) current($image_files)); $this->image = File::create((array) current($image_files));
list(, $this->imageExtension) = explode('.', $this->image->getFilename()); list(, $this->imageExtension) = explode('.', $this->image->getFilename());
$this->assertTrue(is_file($this->image->getFileUri()), "The image file we're going to upload exists."); $this->assertTrue(is_file($this->image->getFileUri()), "The image file we're going to upload exists.");

View File

@ -6,6 +6,7 @@
*/ */
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\file\Entity\File;
/** /**
* Tests the spaceUsed() function. * Tests the spaceUsed() function.
@ -44,11 +45,11 @@ class SpaceUsedTest extends FileManagedUnitTestBase {
*/ */
protected function createFileWithSize($uri, $size, $uid, $status = FILE_STATUS_PERMANENT) { protected function createFileWithSize($uri, $size, $uid, $status = FILE_STATUS_PERMANENT) {
file_put_contents($uri, $this->randomMachineName($size)); file_put_contents($uri, $this->randomMachineName($size));
$file = entity_create('file', array( $file = File::create([
'uri' => $uri, 'uri' => $uri,
'uid' => $uid, 'uid' => $uid,
'status' => $status, 'status' => $status,
)); ]);
$file->save(); $file->save();
return $file; return $file;
} }

View File

@ -6,6 +6,7 @@
*/ */
namespace Drupal\file\Tests; namespace Drupal\file\Tests;
use Drupal\file\Entity\File;
/** /**
* Tests the functions used to validate uploaded files. * Tests the functions used to validate uploaded files.
@ -31,11 +32,11 @@ class ValidatorTest extends FileManagedUnitTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->image = entity_create('file'); $this->image = File::create();
$this->image->setFileUri('core/misc/druplicon.png'); $this->image->setFileUri('core/misc/druplicon.png');
$this->image->setFilename(drupal_basename($this->image->getFileUri())); $this->image->setFilename(drupal_basename($this->image->getFileUri()));
$this->nonImage = entity_create('file'); $this->nonImage = File::create();
$this->nonImage->setFileUri('core/assets/vendor/jquery/jquery.min.js'); $this->nonImage->setFileUri('core/assets/vendor/jquery/jquery.min.js');
$this->nonImage->setFilename(drupal_basename($this->nonImage->getFileUri())); $this->nonImage->setFilename(drupal_basename($this->nonImage->getFileUri()));
} }
@ -44,7 +45,7 @@ class ValidatorTest extends FileManagedUnitTestBase {
* Test the file_validate_extensions() function. * Test the file_validate_extensions() function.
*/ */
function testFileValidateExtensions() { function testFileValidateExtensions() {
$file = entity_create('file', array('filename' => 'asdf.txt')); $file = File::create(['filename' => 'asdf.txt']);
$errors = file_validate_extensions($file, 'asdf txt pork'); $errors = file_validate_extensions($file, 'asdf txt pork');
$this->assertEqual(count($errors), 0, 'Valid extension accepted.', 'File'); $this->assertEqual(count($errors), 0, 'Valid extension accepted.', 'File');
@ -120,7 +121,7 @@ class ValidatorTest extends FileManagedUnitTestBase {
*/ */
function testFileValidateNameLength() { function testFileValidateNameLength() {
// Create a new file entity. // Create a new file entity.
$file = entity_create('file'); $file = File::create();
// Add a filename with an allowed length and test it. // Add a filename with an allowed length and test it.
$file->setFilename(str_repeat('x', 240)); $file->setFilename(str_repeat('x', 240));
@ -145,7 +146,7 @@ class ValidatorTest extends FileManagedUnitTestBase {
*/ */
function testFileValidateSize() { function testFileValidateSize() {
// Create a file with a size of 1000 bytes, and quotas of only 1 byte. // Create a file with a size of 1000 bytes, and quotas of only 1 byte.
$file = entity_create('file', array('filesize' => 1000)); $file = File::create(['filesize' => 1000]);
$errors = file_validate_size($file, 0, 0); $errors = file_validate_size($file, 0, 0);
$this->assertEqual(count($errors), 0, 'No limits means no errors.', 'File'); $this->assertEqual(count($errors), 0, 'No limits means no errors.', 'File');
$errors = file_validate_size($file, 1, 0); $errors = file_validate_size($file, 1, 0);

View File

@ -8,6 +8,7 @@
namespace Drupal\file\Tests\Views; namespace Drupal\file\Tests\Views;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
@ -60,7 +61,7 @@ class RelationshipUserFileDataTest extends ViewTestBase {
* Tests using the views file relationship. * Tests using the views file relationship.
*/ */
public function testViewsHandlerRelationshipUserFileData() { public function testViewsHandlerRelationshipUserFileData() {
$file = entity_create('file', array( $file = File::create([
'fid' => 2, 'fid' => 2,
'uid' => 2, 'uid' => 2,
'filename' => 'image-test.jpg', 'filename' => 'image-test.jpg',
@ -69,7 +70,7 @@ class RelationshipUserFileDataTest extends ViewTestBase {
'created' => 1, 'created' => 1,
'changed' => 1, 'changed' => 1,
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
)); ]);
$file->enforceIsNew(); $file->enforceIsNew();
file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png')); file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png'));
$file->save(); $file->save();

View File

@ -36,7 +36,7 @@ class FileDenormalizeTest extends WebTestBase {
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
); );
// Create a new file entity. // Create a new file entity.
$file = entity_create('file', $file_params); $file = File::create($file_params);
file_put_contents($file->getFileUri(), 'hello world'); file_put_contents($file->getFileUri(), 'hello world');
$file->save(); $file->save();

View File

@ -8,6 +8,7 @@
namespace Drupal\hal\Tests; namespace Drupal\hal\Tests;
use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\Cache\MemoryBackend;
use Drupal\file\Entity\File;
use Drupal\hal\Encoder\JsonEncoder; use Drupal\hal\Encoder\JsonEncoder;
use Drupal\hal\Normalizer\FieldItemNormalizer; use Drupal\hal\Normalizer\FieldItemNormalizer;
use Drupal\hal\Normalizer\FileEntityNormalizer; use Drupal\hal\Normalizer\FileEntityNormalizer;
@ -65,7 +66,7 @@ class FileNormalizeTest extends NormalizerTestBase {
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
); );
// Create a new file entity. // Create a new file entity.
$file = entity_create('file', $file_params); $file = File::create($file_params);
file_put_contents($file->getFileUri(), 'hello world'); file_put_contents($file->getFileUri(), 'hello world');
$file->save(); $file->save();

View File

@ -7,6 +7,7 @@
namespace Drupal\image\Tests; namespace Drupal\image\Tests;
use Drupal\file\Entity\File;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\image\Entity\ImageStyle; use Drupal\image\Entity\ImageStyle;
@ -29,7 +30,7 @@ class FileMoveTest extends WebTestBase {
*/ */
function testNormal() { function testNormal() {
// Pick a file for testing. // Pick a file for testing.
$file = entity_create('file', (array) current($this->drupalGetTestFiles('image'))); $file = File::create((array) current($this->drupalGetTestFiles('image')));
// Create derivative image. // Create derivative image.
$styles = ImageStyle::loadMultiple(); $styles = ImageStyle::loadMultiple();

View File

@ -38,12 +38,12 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$filename = $this->randomMachineName() . "$i"; $filename = $this->randomMachineName() . "$i";
$desired_filepath = 'public://' . $filename; $desired_filepath = 'public://' . $filename;
file_unmanaged_copy($files[0]->uri, $desired_filepath, FILE_EXISTS_ERROR); file_unmanaged_copy($files[0]->uri, $desired_filepath, FILE_EXISTS_ERROR);
$file = entity_create('file', array('uri' => $desired_filepath, 'filename' => $filename, 'name' => $filename)); $file = File::create(['uri' => $desired_filepath, 'filename' => $filename, 'name' => $filename]);
$file->save(); $file->save();
} }
$default_images = array(); $default_images = array();
foreach (array('field', 'field', 'field2', 'field_new', 'field_new') as $image_target) { foreach (array('field', 'field', 'field2', 'field_new', 'field_new') as $image_target) {
$file = entity_create('file', (array) array_pop($files)); $file = File::create((array) array_pop($files));
$file->save(); $file->save();
$default_images[$image_target] = $file; $default_images[$image_target] = $file;
} }

View File

@ -13,6 +13,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase; use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
/** /**
* Tests using entity fields of the image field type. * Tests using entity fields of the image field type.
@ -58,9 +59,9 @@ class ImageItemTest extends FieldUnitTestBase {
'bundle' => 'entity_test', 'bundle' => 'entity_test',
])->save(); ])->save();
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = entity_create('file', array( $this->image = File::create([
'uri' => 'public://example.jpg', 'uri' => 'public://example.jpg',
)); ]);
$this->image->save(); $this->image->save();
$this->imageFactory = $this->container->get('image.factory'); $this->imageFactory = $this->container->get('image.factory');
} }
@ -91,9 +92,9 @@ class ImageItemTest extends FieldUnitTestBase {
// Make sure the computed entity reflects updates to the referenced file. // Make sure the computed entity reflects updates to the referenced file.
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example-2.jpg'); file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example-2.jpg');
$image2 = entity_create('file', array( $image2 = File::create([
'uri' => 'public://example-2.jpg', 'uri' => 'public://example-2.jpg',
)); ]);
$image2->save(); $image2->save();
$entity->image_test->target_id = $image2->id(); $entity->image_test->target_id = $image2->id();

View File

@ -10,6 +10,7 @@ namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle; use Drupal\image\Entity\ImageStyle;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
@ -55,9 +56,9 @@ class ImageThemeFunctionTest extends WebTestBase {
'bundle' => 'entity_test', 'bundle' => 'entity_test',
])->save(); ])->save();
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = entity_create('file', array( $this->image = File::create([
'uri' => 'public://example.jpg', 'uri' => 'public://example.jpg',
)); ]);
$this->image->save(); $this->image->save();
$this->imageFactory = $this->container->get('image.factory'); $this->imageFactory = $this->container->get('image.factory');
} }

View File

@ -8,6 +8,7 @@
namespace Drupal\image\Tests\Views; namespace Drupal\image\Tests\Views;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Views; use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
@ -60,7 +61,7 @@ class RelationshipUserImageDataTest extends ViewTestBase {
* Tests using the views image relationship. * Tests using the views image relationship.
*/ */
public function testViewsHandlerRelationshipUserImageData() { public function testViewsHandlerRelationshipUserImageData() {
$file = entity_create('file', array( $file = File::create([
'fid' => 2, 'fid' => 2,
'uid' => 2, 'uid' => 2,
'filename' => 'image-test.jpg', 'filename' => 'image-test.jpg',
@ -69,7 +70,7 @@ class RelationshipUserImageDataTest extends ViewTestBase {
'created' => 1, 'created' => 1,
'changed' => 1, 'changed' => 1,
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
)); ]);
$file->enforceIsNew(); $file->enforceIsNew();
file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png')); file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png'));
$file->save(); $file->save();

View File

@ -8,6 +8,7 @@
namespace Drupal\locale\Tests; namespace Drupal\locale\Tests;
use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\file\Entity\File;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\SafeMarkup;
@ -133,14 +134,14 @@ EOF;
} }
file_prepare_directory($path, FILE_CREATE_DIRECTORY); file_prepare_directory($path, FILE_CREATE_DIRECTORY);
$file = entity_create('file', array( $file = File::create([
'uid' => 1, 'uid' => 1,
'filename' => $filename, 'filename' => $filename,
'uri' => $path . '/' . $filename, 'uri' => $path . '/' . $filename,
'filemime' => 'text/x-gettext-translation', 'filemime' => 'text/x-gettext-translation',
'timestamp' => $timestamp, 'timestamp' => $timestamp,
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
)); ]);
file_put_contents($file->getFileUri(), $po_header . $text); file_put_contents($file->getFileUri(), $po_header . $text);
touch(drupal_realpath($file->getFileUri()), $timestamp); touch(drupal_realpath($file->getFileUri()), $timestamp);
$file->save(); $file->save();

View File

@ -8,6 +8,7 @@
namespace Drupal\rdf\Tests; namespace Drupal\rdf\Tests;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle; use Drupal\image\Entity\ImageStyle;
use Drupal\node\Entity\NodeType; use Drupal\node\Entity\NodeType;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
@ -140,7 +141,7 @@ class StandardProfileTest extends WebTestBase {
// Create image. // Create image.
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = entity_create('file', array('uri' => 'public://example.jpg')); $this->image = File::create(['uri' => 'public://example.jpg']);
$this->image->save(); $this->image->save();
// Create article. // Create article.

View File

@ -231,7 +231,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
$url = 'public://entity_crud_hook_test.file'; $url = 'public://entity_crud_hook_test.file';
file_put_contents($url, 'Test test test'); file_put_contents($url, 'Test test test');
$file = entity_create('file', array( $file = File::create([
'fid' => NULL, 'fid' => NULL,
'uid' => 1, 'uid' => 1,
'filename' => 'entity_crud_hook_test.file', 'filename' => 'entity_crud_hook_test.file',
@ -241,7 +241,7 @@ class EntityCrudHookTest extends EntityUnitTestBase {
'status' => 1, 'status' => 1,
'created' => REQUEST_TIME, 'created' => REQUEST_TIME,
'changed' => REQUEST_TIME, 'changed' => REQUEST_TIME,
)); ]);
$this->assertHookMessageOrder(array( $this->assertHookMessageOrder(array(
'entity_crud_hook_test_file_create called', 'entity_crud_hook_test_file_create called',

View File

@ -12,6 +12,7 @@ use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\ListDataDefinition; use Drupal\Core\TypedData\ListDataDefinition;
use Drupal\Core\TypedData\MapDataDefinition; use Drupal\Core\TypedData\MapDataDefinition;
use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\file\Entity\File;
use Drupal\simpletest\KernelTestBase; use Drupal\simpletest\KernelTestBase;
use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Datetime\DrupalDateTime;
@ -247,7 +248,7 @@ class TypedDataTest extends KernelTestBase {
for ($i = 0; $i < 3; $i++){ for ($i = 0; $i < 3; $i++){
$path = "public://example_$i.png"; $path = "public://example_$i.png";
file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', $path); file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', $path);
$image = entity_create('file', array('uri' => $path)); $image = File::create(['uri' => $path]);
$image->save(); $image->save();
$files[] = $image; $files[] = $image;
} }

View File

@ -8,6 +8,7 @@
namespace Drupal\views\Tests\Plugin; namespace Drupal\views\Tests\Plugin;
use Drupal\Component\Gettext\PoHeader; use Drupal\Component\Gettext\PoHeader;
use Drupal\file\Entity\File;
use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestBase;
/** /**
@ -144,7 +145,7 @@ class NumericFormatPluralTest extends ViewTestBase {
*/ */
protected function createFile() { protected function createFile() {
// Create a new file entity. // Create a new file entity.
$file = entity_create('file', array( $file = File::create([
'uid' => 1, 'uid' => 1,
'filename' => 'druplicon.txt', 'filename' => 'druplicon.txt',
'uri' => 'public://druplicon.txt', 'uri' => 'public://druplicon.txt',
@ -152,7 +153,7 @@ class NumericFormatPluralTest extends ViewTestBase {
'created' => 1, 'created' => 1,
'changed' => 1, 'changed' => 1,
'status' => FILE_STATUS_PERMANENT, 'status' => FILE_STATUS_PERMANENT,
)); ]);
file_put_contents($file->getFileUri(), 'hello world'); file_put_contents($file->getFileUri(), 'hello world');
// Save it, inserting a new record. // Save it, inserting a new record.