You are here

protected function EntityValidationTest::createTestEntity in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityValidationTest.php \Drupal\system\Tests\Entity\EntityValidationTest::createTestEntity()

Creates a test entity.

Parameters

string $entity_type: An entity type.

Return value

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

2 calls to EntityValidationTest::createTestEntity()
EntityValidationTest::checkValidation in core/modules/system/src/Tests/Entity/EntityValidationTest.php
Executes the validation test set for a defined entity type.
EntityValidationTest::testCompositeConstraintValidation in core/modules/system/src/Tests/Entity/EntityValidationTest.php
Tests composite constraints.

File

core/modules/system/src/Tests/Entity/EntityValidationTest.php, line 64
Contains \Drupal\system\Tests\Entity\EntityValidationTest.

Class

EntityValidationTest
Tests the Entity Validation API.

Namespace

Drupal\system\Tests\Entity

Code

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

  // 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->user_id->target_id = $this->entityUser
    ->id();
  $entity->name->value = $this->entityName;

  // Set a value for the test field.
  if ($entity
    ->hasField('field_test_text')) {
    $this->entityFieldText = $this
      ->randomMachineName();
    $entity->field_test_text->value = $this->entityFieldText;
  }
  return $entity;
}