Commit 98d39d1b authored by alexpott's avatar alexpott

Issue #2669400 by jungle, dimaro, rakesh.gectcr, lluvigne, Mile23: Replace...

Issue #2669400 by jungle, dimaro, rakesh.gectcr, lluvigne, Mile23: Replace deprecated usages of entity_create('type') with a direct call to <EntityType>::create()
parent e5b24859
......@@ -11,6 +11,7 @@
use Drupal\comment\CommentManagerInterface;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Entity\EntityInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\user\Entity\Role;
......@@ -70,7 +71,7 @@ protected function createEntity() {
$field->save();
// Create a "Camelids" test entity that the comment will be assigned to.
$this->entityTestCamelid = entity_create('entity_test', array(
$this->entityTestCamelid = EntityTest::create(array(
'name' => 'Camelids',
'type' => 'bar',
));
......@@ -101,7 +102,7 @@ public function testCommentEntity() {
$this->verifyPageCache($this->entityTestCamelid->urlInfo(), 'HIT');
// Create a "Hippopotamus" comment.
$this->entityTestHippopotamidae = entity_create('entity_test', array(
$this->entityTestHippopotamidae = EntityTest::create(array(
'name' => 'Hippopotamus',
'type' => 'bar',
));
......
......@@ -14,6 +14,7 @@
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Drupal\comment\Entity\Comment;
use Drupal\entity_test\Entity\EntityTest;
/**
* Tests the bubbling up of comment cache tags when using the Comment list
......@@ -74,7 +75,7 @@ public function testCacheTags() {
$renderer = $this->container->get('renderer');
// Create the entity that will be commented upon.
$commented_entity = entity_create('entity_test', array('name' => $this->randomMachineName()));
$commented_entity = EntityTest::create(array('name' => $this->randomMachineName()));
$commented_entity->save();
// Verify cache tags on the rendered entity before it has comments.
......
......@@ -9,6 +9,7 @@
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Tests\FieldUnitTestBase;
/**
......@@ -40,7 +41,7 @@ public function testCommentItem() {
$this->addDefaultCommentField('entity_test', 'entity_test', 'comment');
// Verify entity creation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->name->value = $this->randomMachineName();
$entity->save();
......@@ -52,7 +53,7 @@ public function testCommentItem() {
// Test sample item generation.
/** @var \Drupal\entity_test\Entity\EntityTest $entity */
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->comment->generateSampleItems();
$this->entityValidateAndSave($entity);
$this->assertTrue(in_array($entity->get('comment')->status, [
......
......@@ -11,6 +11,7 @@
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_ui\Tests\FieldUiTestTrait;
......@@ -92,7 +93,7 @@ protected function setUp() {
// Create a test entity.
$random_label = $this->randomMachineName();
$data = array('type' => 'entity_test', 'name' => $random_label);
$this->entity = entity_create('entity_test', $data);
$this->entity = EntityTest::create($data);
$this->entity->save();
}
......@@ -433,7 +434,7 @@ function testCommentFunctionality() {
// Test the new entity commenting inherits default.
$random_label = $this->randomMachineName();
$data = array('bundle' => 'entity_test', 'name' => $random_label);
$new_entity = entity_create('entity_test', $data);
$new_entity = EntityTest::create($data);
$new_entity->save();
$this->drupalGet('entity_test/manage/' . $new_entity->id() . '/edit');
$this->assertNoFieldChecked('edit-field-foobar-0-status-1');
......
......@@ -115,7 +115,7 @@ public function testDependencyManagement() {
$this->assertTrue(isset($dependents['config_test.dynamic.entity4']), 'config_test.dynamic.entity4 has a dependency on the Node module.');
// Test dependency on a content entity.
$entity_test = entity_create('entity_test', array(
$entity_test = EntityTest::create(array(
'name' => $this->randomString(),
'type' => 'entity_test',
));
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\StorageComparer;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\simpletest\KernelTestBase;
/**
......@@ -77,9 +78,9 @@ function testMissingContent() {
// on two content entities that do not exist.
$storage = $this->container->get('config.storage');
$sync = $this->container->get('config.storage.sync');
$entity_one = entity_create('entity_test', array('name' => 'one'));
$entity_two = entity_create('entity_test', array('name' => 'two'));
$entity_three = entity_create('entity_test', array('name' => 'three'));
$entity_one = EntityTest::create(array('name' => 'one'));
$entity_two = EntityTest::create(array('name' => 'two'));
$entity_three = EntityTest::create(array('name' => 'three'));
$dynamic_name = 'config_test.dynamic.dotted.default';
$original_dynamic_data = $storage->read($dynamic_name);
// Entity one will be resolved by
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -53,7 +54,7 @@ protected function setUp() {
*/
public function testDateTimeItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '2014-01-01T20:00:00Z';
$entity->field_datetime = $value;
$entity->name->value = $this->randomMachineName();
......@@ -78,7 +79,7 @@ public function testDateTimeItem() {
$this->assertEqual($entity->field_datetime->value, $new_value);
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_datetime->generateSampleItems();
$this->entityValidateAndSave($entity);
}
......@@ -88,7 +89,7 @@ public function testDateTimeItem() {
*/
public function testSetValue() {
// Test DateTimeItem::setValue() using string.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '2014-01-01T20:00:00Z';
$entity->get('field_datetime')->set(0, $value);
$entity->save();
......@@ -98,7 +99,7 @@ public function testSetValue() {
$this->assertEqual($entity->field_datetime[0]->value, $value, 'DateTimeItem::setValue() works with string value.');
// Test DateTimeItem::setValue() using property array.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '2014-01-01T20:00:00Z';
$entity->set('field_datetime', $value);
$entity->save();
......@@ -113,7 +114,7 @@ public function testSetValue() {
*/
public function testSetValueProperty() {
// Test Date::setValue().
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '2014-01-01T20:00:00Z';
$entity->set('field_datetime', $value);
......
......@@ -11,6 +11,7 @@
use Drupal\Core\EventSubscriber\AjaxResponseSubscriber;
use Drupal\Core\Language\LanguageInterface;
use Drupal\editor\Entity\Editor;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\quickedit\MetadataGenerator;
use Drupal\quickedit\Tests\QuickEditTestBase;
use Drupal\quickedit_test\MockEditEntityFieldAccessCheck;
......@@ -143,7 +144,7 @@ public function testEditorSelection() {
$this->editorSelector = $this->container->get('quickedit.editor.selector');
// Create an entity with values for this text field.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->{$this->fieldName}->value = 'Hello, world!';
$entity->{$this->fieldName}->format = 'filtered_html';
$entity->save();
......@@ -172,7 +173,7 @@ public function testMetadata() {
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
// Create an entity with values for the field.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->{$this->fieldName}->value = 'Test';
$entity->{$this->fieldName}->format = 'full_html';
$entity->save();
......@@ -209,7 +210,7 @@ public function testAttachments() {
*/
public function testGetUntransformedTextCommand() {
// Create an entity with values for the field.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->{$this->fieldName}->value = 'Test';
$entity->{$this->fieldName}->format = 'full_html';
$entity->save();
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -51,7 +52,7 @@ protected function setUp() {
*/
public function testBooleanItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '1';
$entity->field_boolean = $value;
$entity->name->value = $this->randomMachineName();
......@@ -76,7 +77,7 @@ public function testBooleanItem() {
$this->assertEqual($entity->field_boolean->value, $new_value);
// Test sample item generation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_boolean->generateSampleItems();
$this->entityValidateAndSave($entity);
}
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -110,7 +111,7 @@ protected function setUp() {
// Create an entity with values.
$this->values = $this->_generateTestFieldValues($this->cardinality);
$this->entity = entity_create('entity_test');
$this->entity = EntityTest::create();
$this->entity->{$this->fieldName}->setValue($this->values);
$this->entity->save();
}
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -48,7 +49,7 @@ protected function setUp() {
*/
public function testEmailItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = 'test@example.com';
$entity->field_email = $value;
$entity->name->value = $this->randomMachineName();
......@@ -73,7 +74,7 @@ public function testEmailItem() {
$this->assertEqual($entity->field_email->value, $new_value);
// Test sample item generation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_email->generateSampleItems();
$this->entityValidateAndSave($entity);
}
......
......@@ -9,6 +9,7 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\config\Tests\AssertConfigEntityImportTrait;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
......@@ -202,9 +203,9 @@ protected function getTestEntities() {
$config_entity_2 = entity_create('config_test', array('id' => $this->randomMachineName(), 'label' => $this->randomMachineName()));
$config_entity_2->save();
$content_entity_1 = entity_create('entity_test', array('name' => $this->randomMachineName()));
$content_entity_1 = EntityTest::create(array('name' => $this->randomMachineName()));
$content_entity_1->save();
$content_entity_2 = entity_create('entity_test', array('name' => $this->randomMachineName()));
$content_entity_2 = EntityTest::create(array('name' => $this->randomMachineName()));
$content_entity_2->save();
return array(
......
......@@ -115,7 +115,7 @@ public function testContentEntityReferenceItem() {
$tid = $this->term->id();
// Just being able to create the entity like this verifies a lot of code.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_test_taxonomy_term->target_id = $tid;
$entity->name->value = $this->randomMachineName();
$entity->save();
......@@ -178,11 +178,11 @@ public function testContentEntityReferenceItem() {
// Delete terms so we have nothing to reference and try again
$term->delete();
$term2->delete();
$entity = entity_create('entity_test', array('name' => $this->randomMachineName()));
$entity = EntityTest::create(array('name' => $this->randomMachineName()));
$entity->save();
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_test_taxonomy_term->generateSampleItems();
$entity->field_test_taxonomy_vocabulary->generateSampleItems();
$this->entityValidateAndSave($entity);
......@@ -211,7 +211,7 @@ public function testConfigEntityReferenceItem() {
$referenced_entity_id = $this->vocabulary->id();
// Just being able to create the entity like this verifies a lot of code.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_test_taxonomy_vocabulary->target_id = $referenced_entity_id;
$entity->name->value = $this->randomMachineName();
$entity->save();
......@@ -247,7 +247,7 @@ public function testConfigEntityReferenceItem() {
// Delete terms so we have nothing to reference and try again
$this->vocabulary->delete();
$vocabulary2->delete();
$entity = entity_create('entity_test', array('name' => $this->randomMachineName()));
$entity = EntityTest::create(array('name' => $this->randomMachineName()));
$entity->save();
}
......@@ -285,7 +285,7 @@ public function testEntitySaveOrder() {
'vid' => $this->term->bundle(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));
$entity = entity_create('entity_test');
$entity = EntityTest::create();
// Now assign the unsaved term to the field.
$entity->field_test_taxonomy_term->entity = $term;
$entity->name->value = $this->randomMachineName();
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Form\FormState;
use Drupal\entity_test\Entity\EntityTest;
/**
* Tests other Field API functions.
......@@ -143,9 +144,9 @@ function testEntityDisplayViewMultiple() {
));
// Create two entities.
$entity1 = entity_create('entity_test', array('id' => 1, 'type' => 'entity_test'));
$entity1 = EntityTest::create(array('id' => 1, 'type' => 'entity_test'));
$entity1->{$this->fieldTestData->field_name}->setValue($this->_generateTestFieldValues(1));
$entity2 = entity_create('entity_test', array('id' => 2, 'type' => 'entity_test'));
$entity2 = EntityTest::create(array('id' => 2, 'type' => 'entity_test'));
$entity2->{$this->fieldTestData->field_name}->setValue($this->_generateTestFieldValues(1));
// Run buildMultiple(), and check that the entities come out as expected.
......@@ -164,7 +165,7 @@ function testEntityDisplayViewMultiple() {
*/
function testEntityCache() {
// Initialize random values and a test entity.
$entity_init = entity_create('entity_test', array('type' => $this->fieldTestData->field->getTargetBundle()));
$entity_init = EntityTest::create(array('type' => $this->fieldTestData->field->getTargetBundle()));
$values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality());
// Non-cacheable entity type.
......
......@@ -291,7 +291,7 @@ function testDeleteFieldCrossDeletion() {
* @see field_test_entity_bundle_field_info_alter()
*/
protected function doFieldValidationTests() {
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->set($this->fieldStorage->getName(), 1);
$violations = $entity->validate();
$this->assertEqual(count($violations), 0, 'No violations found when in-range value passed.');
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -70,7 +71,7 @@ public function testEntityCountAndHasData() {
$this->assertIdentical($this->storage->countFieldData($field_storage), 0, 'There are 0 entities with field data.');
// Create 1 entity without the field.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->name->value = $this->randomMachineName();
$entity->save();
......@@ -79,7 +80,7 @@ public function testEntityCountAndHasData() {
// Create 12 entities to ensure that the purging works as expected.
for ($i=0; $i < 12; $i++) {
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_int[] = mt_rand(1, 99);
$entity->field_int[] = mt_rand(1, 99);
$entity->name[] = $this->randomMachineName();
......
......@@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -65,7 +66,7 @@ public function testImportDeleteUninstall() {
'bundle' => 'entity_test',
])->save();
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '+0123456789';
$entity->field_test = $value;
$entity->field_int = '99';
......@@ -130,7 +131,7 @@ public function testImportAlreadyDeletedUninstall() {
// Create 12 entities to ensure that the purging works as expected.
for ($i=0; $i < 12; $i++) {
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '+0123456789';
$entity->field_test = $value;
$entity->name->value = $this->randomMachineName();
......
......@@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -63,7 +64,7 @@ public function testImportDeleteUninstall() {
])->save();
// Create an entity which has values for the telephone and text field.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = '+0123456789';
$entity->field_tel = $value;
$entity->field_date = time();
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException;
use Drupal\Core\Field\FieldException;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -355,7 +356,7 @@ function testDelete() {
$this->assertTrue(!empty($field) && !$field->isDeleted(), 'A new field for a previously used field name is created.');
// Save an entity with data for the field
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$values[0]['value'] = mt_rand(1, 127);
$entity->{$field_storage->getName()}->value = $values[0]['value'];
$entity = $this->entitySaveReload($entity);
......@@ -408,7 +409,7 @@ function testUpdate() {
$field->save();
do {
$entity = entity_create('entity_test');
$entity = EntityTest::create();
// Fill in the entity with more values than $cardinality.
for ($i = 0; $i < 20; $i++) {
// We can not use $i here because 0 values are filtered out.
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -50,7 +51,7 @@ protected function setUp() {
*/
public function testNumberItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$integer = rand(0, 10);
$entity->field_integer = $integer;
$float = 3.14;
......@@ -98,7 +99,7 @@ public function testNumberItem() {
$this->assertEqual($entity->field_decimal->value, $new_decimal);
/// Test sample item generation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->field_integer->generateSampleItems();
$entity->field_float->generateSampleItems();
$entity->field_decimal->generateSampleItems();
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -54,7 +55,7 @@ protected function setUp() {
*/
public function testShapeItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$shape = 'cube';
$color = 'blue';
$entity->{$this->fieldName}->shape = $shape;
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -55,7 +56,7 @@ protected function setUp() {
*/
public function testTestItem() {
// Verify entity creation.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$value = rand(1, 10);
$entity->field_test = $value;
$entity->name->value = $this->randomMachineName();
......
......@@ -8,6 +8,7 @@
namespace Drupal\field\Tests\Uri;
use Drupal\Component\Utility\Unicode;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\FieldUnitTestBase;
......@@ -70,7 +71,7 @@ public function testUriField() {
->save();
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->$field_name->generateSampleItems();
$this->entityValidateAndSave($entity);
}
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -80,7 +81,7 @@ public function testFileItem() {
$this->assertEqual($handler_id, 'default:file');
// Create a test entity with the
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->file_test->target_id = $this->file->id();
$entity->file_test->display = 1;
$entity->file_test->description = $description = $this->randomMachineName();
......@@ -115,7 +116,7 @@ public function testFileItem() {
$entity->delete();
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->file_test->generateSampleItems();
$this->entityValidateAndSave($entity);
// Verify that the sample file was stored in the correct directory.
......@@ -134,7 +135,7 @@ public function testFileItem() {
'type' => 'file_default',
'weight' => 1,
])->save();
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->file_test = array('entity' => $file3);
$uri = $file3->getFileUri();
$output = entity_view($entity, 'default');
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
/**
* Tests that entities can be normalized in HAL.
......@@ -30,9 +31,9 @@ protected function setUp() {
* Tests the normalize function.
*/
public function testNormalize() {
$target_entity_de = entity_create('entity_test', (array('langcode' => 'de', 'field_test_entity_reference' => NULL)));
$target_entity_de = EntityTest::create((array('langcode' => 'de', 'field_test_entity_reference' => NULL)));
$target_entity_de->save();
$target_entity_en = entity_create('entity_test', (array('langcode' => 'en', 'field_test_entity_reference' => NULL)));
$target_entity_en = EntityTest::create((array('langcode' => 'en', 'field_test_entity_reference' => NULL)));
$target_entity_en->save();
// Create a German entity.
......@@ -55,7 +56,7 @@ public function testNormalize() {
)
);
$entity = entity_create('entity_test', $values);
$entity = EntityTest::create($values);
$entity->save();
// Add an English value for name and entity reference properties.
$entity->addTranslation('en')->set('name', array(0 => array('value' => $translation_values['name'])));
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Tests\FieldUnitTestBase;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -71,7 +72,7 @@ protected function setUp() {
*/
public function testImageItem() {
// Create a test entity with the image field set.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->image_test->target_id = $this->image->id();
$entity->image_test->alt = $alt = $this->randomMachineName();
$entity->image_test->title = $title = $this->randomMachineName();
......@@ -115,7 +116,7 @@ public function testImageItem() {
// Delete the image and try to save the entity again.
$this->image->delete();
$entity = entity_create('entity_test', array('mame' => $this->randomMachineName()));
$entity = EntityTest::create(array('mame' => $this->randomMachineName()));
$entity->save();
// Test image item properties.
......@@ -124,7 +125,7 @@ public function testImageItem() {
$this->assertEqual(array_keys($properties), $expected);
// Test the generateSampleValue() method.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->image_test->generateSampleItems();
$this->entityValidateAndSave($entity);
}
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\image\Entity\ImageStyle;
......@@ -81,7 +82,7 @@ function testImageFormatterTheme() {
$url = file_url_transform_relative($style->buildUrl($original_uri));
// Create a test entity with the image field set.
$entity = entity_create('entity_test');
$entity = EntityTest::create();
$entity->image_test->target_id = $this->image->id();
$entity->image_test->alt = NULL;
$entity->image_test->uri = $original_uri;
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Tests\FieldUnitTestBase;
......@@ -73,7 +74,7 @@ protected function setUp() {
*/
public function testLinkItem() {
// Create entity.
$entity = entity_create('entity_test');