You are here

protected function EntityHierarchyTestTrait::createTestEntity in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Traits/EntityHierarchyTestTrait.php \Drupal\Tests\entity_hierarchy\Traits\EntityHierarchyTestTrait::createTestEntity()

Creates a new test entity.

Parameters

int|null $parentId: Parent ID.

string $label: Entity label.

int $weight: Entity weight amongst sibling, if parent is set.

Return value

\Drupal\Core\Entity\EntityInterface New entity.

28 calls to EntityHierarchyTestTrait::createTestEntity()
AutocompleteHandlerTest::testAutoCompleteHandler in tests/src/Kernel/AutocompleteHandlerTest.php
Tests autocomplete handler.
EntityHierarchyTestTrait::additionalSetup in tests/src/Traits/EntityHierarchyTestTrait.php
Perform additional setup.
EntityHierarchyTestTrait::doCreateChildTestEntity in tests/src/Traits/EntityHierarchyTestTrait.php
Creates a new test entity.
EntityHierarchyValidationTest::testValidation in tests/src/Kernel/EntityHierarchyValidationTest.php
Tests validation.
HierarchyNestedSetIntegrationTest::testDeleteChild in tests/src/Kernel/HierarchyNestedSetIntegrationTest.php
Tests deleting child node.

... See full list

4 methods override EntityHierarchyTestTrait::createTestEntity()
ForwardRevisionNodeValidationTest::createTestEntity in tests/src/Functional/ForwardRevisionNodeValidationTest.php
Creates a new test entity.
HierarchyNestedSetRevisionIntegrationTest::createTestEntity in tests/src/Kernel/HierarchyNestedSetRevisionIntegrationTest.php
Creates a new test entity.
ReorderChildrenWithRevisionsFunctionalTest::createTestEntity in tests/src/Functional/ReorderChildrenWithRevisionsFunctionalTest.php
Creates a new test entity.
ViewsRevisionableIntegrationTest::createTestEntity in tests/src/Kernel/ViewsRevisionableIntegrationTest.php
Creates a new test entity.

File

tests/src/Traits/EntityHierarchyTestTrait.php, line 127

Class

EntityHierarchyTestTrait
Defines a trait for common testing methods for entity hierarchy.

Namespace

Drupal\Tests\entity_hierarchy\Traits

Code

protected function createTestEntity($parentId, $label = 'Child 1', $weight = 0) {
  $values = [
    'type' => static::ENTITY_TYPE,
    $this->container
      ->get('entity_type.manager')
      ->getDefinition(static::ENTITY_TYPE)
      ->getKey('label') => $label,
  ];
  if ($parentId) {
    $values[static::FIELD_NAME] = [
      'target_id' => $parentId,
      'weight' => $weight,
    ];
  }
  $entity = $this
    ->doCreateTestEntity($values);
  $entity
    ->save();
  return $entity;
}