You are here

protected function NodeTest::createEntity in JSON:API 8.2

Same name and namespace in other branches
  1. 8 tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::createEntity()

Creates the entity to be tested.

Return value

\Drupal\Core\Entity\EntityInterface The entity to be tested.

Overrides ResourceTestBase::createEntity

File

tests/src/Functional/NodeTest.php, line 108

Class

NodeTest
JSON:API integration test for the "Node" content entity type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function createEntity() {
  if (!NodeType::load('camelids')) {

    // Create a "Camelids" node type.
    NodeType::create([
      'name' => 'Camelids',
      'type' => 'camelids',
    ])
      ->save();
  }

  // Create a "Llama" node.
  $node = Node::create([
    'type' => 'camelids',
  ]);
  $node
    ->setTitle('Llama')
    ->setOwnerId($this->account
    ->id())
    ->setPublished()
    ->setCreatedTime(123456789)
    ->setChangedTime(123456789)
    ->setRevisionCreationTime(123456789)
    ->set('path', '/llama')
    ->save();
  return $node;
}