You are here

protected function EntityFieldTest::createTestEntity in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::createTestEntity()

Creates a test entity.

Return value

\Drupal\Core\Entity\EntityInterface

7 calls to EntityFieldTest::createTestEntity()
EntityFieldTest::doTestComputedProperties in core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
Executes the computed properties tests for the given entity type.
EntityFieldTest::doTestDataStructureInterfaces in core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
Executes the data structure interfaces tests for the given entity type.
EntityFieldTest::doTestIterator in core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
Executes the iterator tests for the given entity type.
EntityFieldTest::doTestReadWrite in core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
Executes the read write test set for a defined entity type.
EntityFieldTest::doTestSave in core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
Executes the save tests for the given entity type.

... See full list

File

core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php, line 79

Class

EntityFieldTest
Tests the Entity Field API.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function createTestEntity($entity_type) {
  $this->entityName = $this
    ->randomMachineName();
  $this->entityUser = $this
    ->createUser();
  $this->entityFieldText = $this
    ->randomMachineName();

  // Pass in the value of the name field when creating. With the user
  // field we test setting a field after creation.
  $entity = $this->container
    ->get('entity_type.manager')
    ->getStorage($entity_type)
    ->create();
  $entity->user_id->target_id = $this->entityUser
    ->id();
  $entity->name->value = $this->entityName;

  // Set a value for the test field.
  $entity->field_test_text->value = $this->entityFieldText;
  return $entity;
}