function NodeTest::createEntity

Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::createEntity()
  2. 10 core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::createEntity()
  3. 11.x core/modules/jsonapi/tests/src/Functional/NodeTest.php \Drupal\Tests\jsonapi\Functional\NodeTest::createEntity()

Overrides ResourceTestBase::createEntity

File

core/modules/jsonapi/tests/src/Functional/NodeTest.php, line 114

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.