You are here

public function EntityResourceTest::testCreateIndividual in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi\Kernel\Controller\EntityResourceTest::testCreateIndividual()

@covers ::createIndividual

File

tests/src/Kernel/Controller/EntityResourceTest.php, line 410

Class

EntityResourceTest
@coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @group jsonapi @group legacy

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testCreateIndividual() {
  $node = Node::create([
    'type' => 'article',
    'title' => 'Lorem ipsum',
  ]);
  Role::load(Role::ANONYMOUS_ID)
    ->grantPermission('create article content')
    ->save();
  $entity_resource = $this
    ->buildEntityResource('node', 'article');
  $response = $entity_resource
    ->createIndividual($node, new Request());

  // As a side effect, the node will also be saved.
  $this
    ->assertNotEmpty($node
    ->id());
  $this
    ->assertInstanceOf(JsonApiDocumentTopLevel::class, $response
    ->getResponseData());
  $this
    ->assertEquals(5, $response
    ->getResponseData()
    ->getData()
    ->id());
  $this
    ->assertEquals(201, $response
    ->getStatusCode());
}