protected function EntityValidationTest::createTestEntity

Creates a test entity.

Parameters

string $entity_type: An entity type.

Return value

\Drupal\Core\Entity\EntityInterface The created test entity.

1 call to EntityValidationTest::createTestEntity()
EntityValidationTest::checkValidation in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php
Executes the validation test set for a defined entity type.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityValidationTest.php, line 67
Contains \Drupal\system\Tests\Entity\EntityValidationTest.

Class

EntityValidationTest
Tests Entity API base functionality.

Namespace

Drupal\system\Tests\Entity

Code

protected function createTestEntity($entity_type) {
  $this->entity_name = $this
    ->randomName();
  $this->entity_user = $this
    ->createUser();
  $this->entity_field_text = $this
    ->randomName();

  // 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, array());
  $entity->user_id->target_id = $this->entity_user->uid;
  $entity->name->value = $this->entity_name;

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