diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php index 380e1dca4c2792f74194c808001aaf1acb5e3fd0..281d7b8518d59af2926728c1f65e35960cab0371 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSyncImageTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\file\Entity\File; /** * Tests the field synchronization behavior for the image field. @@ -139,7 +140,7 @@ function testImageFieldSync() { 'uid' => \Drupal::currentUser()->id(), 'status' => FILE_STATUS_PERMANENT, ); - $file = entity_create('file', $field_values); + $file = File::create($field_values); $file->save(); $fid = $file->id(); $this->files[$index]->fid = $fid; diff --git a/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php b/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php index 87809ef512cba1382ac2cf8bf3041663ec40a1fc..aac6ae07f1d81e0731061c0a7b8abcd3486346af 100644 --- a/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php +++ b/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php @@ -8,6 +8,7 @@ namespace Drupal\editor\Tests; use Drupal\Core\Cache\Cache; +use Drupal\file\Entity\File; use Drupal\simpletest\KernelTestBase; use Drupal\filter\FilterPluginCollection; @@ -55,14 +56,14 @@ function testEditorFileReferenceFilter() { }; 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(); $id = $image->id(); $uuid = $image->uuid(); $cache_tag = ['file:' . $id]; 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(); $id_2 = $image_2->id(); $uuid_2 = $image_2->uuid(); diff --git a/core/modules/editor/src/Tests/EditorFileUsageTest.php b/core/modules/editor/src/Tests/EditorFileUsageTest.php index e49ddb144d7655b0183132fe9e76d73fa75ba6c5..750edd300851432ff13e64bfb1be11fc5aac34ad 100644 --- a/core/modules/editor/src/Tests/EditorFileUsageTest.php +++ b/core/modules/editor/src/Tests/EditorFileUsageTest.php @@ -9,6 +9,7 @@ use Drupal\editor\Entity\Editor; use Drupal\node\Entity\NodeType; +use Drupal\file\Entity\File; use Drupal\system\Tests\Entity\EntityUnitTestBase; use Drupal\field\Entity\FieldStorageConfig; use Drupal\Core\Field\FieldStorageDefinitionInterface; @@ -74,7 +75,7 @@ public function testEditorEntityHooks() { $image_entities = array(); foreach ($image_paths as $key => $image_path) { - $image = entity_create('file'); + $image = File::create(); $image->setFileUri($image_path); $image->setFilename(drupal_basename($image->getFileUri())); $image->save(); diff --git a/core/modules/file/file.module b/core/modules/file/file.module index fd170216f73d2c55095fd0c446fed3daa1eed40d..bffb84d27ea38945c047ab846fbbdf86d473689c 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -504,11 +504,11 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM if ($uri = file_unmanaged_save_data($data, $destination, $replace)) { // Create a file entity. - $file = entity_create('file', array( + $file = File::create([ 'uri' => $uri, 'uid' => $user->id(), 'status' => FILE_STATUS_PERMANENT, - )); + ]); // 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 // https://www.drupal.org/node/2241865. @@ -772,7 +772,7 @@ function file_save_upload($form_field_name, $validators = array(), $destination 'filesize' => $file_info->getSize(), ); $values['filemime'] = \Drupal::service('file.mime_type.guesser')->guess($values['filename']); - $file = entity_create('file', $values); + $file = File::create($values); $extensions = ''; if (isset($validators['file_validate_extensions'])) { diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index 903c200d2e1218e366f6f11b753abad7e3ef5e8e..e9cdc24eeb6cef9d319b29af73d60877c8ddd849 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -50,7 +50,7 @@ function getTestFile($type_name, $size = NULL) { // \Drupal\file\Entity\File::load(). $file->filesize = filesize($file->uri); - return entity_create('file', (array) $file); + return File::create((array) $file); } /** diff --git a/core/modules/file/src/Tests/FileItemTest.php b/core/modules/file/src/Tests/FileItemTest.php index 34405358f3fd5ee4beea136f151def0f4bcf82ef..e94f4ee2e82c7ac8d5426dbb1fc63fdc5fa14f29 100644 --- a/core/modules/file/src/Tests/FileItemTest.php +++ b/core/modules/file/src/Tests/FileItemTest.php @@ -13,6 +13,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field\Tests\FieldUnitTestBase; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\file\Entity\File; /** * Tests using entity fields of the file field type. @@ -62,9 +63,9 @@ protected function setUp() { 'settings' => array('file_directory' => $this->directory), ])->save(); file_put_contents('public://example.txt', $this->randomMachineName()); - $this->file = entity_create('file', array( + $this->file = File::create([ 'uri' => 'public://example.txt', - )); + ]); $this->file->save(); } @@ -99,9 +100,9 @@ public function testFileItem() { // Make sure the computed files reflects updates to the file. file_put_contents('public://example-2.txt', $this->randomMachineName()); - $file2 = entity_create('file', array( + $file2 = File::create([ 'uri' => 'public://example-2.txt', - )); + ]); $file2->save(); $entity->file_test->target_id = $file2->id(); @@ -124,9 +125,9 @@ public function testFileItem() { // Make sure the computed files reflects updates to the file. file_put_contents('public://example-3.txt', $this->randomMachineName()); // Test unsaved file entity. - $file3 = entity_create('file', array( + $file3 = File::create([ 'uri' => 'public://example-3.txt', - )); + ]); $display = entity_get_display('entity_test', 'entity_test', 'default'); $display->setComponent('file_test', [ 'label' => 'above', diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php index 72b2378fc383847b1892b59c4e3b26f6f47e5ba8..47612ca131fb73148f33bac57314427493594b4d 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -157,7 +157,7 @@ function testFileListingPages() { */ protected function createFile() { // Create a new file entity. - $file = entity_create('file', array( + $file = File::create([ 'uid' => 1, 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', @@ -165,7 +165,7 @@ protected function createFile() { 'created' => 1, 'changed' => 1, 'status' => FILE_STATUS_PERMANENT, - )); + ]); file_put_contents($file->getFileUri(), 'hello world'); // Save it, inserting a new record. diff --git a/core/modules/file/src/Tests/FileManagedTestBase.php b/core/modules/file/src/Tests/FileManagedTestBase.php index ebaaaea1b881c3c099432792799d51b667db5e2a..04b33aa11750680550811d5918da18a9002bce40 100644 --- a/core/modules/file/src/Tests/FileManagedTestBase.php +++ b/core/modules/file/src/Tests/FileManagedTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\simpletest\WebTestBase; @@ -152,10 +153,10 @@ function assertSameFile(FileInterface $file1, FileInterface $file2) { function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { // Don't count hook invocations caused by creating the file. \Drupal::state()->set('file_test.count_hook_invocations', FALSE); - $file = entity_create('file', array( + $file = File::create([ 'uri' => $this->createUri($filepath, $contents, $scheme), 'uid' => 1, - )); + ]); $file->save(); // Write the record directly rather than using the API so we don't invoke // the hooks. diff --git a/core/modules/file/src/Tests/FileManagedUnitTestBase.php b/core/modules/file/src/Tests/FileManagedUnitTestBase.php index 61e5b25f019cc77dc3f44c6fd79f19a52fa875d9..62ee4c2cde5d9e9a9202f68f4d41b8d18d9ae1ac 100644 --- a/core/modules/file/src/Tests/FileManagedUnitTestBase.php +++ b/core/modules/file/src/Tests/FileManagedUnitTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\simpletest\KernelTestBase; use Drupal\user\Entity\User; @@ -165,10 +166,10 @@ function assertSameFile(FileInterface $file1, FileInterface $file2) { function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { // Don't count hook invocations caused by creating the file. \Drupal::state()->set('file_test.count_hook_invocations', FALSE); - $file = entity_create('file', array( + $file = File::create([ 'uri' => $this->createUri($filepath, $contents, $scheme), 'uid' => 1, - )); + ]); $file->save(); // Write the record directly rather than using the API so we don't invoke // the hooks. diff --git a/core/modules/file/src/Tests/SaveUploadTest.php b/core/modules/file/src/Tests/SaveUploadTest.php index 7c3bd4cf6d19b72c63805f9f65b499e03296817f..9b6a090d82359579ba2ddbb07412879e1f212e52 100644 --- a/core/modules/file/src/Tests/SaveUploadTest.php +++ b/core/modules/file/src/Tests/SaveUploadTest.php @@ -52,7 +52,7 @@ protected function setUp() { $this->drupalLogin($account); $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()); $this->assertTrue(is_file($this->image->getFileUri()), "The image file we're going to upload exists."); diff --git a/core/modules/file/src/Tests/SpaceUsedTest.php b/core/modules/file/src/Tests/SpaceUsedTest.php index 56ed974053daa48921060d0f1f9e7ba5b2cd4493..3a4e8c36b9695b640de1f594705ad590ee0f28cd 100644 --- a/core/modules/file/src/Tests/SpaceUsedTest.php +++ b/core/modules/file/src/Tests/SpaceUsedTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; /** * Tests the spaceUsed() function. @@ -44,11 +45,11 @@ protected function setUp() { */ protected function createFileWithSize($uri, $size, $uid, $status = FILE_STATUS_PERMANENT) { file_put_contents($uri, $this->randomMachineName($size)); - $file = entity_create('file', array( + $file = File::create([ 'uri' => $uri, 'uid' => $uid, 'status' => $status, - )); + ]); $file->save(); return $file; } diff --git a/core/modules/file/src/Tests/ValidatorTest.php b/core/modules/file/src/Tests/ValidatorTest.php index 8ad59396f81c2952a6b2cc84ca130b915ab90677..be3e0986bb92d64c1e5ff6445b7f4391cfb2e412 100644 --- a/core/modules/file/src/Tests/ValidatorTest.php +++ b/core/modules/file/src/Tests/ValidatorTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\file\Tests; +use Drupal\file\Entity\File; /** * Tests the functions used to validate uploaded files. @@ -31,11 +32,11 @@ class ValidatorTest extends FileManagedUnitTestBase { protected function setUp() { parent::setUp(); - $this->image = entity_create('file'); + $this->image = File::create(); $this->image->setFileUri('core/misc/druplicon.png'); $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->setFilename(drupal_basename($this->nonImage->getFileUri())); } @@ -44,7 +45,7 @@ protected function setUp() { * Test the file_validate_extensions() function. */ function testFileValidateExtensions() { - $file = entity_create('file', array('filename' => 'asdf.txt')); + $file = File::create(['filename' => 'asdf.txt']); $errors = file_validate_extensions($file, 'asdf txt pork'); $this->assertEqual(count($errors), 0, 'Valid extension accepted.', 'File'); @@ -120,7 +121,7 @@ function testFileValidateImageResolution() { */ function testFileValidateNameLength() { // Create a new file entity. - $file = entity_create('file'); + $file = File::create(); // Add a filename with an allowed length and test it. $file->setFilename(str_repeat('x', 240)); @@ -145,7 +146,7 @@ function testFileValidateNameLength() { */ function testFileValidateSize() { // 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); $this->assertEqual(count($errors), 0, 'No limits means no errors.', 'File'); $errors = file_validate_size($file, 1, 0); diff --git a/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php b/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php index fc795d9610bb3bb352fe3be8d295740c9ff25f1b..c1f1e2c76d67d20966c0b5c8ea0c16141eb4e89a 100644 --- a/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php +++ b/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php @@ -8,6 +8,7 @@ namespace Drupal\file\Tests\Views; use Drupal\field\Entity\FieldConfig; +use Drupal\file\Entity\File; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Views; use Drupal\views\Tests\ViewTestData; @@ -60,7 +61,7 @@ protected function setUp() { * Tests using the views file relationship. */ public function testViewsHandlerRelationshipUserFileData() { - $file = entity_create('file', array( + $file = File::create([ 'fid' => 2, 'uid' => 2, 'filename' => 'image-test.jpg', @@ -69,7 +70,7 @@ public function testViewsHandlerRelationshipUserFileData() { 'created' => 1, 'changed' => 1, 'status' => FILE_STATUS_PERMANENT, - )); + ]); $file->enforceIsNew(); file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png')); $file->save(); diff --git a/core/modules/hal/src/Tests/FileDenormalizeTest.php b/core/modules/hal/src/Tests/FileDenormalizeTest.php index 853b06d74fddaaf87968806cb682917b0705e7cc..b2e6ab59c7ac382e0341e29ab5b18b78c0637676 100644 --- a/core/modules/hal/src/Tests/FileDenormalizeTest.php +++ b/core/modules/hal/src/Tests/FileDenormalizeTest.php @@ -36,7 +36,7 @@ public function testFileDenormalize() { 'status' => FILE_STATUS_PERMANENT, ); // Create a new file entity. - $file = entity_create('file', $file_params); + $file = File::create($file_params); file_put_contents($file->getFileUri(), 'hello world'); $file->save(); diff --git a/core/modules/hal/src/Tests/FileNormalizeTest.php b/core/modules/hal/src/Tests/FileNormalizeTest.php index 64ffd0797b30d6f26a0bc51c24884138558e54b5..67406fb2caf4aeb3df40ab738bb658241aef6f09 100644 --- a/core/modules/hal/src/Tests/FileNormalizeTest.php +++ b/core/modules/hal/src/Tests/FileNormalizeTest.php @@ -8,6 +8,7 @@ namespace Drupal\hal\Tests; use Drupal\Core\Cache\MemoryBackend; +use Drupal\file\Entity\File; use Drupal\hal\Encoder\JsonEncoder; use Drupal\hal\Normalizer\FieldItemNormalizer; use Drupal\hal\Normalizer\FileEntityNormalizer; @@ -65,7 +66,7 @@ public function testNormalize() { 'status' => FILE_STATUS_PERMANENT, ); // Create a new file entity. - $file = entity_create('file', $file_params); + $file = File::create($file_params); file_put_contents($file->getFileUri(), 'hello world'); $file->save(); diff --git a/core/modules/image/src/Tests/FileMoveTest.php b/core/modules/image/src/Tests/FileMoveTest.php index 34c54a711d33359a34519fdb0f65205b3d9b1b38..4c11725e2744b5397529f567fa248d16069c869b 100644 --- a/core/modules/image/src/Tests/FileMoveTest.php +++ b/core/modules/image/src/Tests/FileMoveTest.php @@ -7,6 +7,7 @@ namespace Drupal\image\Tests; +use Drupal\file\Entity\File; use Drupal\simpletest\WebTestBase; use Drupal\image\Entity\ImageStyle; @@ -29,7 +30,7 @@ class FileMoveTest extends WebTestBase { */ function testNormal() { // 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. $styles = ImageStyle::loadMultiple(); diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index 07e7575bc99cb21db105da3bb1972375f037c58b..627bd74c43c9ffd856a1e4db57d07e1a31344984 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -38,12 +38,12 @@ public function testDefaultImages() { $filename = $this->randomMachineName() . "$i"; $desired_filepath = 'public://' . $filename; 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(); } $default_images = array(); 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(); $default_images[$image_target] = $file; } diff --git a/core/modules/image/src/Tests/ImageItemTest.php b/core/modules/image/src/Tests/ImageItemTest.php index 5969c419fa060cce813dd32444074602600f2980..983088f46120e500d87c4d3d51dbcdf2ea6e49c5 100644 --- a/core/modules/image/src/Tests/ImageItemTest.php +++ b/core/modules/image/src/Tests/ImageItemTest.php @@ -13,6 +13,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field\Tests\FieldUnitTestBase; use Drupal\field\Entity\FieldStorageConfig; +use Drupal\file\Entity\File; /** * Tests using entity fields of the image field type. @@ -58,9 +59,9 @@ protected function setUp() { 'bundle' => 'entity_test', ])->save(); 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', - )); + ]); $this->image->save(); $this->imageFactory = $this->container->get('image.factory'); } @@ -91,9 +92,9 @@ public function testImageItem() { // Make sure the computed entity reflects updates to the referenced file. 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', - )); + ]); $image2->save(); $entity->image_test->target_id = $image2->id(); diff --git a/core/modules/image/src/Tests/ImageThemeFunctionTest.php b/core/modules/image/src/Tests/ImageThemeFunctionTest.php index e4f7b177a48edb1b8074c42a42f117ec07072efc..653ba557d2cd3fe47c071c1aba4a4fd92eecdbd1 100644 --- a/core/modules/image/src/Tests/ImageThemeFunctionTest.php +++ b/core/modules/image/src/Tests/ImageThemeFunctionTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Url; use Drupal\field\Entity\FieldConfig; +use Drupal\file\Entity\File; use Drupal\image\Entity\ImageStyle; use Drupal\simpletest\WebTestBase; use Drupal\field\Entity\FieldStorageConfig; @@ -55,9 +56,9 @@ protected function setUp() { 'bundle' => 'entity_test', ])->save(); 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', - )); + ]); $this->image->save(); $this->imageFactory = $this->container->get('image.factory'); } diff --git a/core/modules/image/src/Tests/Views/RelationshipUserImageDataTest.php b/core/modules/image/src/Tests/Views/RelationshipUserImageDataTest.php index 8970a97e238ec2a1f138f4c866c5358c6606f204..0ef0dd160eb86e922ca5e84bbaf931f9fddb1a48 100644 --- a/core/modules/image/src/Tests/Views/RelationshipUserImageDataTest.php +++ b/core/modules/image/src/Tests/Views/RelationshipUserImageDataTest.php @@ -8,6 +8,7 @@ namespace Drupal\image\Tests\Views; use Drupal\field\Entity\FieldConfig; +use Drupal\file\Entity\File; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Views; use Drupal\views\Tests\ViewTestData; @@ -60,7 +61,7 @@ protected function setUp() { * Tests using the views image relationship. */ public function testViewsHandlerRelationshipUserImageData() { - $file = entity_create('file', array( + $file = File::create([ 'fid' => 2, 'uid' => 2, 'filename' => 'image-test.jpg', @@ -69,7 +70,7 @@ public function testViewsHandlerRelationshipUserImageData() { 'created' => 1, 'changed' => 1, 'status' => FILE_STATUS_PERMANENT, - )); + ]); $file->enforceIsNew(); file_put_contents($file->getFileUri(), file_get_contents('core/modules/simpletest/files/image-1.png')); $file->save(); diff --git a/core/modules/locale/src/Tests/LocaleUpdateBase.php b/core/modules/locale/src/Tests/LocaleUpdateBase.php index cc2aed324a71b9baf571938e145d552f26d5d3c2..78c2b39b42fffa99ccc244e9f7df2c9ffb1bf836 100644 --- a/core/modules/locale/src/Tests/LocaleUpdateBase.php +++ b/core/modules/locale/src/Tests/LocaleUpdateBase.php @@ -8,6 +8,7 @@ namespace Drupal\locale\Tests; use Drupal\Core\StreamWrapper\PublicStream; +use Drupal\file\Entity\File; use Drupal\simpletest\WebTestBase; use Drupal\Component\Utility\SafeMarkup; @@ -133,14 +134,14 @@ protected function makePoFile($path, $filename, $timestamp = NULL, array $transl } file_prepare_directory($path, FILE_CREATE_DIRECTORY); - $file = entity_create('file', array( + $file = File::create([ 'uid' => 1, 'filename' => $filename, 'uri' => $path . '/' . $filename, 'filemime' => 'text/x-gettext-translation', 'timestamp' => $timestamp, 'status' => FILE_STATUS_PERMANENT, - )); + ]); file_put_contents($file->getFileUri(), $po_header . $text); touch(drupal_realpath($file->getFileUri()), $timestamp); $file->save(); diff --git a/core/modules/rdf/src/Tests/StandardProfileTest.php b/core/modules/rdf/src/Tests/StandardProfileTest.php index c1cd2a5b063e1d3ed48ad822852687acff227a49..4a812ac705cd4ff72ccc9bbe5abc744831870085 100644 --- a/core/modules/rdf/src/Tests/StandardProfileTest.php +++ b/core/modules/rdf/src/Tests/StandardProfileTest.php @@ -8,6 +8,7 @@ namespace Drupal\rdf\Tests; use Drupal\Core\Url; +use Drupal\file\Entity\File; use Drupal\image\Entity\ImageStyle; use Drupal\node\Entity\NodeType; use Drupal\node\NodeInterface; @@ -140,7 +141,7 @@ protected function setUp() { // Create image. 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(); // Create article. diff --git a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php index ab2ab70fe0640f1068593c4c5d8d021c987d94da..46ddaadc4c0dc23beb85a9db648e9f366456e127 100644 --- a/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/src/Tests/Entity/EntityCrudHookTest.php @@ -231,7 +231,7 @@ public function testFileHooks() { $url = 'public://entity_crud_hook_test.file'; file_put_contents($url, 'Test test test'); - $file = entity_create('file', array( + $file = File::create([ 'fid' => NULL, 'uid' => 1, 'filename' => 'entity_crud_hook_test.file', @@ -241,7 +241,7 @@ public function testFileHooks() { 'status' => 1, 'created' => REQUEST_TIME, 'changed' => REQUEST_TIME, - )); + ]); $this->assertHookMessageOrder(array( 'entity_crud_hook_test_file_create called', diff --git a/core/modules/system/src/Tests/TypedData/TypedDataTest.php b/core/modules/system/src/Tests/TypedData/TypedDataTest.php index c6a7f1c291127c51653459b5449dcdc8572ac81a..8c24946ba80079e2a99f725480db19cadf9139ac 100644 --- a/core/modules/system/src/Tests/TypedData/TypedDataTest.php +++ b/core/modules/system/src/Tests/TypedData/TypedDataTest.php @@ -12,6 +12,7 @@ use Drupal\Core\TypedData\ListDataDefinition; use Drupal\Core\TypedData\MapDataDefinition; use Drupal\Core\TypedData\TypedDataInterface; +use Drupal\file\Entity\File; use Drupal\simpletest\KernelTestBase; use Drupal\Core\Datetime\DrupalDateTime; @@ -247,7 +248,7 @@ public function testGetAndSet() { for ($i = 0; $i < 3; $i++){ $path = "public://example_$i.png"; file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', $path); - $image = entity_create('file', array('uri' => $path)); + $image = File::create(['uri' => $path]); $image->save(); $files[] = $image; } diff --git a/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php b/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php index 8e75e4dab02342fc74ca715413b1fb20ac04289a..8efa45aa9fe938b2e5c7f532d16313790a85487d 100644 --- a/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php +++ b/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php @@ -8,6 +8,7 @@ namespace Drupal\views\Tests\Plugin; use Drupal\Component\Gettext\PoHeader; +use Drupal\file\Entity\File; use Drupal\views\Tests\ViewTestBase; /** @@ -144,7 +145,7 @@ function testNumericFormatPlural() { */ protected function createFile() { // Create a new file entity. - $file = entity_create('file', array( + $file = File::create([ 'uid' => 1, 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', @@ -152,7 +153,7 @@ protected function createFile() { 'created' => 1, 'changed' => 1, 'status' => FILE_STATUS_PERMANENT, - )); + ]); file_put_contents($file->getFileUri(), 'hello world'); // Save it, inserting a new record.