summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-03-04 00:25:41 (GMT)
committerNathaniel Catchpole2016-03-04 00:25:41 (GMT)
commit0e454b550fb136737d3da81204be7b99a202e964 (patch)
tree597b7b630345f823d760c05265db9a66de8a7aff
parentce88723715f4a76c76fa11e6684256ca9c81ad70 (diff)
Issue #2502917 by dimaro, rakesh.gectcr, DuaelFr, suhel.rangnekar: Replace deprecated usage of entity_create used with variable entity types with a direct call to EntityManager::getStorage()->create()
-rw-r--r--core/modules/config/src/Tests/ConfigEntityStaticCacheTest.php5
-rw-r--r--core/modules/config/src/Tests/ConfigEntityStorageTest.php5
-rw-r--r--core/modules/content_translation/src/Tests/ContentTranslationTestBase.php4
-rw-r--r--core/modules/field/field.module4
-rw-r--r--core/modules/field/src/Tests/BulkDeleteTest.php4
-rw-r--r--core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php16
-rw-r--r--core/modules/field/src/Tests/FieldAttachOtherTest.php16
-rw-r--r--core/modules/field/src/Tests/FieldAttachStorageTest.php32
-rw-r--r--core/modules/field/src/Tests/FieldDataCountTest.php6
-rw-r--r--core/modules/field/src/Tests/FormTest.php4
-rw-r--r--core/modules/field/src/Tests/NestedFormTest.php8
-rw-r--r--core/modules/field/src/Tests/TranslationTest.php8
-rw-r--r--core/modules/field/src/Tests/TranslationWebTest.php4
-rw-r--r--core/modules/rdf/src/Tests/Field/EntityReferenceRdfaTest.php8
-rw-r--r--core/modules/rest/src/Tests/CsrfTest.php4
-rw-r--r--core/modules/rest/src/Tests/RESTTestBase.php4
-rw-r--r--core/modules/rest/src/Tests/UpdateTest.php4
-rw-r--r--core/modules/system/src/Tests/Entity/EntityApiTest.php12
-rw-r--r--core/modules/system/src/Tests/Entity/EntityAutocompleteTest.php14
-rw-r--r--core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php26
-rw-r--r--core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php4
-rw-r--r--core/modules/system/src/Tests/Entity/EntityFieldTest.php52
-rw-r--r--core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php28
-rw-r--r--core/modules/system/src/Tests/Entity/EntityRevisionsTest.php10
-rw-r--r--core/modules/system/src/Tests/Entity/EntityTranslationTest.php44
-rw-r--r--core/modules/system/src/Tests/Entity/EntityUUIDTest.php14
-rw-r--r--core/modules/system/src/Tests/Entity/EntityValidationTest.php4
-rw-r--r--core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php32
-rw-r--r--core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php4
-rw-r--r--core/modules/text/src/Tests/Formatter/TextFormatterTest.php4
-rw-r--r--core/modules/text/src/Tests/TextWithSummaryItemTest.php8
31 files changed, 269 insertions, 123 deletions
diff --git a/core/modules/config/src/Tests/ConfigEntityStaticCacheTest.php b/core/modules/config/src/Tests/ConfigEntityStaticCacheTest.php
index 6b30269..e36331c 100644
--- a/core/modules/config/src/Tests/ConfigEntityStaticCacheTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityStaticCacheTest.php
@@ -45,7 +45,10 @@ class ConfigEntityStaticCacheTest extends KernelTestBase {
parent::setUp();
$this->entityTypeId = 'config_test';
$this->entityId = 'test_1';
- entity_create($this->entityTypeId, array('id' => $this->entityId, 'label' => 'Original label'))->save();
+ $this->container->get('entity_type.manager')
+ ->getStorage($this->entityTypeId)
+ ->create(array('id' => $this->entityId, 'label' => 'Original label'))
+ ->save();
}
/**
diff --git a/core/modules/config/src/Tests/ConfigEntityStorageTest.php b/core/modules/config/src/Tests/ConfigEntityStorageTest.php
index dea998b..0eb1ab6 100644
--- a/core/modules/config/src/Tests/ConfigEntityStorageTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityStorageTest.php
@@ -32,7 +32,10 @@ class ConfigEntityStorageTest extends KernelTestBase {
$entity_type = 'config_test';
$id = 'test_1';
// Load the original configuration entity.
- entity_create($entity_type, array('id' => $id))->save();
+ $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => $id))
+ ->save();
$entity = entity_load($entity_type, $id);
$original_properties = $entity->toArray();
diff --git a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php
index 9a93ba2..09c13cc 100644
--- a/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php
+++ b/core/modules/content_translation/src/Tests/ContentTranslationTestBase.php
@@ -234,7 +234,9 @@ abstract class ContentTranslationTestBase extends WebTestBase {
}
}
}
- $entity = entity_create($this->entityTypeId, $entity_values);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityTypeId)
+ ->create($entity_values);
$entity->save();
return $entity->id();
}
diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index ce65c79..e453c46 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -292,7 +292,9 @@ function _field_create_entity_from_ids($ids) {
if (isset($ids->bundle) && $bundle_key = $entity_type->getKey('bundle')) {
$id_properties[$bundle_key] = $ids->bundle;
}
- return entity_create($ids->entity_type, $id_properties);
+ return \Drupal::entityTypeManager()
+ ->getStorage($ids->entity_type)
+ ->create($id_properties);
}
/**
diff --git a/core/modules/field/src/Tests/BulkDeleteTest.php b/core/modules/field/src/Tests/BulkDeleteTest.php
index 2c7835f..2949867 100644
--- a/core/modules/field/src/Tests/BulkDeleteTest.php
+++ b/core/modules/field/src/Tests/BulkDeleteTest.php
@@ -133,7 +133,9 @@ class BulkDeleteTest extends FieldUnitTestBase {
])->save();
}
for ($i = 0; $i < 10; $i++) {
- $entity = entity_create($this->entityTypeId, array('type' => $bundle));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityTypeId)
+ ->create(array('type' => $bundle));
foreach ($this->fieldStorages as $field_storage) {
$entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality()));
}
diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
index 8e1948d..a53a2fb 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
@@ -108,7 +108,9 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
))->save();
// Create the entity to be referenced.
- $this->referencedEntity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
+ $this->referencedEntity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => $this->randomMachineName()));
$this->referencedEntity->body = array(
'value' => '<p>Hello, world!</p>',
'format' => 'full_html',
@@ -116,7 +118,9 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
$this->referencedEntity->save();
// Create another entity to be referenced but do not save it.
- $this->unsavedReferencedEntity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
+ $this->unsavedReferencedEntity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => $this->randomMachineName()));
$this->unsavedReferencedEntity->body = array(
'value' => '<p>Hello, unsaved world!</p>',
'format' => 'full_html',
@@ -134,7 +138,9 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
$field_name = $this->fieldName;
- $referencing_entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
+ $referencing_entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => $this->randomMachineName()));
$referencing_entity->save();
$referencing_entity->{$field_name}->entity = $this->referencedEntity;
@@ -286,7 +292,9 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
*/
protected function buildRenderArray(array $referenced_entities, $formatter, $formatter_options = array()) {
// Create the entity that will have the entity reference field.
- $referencing_entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
+ $referencing_entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => $this->randomMachineName()));
$items = $referencing_entity->get($this->fieldName);
diff --git a/core/modules/field/src/Tests/FieldAttachOtherTest.php b/core/modules/field/src/Tests/FieldAttachOtherTest.php
index 37c6fec..6c67793 100644
--- a/core/modules/field/src/Tests/FieldAttachOtherTest.php
+++ b/core/modules/field/src/Tests/FieldAttachOtherTest.php
@@ -32,7 +32,9 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
$this->createFieldWithStorage('_2');
$entity_type = 'entity_test';
- $entity_init = entity_create($entity_type);
+ $entity_init = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
// Populate values to be displayed.
$values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality());
@@ -186,9 +188,11 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
$entity_type = 'entity_test_rev';
$this->createFieldWithStorage('_2', $entity_type);
- $entity_init = entity_create($entity_type, array(
- 'type' => $entity_type,
- ));
+ $entity_init = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'type' => $entity_type,
+ ));
// Check that no initial cache entry is present.
$cid = "values:$entity_type:" . $entity->id();
@@ -293,7 +297,9 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
$this->createFieldWithStorage('_2');
$entity_type = 'entity_test';
- $entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->field->getTargetBundle()));
+ $entity_init = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => 1, 'revision_id' => 1, 'type' => $this->fieldTestData->field->getTargetBundle()));
// Build the form for all fields.
$display = entity_get_form_display($entity_type, $this->fieldTestData->field->getTargetBundle(), 'default');
diff --git a/core/modules/field/src/Tests/FieldAttachStorageTest.php b/core/modules/field/src/Tests/FieldAttachStorageTest.php
index d700334..596eb13 100644
--- a/core/modules/field/src/Tests/FieldAttachStorageTest.php
+++ b/core/modules/field/src/Tests/FieldAttachStorageTest.php
@@ -37,7 +37,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
// TODO : test empty values filtering and "compression" (store consecutive deltas).
// Preparation: create three revisions and store them in $revision array.
$values = array();
- $entity = entity_create($entity_type);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
for ($revision_id = 0; $revision_id < 3; $revision_id++) {
// Note: we try to insert one extra value.
$current_values = $this->_generateTestFieldValues($cardinality + 1);
@@ -114,7 +116,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
// Create one test entity per bundle, with random values.
foreach ($bundles as $index => $bundle) {
- $entities[$index] = entity_create($entity_type, array('id' => $index, 'revision_id' => $index, 'type' => $bundle));
+ $entities[$index] = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => $index, 'revision_id' => $index, 'type' => $bundle));
$entity = clone($entities[$index]);
foreach ($field_names as $field_name) {
if (!$entity->hasField($field_name)) {
@@ -149,7 +153,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
$entity_type = 'entity_test';
$this->createFieldWithStorage('', $entity_type);
- $entity_init = entity_create($entity_type, array('id' => 1));
+ $entity_init = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => 1));
// Insert: Field is NULL.
$entity = clone $entity_init;
@@ -200,7 +206,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
$this->fieldTestData->field->save();
// Verify that fields are populated with default values.
- $entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1));
+ $entity_init = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => 1, 'revision_id' => 1));
$default = field_test_default_value($entity_init, $this->fieldTestData->field);
$this->assertEqual($entity_init->{$this->fieldTestData->field_name}->getValue(), $default, 'Default field value correctly populated.');
@@ -213,7 +221,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
// Verify that prepopulated field values are not overwritten by defaults.
$value = array(array('value' => $default[0]['value'] - mt_rand(1, 127)));
- $entity = entity_create($entity_type, array('type' => $entity_init->bundle(), $this->fieldTestData->field_name => $value));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('type' => $entity_init->bundle(), $this->fieldTestData->field_name => $value));
$this->assertEqual($entity->{$this->fieldTestData->field_name}->getValue(), $value, 'Prepopulated field value correctly maintained.');
}
@@ -224,7 +234,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
$entity_type = 'entity_test_rev';
$this->createFieldWithStorage('', $entity_type);
$cardinality = $this->fieldTestData->field_storage->getCardinality();
- $entity = entity_create($entity_type, array('type' => $this->fieldTestData->field->getTargetBundle()));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('type' => $this->fieldTestData->field->getTargetBundle()));
$vids = array();
// Create revision 0
@@ -292,7 +304,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
FieldConfig::create($this->fieldTestData->field_definition)->save();
// Save an entity with data in the field.
- $entity = entity_create($entity_type, array('type' => $this->fieldTestData->field->getTargetBundle()));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('type' => $this->fieldTestData->field->getTargetBundle()));
$values = $this->_generateTestFieldValues($cardinality);
$entity->{$this->fieldTestData->field_name} = $values;
@@ -336,7 +350,9 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
FieldConfig::create($field)->save();
// Save an entity with data for both fields
- $entity = entity_create($entity_type, array('type' => $this->fieldTestData->field->getTargetBundle()));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('type' => $this->fieldTestData->field->getTargetBundle()));
$values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality());
$entity->{$this->fieldTestData->field_name} = $values;
$entity->{$field_name} = $this->_generateTestFieldValues(1);
diff --git a/core/modules/field/src/Tests/FieldDataCountTest.php b/core/modules/field/src/Tests/FieldDataCountTest.php
index a844b05..c146289 100644
--- a/core/modules/field/src/Tests/FieldDataCountTest.php
+++ b/core/modules/field/src/Tests/FieldDataCountTest.php
@@ -115,9 +115,9 @@ class FieldDataCountTest extends FieldUnitTestBase {
$entity_type = 'entity_test_rev';
$this->createFieldWithStorage('_2', $entity_type);
- $entity_init = entity_create($entity_type, array(
- 'type' => $entity_type,
- ));
+ $entity_init = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('type' => $entity_type,));
$cardinality = $this->fieldTestData->field_storage_2->getCardinality();
$this->assertIdentical($this->fieldTestData->field_storage_2->hasData(), FALSE, 'There are no entities with field data.');
diff --git a/core/modules/field/src/Tests/FormTest.php b/core/modules/field/src/Tests/FormTest.php
index c629ca7..79ba7d1 100644
--- a/core/modules/field/src/Tests/FormTest.php
+++ b/core/modules/field/src/Tests/FormTest.php
@@ -543,7 +543,9 @@ class FormTest extends FieldTestBase {
// Test that the form structure includes full information for each delta
// apart from #access.
- $entity = entity_create($entity_type, array('id' => 0, 'revision_id' => 0));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => 0, 'revision_id' => 0));
$display = entity_get_form_display($entity_type, $entity_type, 'default');
$form = array();
diff --git a/core/modules/field/src/Tests/NestedFormTest.php b/core/modules/field/src/Tests/NestedFormTest.php
index ac5dca4..5d6b410 100644
--- a/core/modules/field/src/Tests/NestedFormTest.php
+++ b/core/modules/field/src/Tests/NestedFormTest.php
@@ -76,13 +76,17 @@ class NestedFormTest extends FieldTestBase {
// Create two entities.
$entity_type = 'entity_test';
- $entity_1 = entity_create($entity_type, array('id' => 1));
+ $entity_1 = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => 1));
$entity_1->enforceIsNew();
$entity_1->field_single->value = 0;
$entity_1->field_unlimited->value = 1;
$entity_1->save();
- $entity_2 = entity_create($entity_type, array('id' => 2));
+ $entity_2 = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => 2));
$entity_2->enforceIsNew();
$entity_2->field_single->value = 10;
$entity_2->field_unlimited->value = 11;
diff --git a/core/modules/field/src/Tests/TranslationTest.php b/core/modules/field/src/Tests/TranslationTest.php
index 359ef7d..efe1b7a 100644
--- a/core/modules/field/src/Tests/TranslationTest.php
+++ b/core/modules/field/src/Tests/TranslationTest.php
@@ -120,7 +120,9 @@ class TranslationTest extends FieldUnitTestBase {
// Prepare the field translations.
$entity_type_id = 'entity_test';
field_test_entity_info_translatable($entity_type_id, TRUE);
- $entity = entity_create($entity_type_id, array('type' => $this->field->getTargetBundle()));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type_id)
+ ->create(array('type' => $this->field->getTargetBundle()));
$field_translations = array();
$available_langcodes = array_keys($this->container->get('language_manager')->getLanguages());
$entity->langcode->value = reset($available_langcodes);
@@ -160,7 +162,9 @@ class TranslationTest extends FieldUnitTestBase {
$translation_langcodes = array_values($translation_langcodes);
$values = array('type' => $field->getTargetBundle(), 'langcode' => $translation_langcodes[0]);
- $entity = entity_create($entity_type_id, $values);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type_id)
+ ->create($values);
foreach ($translation_langcodes as $langcode) {
$values[$this->fieldName][$langcode] = $this->_generateTestFieldValues($this->fieldStorage->getCardinality());
$translation = $entity->hasTranslation($langcode) ? $entity->getTranslation($langcode) : $entity->addTranslation($langcode);
diff --git a/core/modules/field/src/Tests/TranslationWebTest.php b/core/modules/field/src/Tests/TranslationWebTest.php
index 78530c0..1606ea0 100644
--- a/core/modules/field/src/Tests/TranslationWebTest.php
+++ b/core/modules/field/src/Tests/TranslationWebTest.php
@@ -96,7 +96,9 @@ class TranslationWebTest extends FieldTestBase {
// Prepare the field translations.
field_test_entity_info_translatable($this->entityTypeId, TRUE);
- $entity = entity_create($this->entityTypeId);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityTypeId)
+ ->create();
$available_langcodes = array_flip(array_keys($this->container->get('language_manager')->getLanguages()));
$field_name = $this->fieldStorage->getName();
diff --git a/core/modules/rdf/src/Tests/Field/EntityReferenceRdfaTest.php b/core/modules/rdf/src/Tests/Field/EntityReferenceRdfaTest.php
index 73e6e53..9a4ac05 100644
--- a/core/modules/rdf/src/Tests/Field/EntityReferenceRdfaTest.php
+++ b/core/modules/rdf/src/Tests/Field/EntityReferenceRdfaTest.php
@@ -70,11 +70,15 @@ class EntityReferenceRdfaTest extends FieldRdfaTestBase {
))->save();
// Create the entity to be referenced.
- $this->targetEntity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
+ $this->targetEntity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => $this->randomMachineName()));
$this->targetEntity->save();
// Create the entity that will have the entity reference field.
- $this->entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
+ $this->entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => $this->randomMachineName()));
$this->entity->save();
$this->entity->{$this->fieldName}->entity = $this->targetEntity;
$this->uri = $this->getAbsoluteUri($this->entity);
diff --git a/core/modules/rest/src/Tests/CsrfTest.php b/core/modules/rest/src/Tests/CsrfTest.php
index af49a33..25beae1 100644
--- a/core/modules/rest/src/Tests/CsrfTest.php
+++ b/core/modules/rest/src/Tests/CsrfTest.php
@@ -54,7 +54,9 @@ class CsrfTest extends RESTTestBase {
// request.
$serializer = $this->container->get('serializer');
$entity_values = $this->entityValues($this->testEntityType);
- $entity = entity_create($this->testEntityType, $entity_values);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->testEntityType)
+ ->create($entity_values);
$this->serialized = $serializer->serialize($entity, $this->defaultFormat);
}
diff --git a/core/modules/rest/src/Tests/RESTTestBase.php b/core/modules/rest/src/Tests/RESTTestBase.php
index db7d123..87d18bd 100644
--- a/core/modules/rest/src/Tests/RESTTestBase.php
+++ b/core/modules/rest/src/Tests/RESTTestBase.php
@@ -183,7 +183,9 @@ abstract class RESTTestBase extends WebTestBase {
* The new entity object.
*/
protected function entityCreate($entity_type) {
- return entity_create($entity_type, $this->entityValues($entity_type));
+ return $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create($this->entityValues($entity_type));
}
/**
diff --git a/core/modules/rest/src/Tests/UpdateTest.php b/core/modules/rest/src/Tests/UpdateTest.php
index ef18a74..f407c1e 100644
--- a/core/modules/rest/src/Tests/UpdateTest.php
+++ b/core/modules/rest/src/Tests/UpdateTest.php
@@ -50,7 +50,9 @@ class UpdateTest extends RESTTestBase {
'value' => $this->randomString(),
'format' => 'plain_text',
));
- $patch_entity = entity_create($entity_type, $patch_values);
+ $patch_entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create($patch_values);
// We don't want to overwrite the UUID.
$patch_entity->set('uuid', NULL);
$serialized = $serializer->serialize($patch_entity, $this->defaultFormat, $context);
diff --git a/core/modules/system/src/Tests/Entity/EntityApiTest.php b/core/modules/system/src/Tests/Entity/EntityApiTest.php
index 7445734..396e4dc 100644
--- a/core/modules/system/src/Tests/Entity/EntityApiTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityApiTest.php
@@ -52,11 +52,17 @@ class EntityApiTest extends EntityUnitTestBase {
*/
protected function assertCRUD($entity_type, UserInterface $user1) {
// Create some test entities.
- $entity = entity_create($entity_type, array('name' => 'test', 'user_id' => $user1->id()));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('name' => 'test', 'user_id' => $user1->id()));
$entity->save();
- $entity = entity_create($entity_type, array('name' => 'test2', 'user_id' => $user1->id()));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('name' => 'test2', 'user_id' => $user1->id()));
$entity->save();
- $entity = entity_create($entity_type, array('name' => 'test', 'user_id' => NULL));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('name' => 'test', 'user_id' => NULL));
$entity->save();
$entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test')));
diff --git a/core/modules/system/src/Tests/Entity/EntityAutocompleteTest.php b/core/modules/system/src/Tests/Entity/EntityAutocompleteTest.php
index d42a07a..a7f01ed 100644
--- a/core/modules/system/src/Tests/Entity/EntityAutocompleteTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityAutocompleteTest.php
@@ -50,15 +50,21 @@ class EntityAutocompleteTest extends EntityUnitTestBase {
*/
function testEntityReferenceAutocompletion() {
// Add an entity with a slash in its name.
- $entity_1 = entity_create($this->entityType, array('name' => '10/16/2011'));
+ $entity_1 = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => '10/16/2011'));
$entity_1->save();
// Add another entity that differs after the slash character.
- $entity_2 = entity_create($this->entityType, array('name' => '10/17/2011'));
+ $entity_2 = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => '10/17/2011'));
$entity_2->save();
// Add another entity that has both a comma, a slash and markup.
- $entity_3 = entity_create($this->entityType, array('name' => 'label with, and / <em>test</em>'));
+ $entity_3 = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => 'label with, and / test'));
$entity_3->save();
// Try to autocomplete a entity label that matches both entities.
@@ -85,7 +91,7 @@ class EntityAutocompleteTest extends EntityUnitTestBase {
$this->assertIdentical($data[0]['label'], Html::escape($entity_2->name->value), 'Autocomplete returned the second matching entity');
// Try to autocomplete a entity label with both a comma, a slash and markup.
- $input = '"label with, and / <em>';
+ $input = '"label with, and /"';
$data = $this->getAutocompleteResult($input);
$n = $entity_3->name->value . ' (3)';
// Entity labels containing commas or quotes must be wrapped in quotes.
diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
index 53df175..2c712b1 100644
--- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
@@ -291,20 +291,24 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
// Create an entity that does reference the entity being tested.
$label_key = \Drupal::entityManager()->getDefinition($entity_type)->getKey('label');
- $referencing_entity = entity_create($entity_type, array(
- $label_key => 'Referencing ' . $entity_type,
- 'status' => 1,
- 'type' => $bundle,
- $field_name => array('target_id' => $referenced_entity->id()),
- ));
+ $referencing_entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ $label_key => 'Referencing ' . $entity_type,
+ 'status' => 1,
+ 'type' => $bundle,
+ $field_name => array('target_id' => $referenced_entity->id()),
+ ));
$referencing_entity->save();
// Create an entity that does not reference the entity being tested.
- $non_referencing_entity = entity_create($entity_type, array(
- $label_key => 'Non-referencing ' . $entity_type,
- 'status' => 1,
- 'type' => $bundle,
- ));
+ $non_referencing_entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ $label_key => 'Non-referencing ' . $entity_type,
+ 'status' => 1,
+ 'type' => $bundle,
+ ));
$non_referencing_entity->save();
return array(
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php b/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
index e8453ff..fb9f103 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
@@ -47,7 +47,9 @@ class EntityFieldDefaultValueTest extends EntityUnitTestBase {
* The entity type to run the tests with.
*/
protected function assertDefaultValues($entity_type_id) {
- $entity = entity_create($entity_type_id);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type_id)
+ ->create();
$definition = $this->entityManager->getDefinition($entity_type_id);
$langcode_key = $definition->getKey('langcode');
$this->assertEqual($entity->{$langcode_key}->value, 'en', SafeMarkup::format('%entity_type: Default language', array('%entity_type' => $entity_type_id)));
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
index 5c9161e..8919326 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
@@ -77,7 +77,9 @@ class EntityFieldTest extends EntityUnitTestBase {
// Pass in the value of the name field when creating. With the user
// field we test setting a field after creation.
- $entity = entity_create($entity_type);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
$entity->user_id->target_id = $this->entityUser->id();
$entity->name->value = $this->entityName;
@@ -172,9 +174,11 @@ class EntityFieldTest extends EntityUnitTestBase {
// Create a fresh entity so target_id does not get its property object
// instantiated, then verify setting a new value via typed data API works.
- $entity2 = entity_create($entity_type, array(
- 'user_id' => array('target_id' => $new_user1->id()),
- ));
+ $entity2 = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'user_id' => array('target_id' => $new_user1->id()),
+ ));
// Access the property object, and set a value.
$entity2->user_id->first()->get('target_id')->setValue($new_user2->id());
$this->assertEqual($new_user2->id(), $entity2->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type)));
@@ -255,11 +259,13 @@ class EntityFieldTest extends EntityUnitTestBase {
$this->entityFieldText = $this->randomMachineName();
$text_item[0]['value'] = $this->entityFieldText;
- $entity = entity_create($entity_type, array(
- 'name' => $name_item,
- 'user_id' => $user_item,
- 'field_test_text' => $text_item,
- ));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'name' => $name_item,
+ 'user_id' => $user_item,
+ 'field_test_text' => $text_item,
+ ));
$this->assertEqual($this->entityName, $entity->name->value, format_string('%entity_type: Name value can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityUser->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entityUser->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
@@ -327,20 +333,24 @@ class EntityFieldTest extends EntityUnitTestBase {
// Make sure the user id can be set to zero.
$user_item[0]['target_id'] = 0;
- $entity = entity_create($entity_type, array(
- 'name' => $name_item,
- 'user_id' => $user_item,
- 'field_test_text' => $text_item,
- ));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'name' => $name_item,
+ 'user_id' => $user_item,
+ 'field_test_text' => $text_item,
+ ));
$this->assertNotNull($entity->user_id->target_id, format_string('%entity_type: User id is not NULL', array('%entity_type' => $entity_type)));
$this->assertIdentical($entity->user_id->target_id, 0, format_string('%entity_type: User id has been set to 0', array('%entity_type' => $entity_type)));
// Test setting the ID with the value only.
- $entity = entity_create($entity_type, array(
- 'name' => $name_item,
- 'user_id' => 0,
- 'field_test_text' => $text_item,
- ));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'name' => $name_item,
+ 'user_id' => 0,
+ 'field_test_text' => $text_item,
+ ));
$this->assertNotNull($entity->user_id->target_id, format_string('%entity_type: User id is not NULL', array('%entity_type' => $entity_type)));
$this->assertIdentical($entity->user_id->target_id, 0, format_string('%entity_type: User id has been set to 0', array('%entity_type' => $entity_type)));
}
@@ -435,7 +445,9 @@ class EntityFieldTest extends EntityUnitTestBase {
// Test introspecting an entity object.
// @todo: Add bundles and test bundles as well.
- $entity = entity_create($entity_type);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
$definitions = $entity->getFieldDefinitions();
$this->assertEqual($definitions['name']->getType(), 'string', $entity_type .': Name field found.');
diff --git a/core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php b/core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php
index 33379bc..38a6653 100644
--- a/core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityReferenceFieldTest.php
@@ -93,10 +93,14 @@ class EntityReferenceFieldTest extends EntityUnitTestBase {
*/
public function testEntityReferenceFieldValidation() {
// Test a valid reference.
- $referenced_entity = entity_create($this->referencedEntityType, array('type' => $this->bundle));
+ $referenced_entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->referencedEntityType)
+ ->create(array('type' => $this->bundle));
$referenced_entity->save();
- $entity = entity_create($this->entityType, array('type' => $this->bundle));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('type' => $this->bundle));
$entity->{$this->fieldName}->target_id = $referenced_entity->id();
$violations = $entity->{$this->fieldName}->validate();
$this->assertEqual($violations->count(), 0, 'Validation passes.');
@@ -122,13 +126,17 @@ class EntityReferenceFieldTest extends EntityUnitTestBase {
*/
public function testReferencedEntitiesMultipleLoad() {
// Create the parent entity.
- $entity = entity_create($this->entityType, array('type' => $this->bundle));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('type' => $this->bundle));
// Create three target entities and attach them to parent field.
$target_entities = array();
$reference_field = array();
for ($i = 0; $i < 3; $i++) {
- $target_entity = entity_create($this->referencedEntityType, array('type' => $this->bundle));
+ $target_entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->referencedEntityType)
+ ->create(array('type' => $this->bundle));
$target_entity->save();
$target_entities[] = $target_entity;
$reference_field[]['target_id'] = $target_entity->id();
@@ -149,7 +157,9 @@ class EntityReferenceFieldTest extends EntityUnitTestBase {
// Create a new target entity that is not saved, thus testing the
// "autocreate" feature.
- $target_entity_unsaved = entity_create($this->referencedEntityType, array('type' => $this->bundle, 'name' => $this->randomString()));
+ $target_entity_unsaved = $this->container->get('entity_type.manager')
+ ->getStorage($this->referencedEntityType)
+ ->create(array('type' => $this->bundle, 'name' => $this->randomString()));
$reference_field[6]['entity'] = $target_entity_unsaved;
$target_entities[6] = $target_entity_unsaved;
@@ -200,7 +210,9 @@ class EntityReferenceFieldTest extends EntityUnitTestBase {
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
);
// Create the parent entity.
- $entity = entity_create($this->entityType, array('type' => $this->bundle));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('type' => $this->bundle));
// Create the default target entity.
$target_entity = EntityTestStringId::create([
@@ -224,7 +236,9 @@ class EntityReferenceFieldTest extends EntityUnitTestBase {
$this->assertConfigSchema(\Drupal::service('config.typed'), 'field.field.' . $field->id(), $field->toArray());
// Test that the default value works.
- $entity = entity_create($this->entityType, array('type' => $this->bundle));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('type' => $this->bundle));
$entities = $entity->{$field_name}->referencedEntities();
$this->assertEqual($entities[0]->id(), $target_entity->id());
}
diff --git a/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php b/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php
index 39f04c3..057d23a 100644
--- a/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityRevisionsTest.php
@@ -62,10 +62,12 @@ class EntityRevisionsTest extends WebTestBase {
protected function runRevisionsTests($entity_type) {
// Create initial entity.
- $entity = entity_create($entity_type, array(
- 'name' => 'foo',
- 'user_id' => $this->webUser->id(),
- ));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'name' => 'foo',
+ 'user_id' => $this->webUser->id(),
+ ));
$entity->field_test_text->value = 'bar';
$entity->save();
diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
index de62ba7..f867d98 100644
--- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
@@ -39,16 +39,21 @@ class EntityTranslationTest extends EntityLanguageTestBase {
*/
protected function doTestEntityLanguageMethods($entity_type) {
$langcode_key = $this->entityManager->getDefinition($entity_type)->getKey('langcode');
- $entity = entity_create($entity_type, array(
- 'name' => 'test',
- 'user_id' => $this->container->get('current_user')->id(),
- ));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'name' => 'test',
+ 'user_id' => $this->container->get('current_user')->id(),
+ ));
$this->assertEqual($entity->language()->getId(), $this->languageManager->getDefaultLanguage()->getId(), format_string('%entity_type: Entity created with API has default language.', array('%entity_type' => $entity_type)));
- $entity = entity_create($entity_type, array(
- 'name' => 'test',
- 'user_id' => \Drupal::currentUser()->id(),
- $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
- ));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'name' => 'test',
+ 'user_id' => \Drupal::currentUser()->id(),
+ $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
+ ));
+
$this->assertEqual($entity->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type)));
$this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
@@ -164,7 +169,9 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Create a language neutral entity and check that properties are stored
// as language neutral.
- $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('name' => $name, 'user_id' => $uid, $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$default_langcode = $entity->language()->getId();
@@ -186,7 +193,9 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Create a language-aware entity and check that properties are stored
// as language-aware.
- $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, $langcode_key => $langcode));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('name' => $name, 'user_id' => $uid, $langcode_key => $langcode));
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$default_langcode = $entity->language()->getId();
@@ -238,11 +247,14 @@ class EntityTranslationTest extends EntityLanguageTestBase {
// Create an additional entity with only the uid set. The uid for the
// original language is the same of one used for a translation.
$langcode = $this->langcodes[1];
- entity_create($entity_type, array(
- 'user_id' => $properties[$langcode]['user_id'],
- 'name' => 'some name',
- $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
- ))->save();
+ $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'user_id' => $properties[$langcode]['user_id'],
+ 'name' => 'some name',
+ $langcode_key => LanguageInterface::LANGCODE_NOT_SPECIFIED,
+ ))
+ ->save();
$entities = entity_load_multiple($entity_type);
$this->assertEqual(count($entities), 3, format_string('%entity_type: Three entities were created.', array('%entity_type' => $entity_type)));
diff --git a/core/modules/system/src/Tests/Entity/EntityUUIDTest.php b/core/modules/system/src/Tests/Entity/EntityUUIDTest.php
index 48a6e4e..570d556 100644
--- a/core/modules/system/src/Tests/Entity/EntityUUIDTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityUUIDTest.php
@@ -45,16 +45,20 @@ class EntityUUIDTest extends EntityUnitTestBase {
// Verify that no UUID is auto-generated when passing one for creation.
$uuid_service = $this->container->get('uuid');
$uuid = $uuid_service->generate();
- $custom_entity = entity_create($entity_type, array(
- 'name' => $this->randomMachineName(),
- 'uuid' => $uuid,
- ));
+ $custom_entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'name' => $this->randomMachineName(),
+ 'uuid' => $uuid,
+ ));
$this->assertIdentical($custom_entity->uuid(), $uuid);
// Save this entity, so we have more than one later.
$custom_entity->save();
// Verify that a new UUID is generated upon creating an entity.
- $entity = entity_create($entity_type, array('name' => $this->randomMachineName()));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('name' => $this->randomMachineName()));
$uuid = $entity->uuid();
$this->assertTrue($uuid);
diff --git a/core/modules/system/src/Tests/Entity/EntityValidationTest.php b/core/modules/system/src/Tests/Entity/EntityValidationTest.php
index aa85fa7..7b5eb58 100644
--- a/core/modules/system/src/Tests/Entity/EntityValidationTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityValidationTest.php
@@ -67,7 +67,9 @@ class EntityValidationTest extends EntityUnitTestBase {
// Pass in the value of the name field when creating. With the user
// field we test setting a field after creation.
- $entity = entity_create($entity_type);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
$entity->user_id->target_id = $this->entityUser->id();
$entity->name->value = $this->entityName;
diff --git a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
index 9f5028f..6bfbe94 100644
--- a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
+++ b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
@@ -116,7 +116,9 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
// Create an entity with four revisions.
$revision_ids = array();
- $entity = entity_create($entity_type);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
$entity->save();
$revision_ids[] = $entity->getRevisionId();
for ($i = 0; $i < 4; $i++) {
@@ -182,7 +184,9 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
*/
function testFieldWrite() {
$entity_type = $bundle = 'entity_test_rev';
- $entity = entity_create($entity_type);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
$revision_values = array();
@@ -297,7 +301,9 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
}
// Save an entity with values.
- $entity = entity_create($entity_type, $values);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create($values);
$entity->save();
// Load the entity back and check the values.
@@ -325,10 +331,12 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
'bundle' => $entity_type,
]);
$field->save();
- $entity = entity_create($entity_type, array(
- 'id' => 0,
- 'revision_id' => 0,
- ));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'id' => 0,
+ 'revision_id' => 0,
+ ));
$entity->decimal52->value = '1.235';
$entity->save();
@@ -408,10 +416,12 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
}
// Add data so the table cannot be dropped.
- $entity = entity_create($entity_type, array(
- 'id' => 1,
- 'revision_id' => 1,
- ));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array(
+ 'id' => 1,
+ 'revision_id' => 1,
+ ));
$entity->$field_name->value = 'field data';
$entity->enforceIsNew();
$entity->save();
diff --git a/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php b/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
index 68bfee6..34233c4 100644
--- a/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
+++ b/core/modules/system/src/Tests/Entity/FieldWidgetConstraintValidatorTest.php
@@ -41,7 +41,9 @@ class FieldWidgetConstraintValidatorTest extends KernelTestBase {
*/
public function testValidation() {
$entity_type = 'entity_test_constraint_violation';
- $entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create(array('id' => 1, 'revision_id' => 1));
$display = entity_get_form_display($entity_type, $entity_type, 'default');
$form = array();
$form_state = new FormState();
diff --git a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
index ca44407..437b8b6 100644
--- a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
+++ b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
@@ -82,7 +82,9 @@ class TextFormatterTest extends EntityUnitTestBase {
);
// Create the entity to be referenced.
- $entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($this->entityType)
+ ->create(array('name' => $this->randomMachineName()));
$entity->formatted_text = array(
'value' => 'Hello, world!',
'format' => 'my_text_format',
diff --git a/core/modules/text/src/Tests/TextWithSummaryItemTest.php b/core/modules/text/src/Tests/TextWithSummaryItemTest.php
index cf42cbe..dcb765f 100644
--- a/core/modules/text/src/Tests/TextWithSummaryItemTest.php
+++ b/core/modules/text/src/Tests/TextWithSummaryItemTest.php
@@ -64,7 +64,9 @@ class TextWithSummaryItemTest extends FieldUnitTestBase {
$this->createField($entity_type);
// Create an entity with a summary and no text format.
- $entity = entity_create($entity_type);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
$entity->summary_field->value = $value = $this->randomMachineName();
$entity->summary_field->summary = $summary = $this->randomMachineName();
$entity->summary_field->format = NULL;
@@ -88,7 +90,9 @@ class TextWithSummaryItemTest extends FieldUnitTestBase {
$this->assertEqual($entity->summary_field->summary_processed, $summary);
// Test the generateSampleValue() method.
- $entity = entity_create($entity_type);
+ $entity = $this->container->get('entity_type.manager')
+ ->getStorage($entity_type)
+ ->create();
$entity->summary_field->generateSampleItems();
$this->entityValidateAndSave($entity);
}