You are here

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

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/ForwardRevisionNodeValidationTest.php \Drupal\Tests\entity_hierarchy\Functional\ForwardRevisionNodeValidationTest::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.

Overrides EntityHierarchyTestTrait::createTestEntity

File

tests/src/Functional/ForwardRevisionNodeValidationTest.php, line 88

Class

ForwardRevisionNodeValidationTest
Defines a class for testing the warnings on edit form.

Namespace

Drupal\Tests\entity_hierarchy\Functional

Code

protected function createTestEntity($parentId, $label = 'Child 1', $weight = 0) {
  $values = [
    'type' => 'article',
    'title' => $label,
    'moderation_state' => 'published',
    'status' => 1,
  ];
  if ($parentId) {
    $values[static::FIELD_NAME] = [
      'target_id' => $parentId,
      'weight' => $weight,
    ];
  }
  $entity = $this
    ->doCreateTestEntity($values);
  $entity
    ->save();
  return $entity;
}