function EntityValidationTest::createTestEntity
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php \Drupal\KernelTests\Core\Entity\EntityValidationTest::createTestEntity()
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php \Drupal\KernelTests\Core\Entity\EntityValidationTest::createTestEntity()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php \Drupal\KernelTests\Core\Entity\EntityValidationTest::createTestEntity()
Creates a test entity.
Parameters
string $entity_type: An entity type.
Return value
\Drupal\Core\Entity\EntityInterface The created test entity.
3 calls to EntityValidationTest::createTestEntity()
- EntityValidationTest::checkValidation in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityValidationTest.php - Executes the validation test set for a defined entity type.
- EntityValidationTest::testCompositeConstraintValidation in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityValidationTest.php - Tests composite constraints.
- EntityValidationTest::testEntityChangedConstraintOnConcurrentMultilingualEditing in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityValidationTest.php - Tests the EntityChangedConstraintValidator with multiple translations.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityValidationTest.php, line 77
Class
- EntityValidationTest
- Tests the Entity Validation API.
Namespace
Drupal\KernelTests\Core\EntityCode
protected function createTestEntity($entity_type) : EntityInterface {
$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 = $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.
if ($entity->hasField('field_test_text')) {
$this->entityFieldText = $this->randomMachineName();
$entity->field_test_text->value = $this->entityFieldText;
}
return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.