From 9986216a70f75e54bf14c3088897fcbcb2862adc Mon Sep 17 00:00:00 2001
From: Mac_Weber <Mac_Weber@789986.no-reply.drupal.org>
Date: Fri, 4 Mar 2016 18:56:47 -0300
Subject: [PATCH] Issue #2641518 by Mac_Weber, heykarthikwithu, nesta_,
 rakesh.gectcr, aditya_anurag, anchal29: Replace deprecated usage of 
 entity_create('config_test') with a direct call to ConfigTest::create()

---
 core/modules/config/src/Tests/ConfigDiffTest.php         |  2 +-
 .../config/src/Tests/ConfigEntityNormalizeTest.php       |  2 +-
 core/modules/config/src/Tests/ConfigEntityStatusTest.php |  2 +-
 core/modules/config/src/Tests/ConfigEntityTest.php       | 16 ++++++++--------
 .../src/Tests/ConfigImportRenameValidationTest.php       |  2 +-
 .../src/Tests/ConfigTranslationOverviewTest.php          |  2 +-
 .../EntityReference/EntityReferenceIntegrationTest.php   |  4 ++--
 core/modules/file/file.module                            |  1 +
 core/modules/file/src/Element/ManagedFile.php            |  1 +
 .../file/src/Plugin/Field/FieldWidget/FileWidget.php     |  1 +
 core/modules/file/tests/file_test/file_test.module       |  1 +
 core/modules/image/image.module                          |  1 +
 .../image/src/Plugin/Field/FieldType/ImageItem.php       |  1 +
 .../image/src/Plugin/Field/FieldWidget/ImageWidget.php   |  1 +
 .../system/src/Tests/Entity/ConfigEntityQueryTest.php    |  6 +++---
 15 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/core/modules/config/src/Tests/ConfigDiffTest.php b/core/modules/config/src/Tests/ConfigDiffTest.php
index 1f32b27..6eba680 100644
--- a/core/modules/config/src/Tests/ConfigDiffTest.php
+++ b/core/modules/config/src/Tests/ConfigDiffTest.php
@@ -81,7 +81,7 @@ function testDiff() {
 
     // Test diffing a renamed config entity.
     $test_entity_id = $this->randomMachineName();
-    $test_entity = entity_create('config_test', array(
+    $test_entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'id' => $test_entity_id,
       'label' => $this->randomMachineName(),
     ));
diff --git a/core/modules/config/src/Tests/ConfigEntityNormalizeTest.php b/core/modules/config/src/Tests/ConfigEntityNormalizeTest.php
index 7e0acef..2f5b16d 100644
--- a/core/modules/config/src/Tests/ConfigEntityNormalizeTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityNormalizeTest.php
@@ -29,7 +29,7 @@ protected function setUp() {
   }
 
   public function testNormalize() {
-    $config_entity = entity_create('config_test', array('id' => 'system', 'label' => 'foobar', 'weight' => 1));
+    $config_entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array('id' => 'system', 'label' => 'foobar', 'weight' => 1));
     $config_entity->save();
 
     // Modify stored config entity, this is comparable with a schema change.
diff --git a/core/modules/config/src/Tests/ConfigEntityStatusTest.php b/core/modules/config/src/Tests/ConfigEntityStatusTest.php
index caad767..bbc4b21 100644
--- a/core/modules/config/src/Tests/ConfigEntityStatusTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityStatusTest.php
@@ -27,7 +27,7 @@ class ConfigEntityStatusTest extends KernelTestBase {
    * Tests the enabling/disabling of entities.
    */
   function testCRUD() {
-    $entity = entity_create('config_test', array(
+    $entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'id' => strtolower($this->randomMachineName()),
     ));
     $this->assertTrue($entity->status(), 'Default status is enabled.');
diff --git a/core/modules/config/src/Tests/ConfigEntityTest.php b/core/modules/config/src/Tests/ConfigEntityTest.php
index 13ab721..a833a66 100644
--- a/core/modules/config/src/Tests/ConfigEntityTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityTest.php
@@ -40,7 +40,7 @@ class ConfigEntityTest extends WebTestBase {
   function testCRUD() {
     $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
     // Verify default properties on a newly created empty entity.
-    $empty = entity_create('config_test');
+    $empty = $this->container->get('entity_type.manager')->getStorage('config_test')->create();
     $this->assertTrue($empty->uuid());
     $this->assertIdentical($empty->label, NULL);
     $this->assertIdentical($empty->style, NULL);
@@ -81,7 +81,7 @@ function testCRUD() {
     }
 
     // Verify that an entity with an empty ID string is considered empty, too.
-    $empty_id = entity_create('config_test', array(
+    $empty_id = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'id' => '',
     ));
     $this->assertIdentical($empty_id->isNew(), TRUE);
@@ -94,7 +94,7 @@ function testCRUD() {
     }
 
     // Verify properties on a newly created entity.
-    $config_test = entity_create('config_test', $expected = array(
+    $config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create($expected = array(
       'id' => $this->randomMachineName(),
       'label' => $this->randomString(),
       'style' => $this->randomMachineName(),
@@ -146,7 +146,7 @@ function testCRUD() {
     // maximum allowed length, but not longer.
 
     // Test with a short ID.
-    $id_length_config_test = entity_create('config_test', array(
+    $id_length_config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'id' => $this->randomMachineName(8),
     ));
     try {
@@ -160,7 +160,7 @@ function testCRUD() {
     }
 
     // Test with an ID of the maximum allowed length.
-    $id_length_config_test = entity_create('config_test', array(
+    $id_length_config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'id' => $this->randomMachineName(static::MAX_ID_LENGTH),
     ));
     try {
@@ -174,7 +174,7 @@ function testCRUD() {
     }
 
     // Test with an ID exceeding the maximum allowed length.
-    $id_length_config_test = entity_create('config_test', array(
+    $id_length_config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'id' => $this->randomMachineName(static::MAX_ID_LENGTH + 1),
     ));
     try {
@@ -193,7 +193,7 @@ function testCRUD() {
 
     // Ensure that creating an entity with the same id as an existing one is not
     // possible.
-    $same_id = entity_create('config_test', array(
+    $same_id = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'id' => $config_test->id(),
     ));
     $this->assertIdentical($same_id->isNew(), TRUE);
@@ -227,7 +227,7 @@ function testCRUD() {
 
     // Test config entity prepopulation.
     \Drupal::state()->set('config_test.prepopulate', TRUE);
-    $config_test = entity_create('config_test', array('foo' => 'bar'));
+    $config_test = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array('foo' => 'bar'));
     $this->assertEqual($config_test->get('foo'), 'baz', 'Initial value correctly populated');
   }
 
diff --git a/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php b/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php
index fe4df02..9d3da93 100644
--- a/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php
+++ b/core/modules/config/src/Tests/ConfigImportRenameValidationTest.php
@@ -72,7 +72,7 @@ protected function setUp() {
   public function testRenameValidation() {
     // Create a test entity.
     $test_entity_id = $this->randomMachineName();
-    $test_entity = entity_create('config_test', array(
+    $test_entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'id' => $test_entity_id,
       'label' => $this->randomMachineName(),
     ));
diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php
index 13b56d5..76c4e9a 100644
--- a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php
+++ b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php
@@ -95,7 +95,7 @@ public function testMapperListPage() {
     );
 
     foreach ($labels as $label) {
-      $test_entity = entity_create('config_test', array(
+      $test_entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
         'id' => $this->randomMachineName(),
         'label' => $label,
       ));
diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php
index ef536f4..851b803 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceIntegrationTest.php
@@ -198,9 +198,9 @@ protected function assertFieldValues($entity_name, $referenced_entities) {
    *   An array of entity objects.
    */
   protected function getTestEntities() {
-    $config_entity_1 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName()));
+    $config_entity_1 = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName()));
     $config_entity_1->save();
-    $config_entity_2 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName()));
+    $config_entity_2 = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName()));
     $config_entity_2->save();
 
     $content_entity_1 = EntityTest::create(array('name' => $this->randomMachineName()));
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 310eb26..fae7b95 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -18,6 +18,7 @@
 use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Template\Attribute;
+use Drupal\config_test\Entity\ConfigTest;
 
 // Load all Field module hooks for File.
 require_once __DIR__ . '/file.field.inc';
diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php
index 305cda1..ebbb44c 100644
--- a/core/modules/file/src/Element/ManagedFile.php
+++ b/core/modules/file/src/Element/ManagedFile.php
@@ -16,6 +16,7 @@
 use Drupal\Core\Url;
 use Drupal\file\Entity\File;
 use Symfony\Component\HttpFoundation\Request;
+use Drupal\config_test\Entity\ConfigTest;
 
 /**
  * Provides an AJAX/progress aware widget for uploading and saving a file.
diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
index 9b120c6..3bdaa43 100644
--- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
+++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
@@ -21,6 +21,7 @@
 use Drupal\file\Entity\File;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\Validator\ConstraintViolationListInterface;
+use Drupal\config_test\Entity\ConfigTest;
 
 /**
  * Plugin implementation of the 'file_generic' widget.
diff --git a/core/modules/file/tests/file_test/file_test.module b/core/modules/file/tests/file_test/file_test.module
index 7b25af4..2d2d706 100644
--- a/core/modules/file/tests/file_test/file_test.module
+++ b/core/modules/file/tests/file_test/file_test.module
@@ -9,6 +9,7 @@
  */
 
 use Drupal\file\Entity\File;
+use Drupal\config_test\Entity\ConfigTest;
 
 const FILE_URL_TEST_CDN_1 = 'http://cdn1.example.com';
 const FILE_URL_TEST_CDN_2 = 'http://cdn2.example.com';
diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index 7f8314a..cbec601 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -11,6 +11,7 @@
 use Drupal\field\FieldStorageConfigInterface;
 use Drupal\field\FieldConfigInterface;
 use Drupal\image\Entity\ImageStyle;
+use Drupal\config_test\Entity\ConfigTest;
 
 /**
  * Image style constant for user presets in the database.
diff --git a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
index a867b9e..aaf5199 100644
--- a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
+++ b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
@@ -15,6 +15,7 @@
 use Drupal\Core\TypedData\DataDefinition;
 use Drupal\file\Entity\File;
 use Drupal\file\Plugin\Field\FieldType\FileItem;
+use Drupal\config_test\Entity\ConfigTest;
 
 /**
  * Plugin implementation of the 'image' field type.
diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
index 7d70e29..86901d4 100644
--- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
+++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
@@ -14,6 +14,7 @@
 use Drupal\file\Entity\File;
 use Drupal\file\Plugin\Field\FieldWidget\FileWidget;
 use Drupal\image\Entity\ImageStyle;
+use Drupal\config_test\Entity\ConfigTest;
 
 /**
  * Plugin implementation of the 'image_image' widget.
diff --git a/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php b/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php
index 09a21d2..4d0cec3 100644
--- a/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php
+++ b/core/modules/system/src/Tests/Entity/ConfigEntityQueryTest.php
@@ -604,7 +604,7 @@ public function testLookupKeys() {
     $key_value = $this->container->get('keyvalue')->get(QueryFactory::CONFIG_LOOKUP_PREFIX . 'config_test');
 
     $test_entities = [];
-    $entity = entity_create('config_test', array(
+    $entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'label' => $this->randomMachineName(),
       'id' => '1',
       'style' => 'test',
@@ -617,7 +617,7 @@ public function testLookupKeys() {
     $expected[] = $entity->getConfigDependencyName();
     $this->assertEqual($expected, $key_value->get('style:test'));
 
-    $entity = entity_create('config_test', array(
+    $entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'label' => $this->randomMachineName(),
       'id' => '2',
       'style' => 'test',
@@ -628,7 +628,7 @@ public function testLookupKeys() {
     $expected[] = $entity->getConfigDependencyName();
     $this->assertEqual($expected, $key_value->get('style:test'));
 
-    $entity = entity_create('config_test', array(
+    $entity = $this->container->get('entity_type.manager')->getStorage('config_test')->create(array(
       'label' => $this->randomMachineName(),
       'id' => '3',
       'style' => 'blah',
-- 
2.1.4

