function EntityCreationTrait::createEntity
Same name in other branches
- 4.0.x src/Testing/EntityCreationTrait.php \Drupal\ctools\Testing\EntityCreationTrait::createEntity()
Creates a custom content type based on default settings.
Parameters
string $entity_type: The type of entity to create.
array $values: An array of settings to change from the defaults. Example: 'type' => 'foo'.
Return value
\Drupal\Core\Entity\EntityInterface Created entity.
1 call to EntityCreationTrait::createEntity()
- RelationshipsTestBase::setUp in tests/
src/ Kernel/ RelationshipsTestBase.php
File
-
src/
Testing/ EntityCreationTrait.php, line 31
Class
- EntityCreationTrait
- Trait used for common entity creation methods.
Namespace
Drupal\ctools\TestingCode
protected function createEntity($entity_type, array $values = []) {
$storage = $this->getEntityTypeManager()
->getStorage($entity_type);
$entity = $storage->create($values);
$status = $entity->save();
\Drupal::service('router.builder')->rebuild();
if ($this instanceof \PHPUnit\Framework\TestCase) {
// phpcs:ignore
$this->assertSame(SAVED_NEW, $status, (new FormattableMarkup('Created entity %id of type %type.', [
'%id' => $entity->id(),
'%type' => $entity_type,
]))
->__toString());
//psp
}
else {
// phpcs:ignore
$this->assertEquals(SAVED_NEW, $status, (new FormattableMarkup('Created entity %id of type %type.', [
'%id' => $entity->id(),
'%type' => $entity_type,
]))
->__toString());
}
return $entity;
}