Commit 0e454b55 authored by catch's avatar catch

Issue #2502917 by dimaro, rakesh.gectcr, DuaelFr, suhel.rangnekar: Replace...

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()
parent ce887237
......@@ -45,7 +45,10 @@ protected function setUp() {
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();
}
/**
......
......@@ -32,7 +32,10 @@ public function testUUIDConflict() {
$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();
......
......@@ -234,7 +234,9 @@ protected function createEntity($values, $langcode, $bundle_name = NULL) {
}
}
}
$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();
}
......
......@@ -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);
}
/**
......
......@@ -133,7 +133,9 @@ protected function setUp() {
])->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()));
}
......
......@@ -108,7 +108,9 @@ protected function setUp() {
))->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 @@ protected function setUp() {
$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 @@ public function testAccess() {
$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 @@ public function testLabelFormatter() {
*/
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);
......
......@@ -32,7 +32,9 @@ function testEntityDisplayBuild() {
$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 @@ function testEntityCache() {
$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 @@ function testEntityFormDisplayExtractFormValues() {
$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');
......
......@@ -37,7 +37,9 @@ function testFieldAttachSaveLoad() {
// 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 @@ function testFieldAttachLoadMultiple() {
// 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 @@ function testFieldAttachSaveEmptyData() {
$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 @@ function testFieldAttachSaveEmptyDataDefaultValue() {
$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 @@ function testFieldAttachSaveEmptyDataDefaultValue() {
// 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 @@ function testFieldAttachDelete() {
$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 @@ function testEntityCreateBundle() {
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 @@ function testEntityDeleteBundle() {
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);
......
......@@ -115,9 +115,9 @@ public function testEntityCountAndHasData() {
$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.');
......
......@@ -543,7 +543,9 @@ function testFieldFormAccess() {
// 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();
......
......@@ -76,13 +76,17 @@ function testNestedFieldForm() {
// 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;
......
......@@ -120,7 +120,9 @@ function testTranslatableFieldSaveLoad() {
// 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 @@ function testTranslatableFieldSaveLoad() {
$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);
......
......@@ -96,7 +96,9 @@ function testFieldFormTranslationRevisions() {
// 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();
......
......@@ -70,11 +70,15 @@ protected function setUp() {
))->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);
......
......@@ -54,7 +54,9 @@ protected function setUp() {
// 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);
}
......
......@@ -183,7 +183,9 @@ protected function httpRequest($url, $method, $body = NULL, $mime_type = NULL) {
* 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));
}
/**
......
......@@ -50,7 +50,9 @@ public function testPatchUpdate() {
'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);
......
......@@ -52,11 +52,17 @@ public function testCRUD() {
*/
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')));
......
......@@ -50,15 +50,21 @@ protected function setUp() {
*/
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 @@ function testEntityReferenceAutocompletion() {
$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.
......
......@@ -291,20 +291,24 @@ protected function createReferenceTestEntities($referenced_entity) {
// 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(
......
......@@ -47,7 +47,9 @@ public function testDefaultValues() {
* 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)));
......
......@@ -77,7 +77,9 @@ protected function createTestEntity($entity_type) {
// 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 @@ protected function doTestReadWrite($entity_type) {
// 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 @@ protected function doTestReadWrite($entity_type) {
$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 @@ protected function doTestReadWrite($entity_type) {
// 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 @@ protected function doTestIntrospection($entity_type) {
// 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.');
......
......@@ -93,10 +93,14 @@ protected function setUp() {
*/
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 @@ public function testEntityReferenceFieldValidation() {
*/
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 @@ public function testReferencedEntitiesMultipleLoad() {
// 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 @@ public function testReferencedEntitiesStringId() {
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 @@ public function testReferencedEntitiesStringId() {
$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());
}
......
......@@ -62,10 +62,12 @@ public function testRevisions() {
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();
......
......@@ -39,16 +39,21 @@ public function testEntityLanguageMethods() {
*/
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(),