You are here

public function EntityResourceTest::testGetRelationship 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::testGetRelationship()

@covers ::getRelationship

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testGetRelationship() {

  // to-one relationship.
  $entity_resource = $this
    ->buildEntityResource('node', 'article', [
    'uid' => [
      new ResourceType('user', 'user', NULL),
    ],
  ]);
  $response = $entity_resource
    ->getRelationship($this->node, 'uid', new Request());
  $this
    ->assertInstanceOf(JsonApiDocumentTopLevel::class, $response
    ->getResponseData());
  $this
    ->assertInstanceOf(EntityReferenceFieldItemListInterface::class, $response
    ->getResponseData()
    ->getData());
  $this
    ->assertEquals(1, $response
    ->getResponseData()
    ->getData()
    ->getEntity()
    ->id());
  $this
    ->assertEquals('node', $response
    ->getResponseData()
    ->getData()
    ->getEntity()
    ->getEntityTypeId());
}