You are here

public function EntityResourceTest::testCreateIndividualConfig in JSON:API Extras 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/Controller/EntityResourceTest.php \Drupal\Tests\jsonapi_extras\Kernel\Controller\EntityResourceTest::testCreateIndividualConfig()

@covers ::createIndividual

File

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

Class

EntityResourceTest
@coversDefaultClass \Drupal\jsonapi\Controller\EntityResource @covers \Drupal\jsonapi_extras\Normalizer\ConfigEntityNormalizer @group jsonapi_extras @group legacy

Namespace

Drupal\Tests\jsonapi_extras\Kernel\Controller

Code

public function testCreateIndividualConfig() {
  $node_type = NodeType::create([
    'type' => 'test',
    'name' => 'Test Type',
    'description' => 'Lorem ipsum',
  ]);
  Role::load(Role::ANONYMOUS_ID)
    ->grantPermission('administer content types')
    ->save();
  $resource_type = new ResourceType('node', 'article', NULL);
  $entity_resource = new EntityResource($resource_type, $this->container
    ->get('entity_type.manager'), $this->container
    ->get('entity_field.manager'), $this->container
    ->get('plugin.manager.field.field_type'), $this->container
    ->get('jsonapi.link_manager'), $this->container
    ->get('jsonapi.resource_type.repository'), $this->container
    ->get('renderer'));
  $response = $entity_resource
    ->createIndividual($node_type, new Request());

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