You are here

public function EntityResourceTest::testGetRelationship in JSON:API 8.2

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

@covers ::getRelationship

File

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

Class

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

Namespace

Drupal\Tests\jsonapi\Kernel\Controller

Code

public function testGetRelationship() {

  // to-one relationship.
  $resource_type = new ResourceType('node', 'article', NULL);
  $resource_type
    ->setRelatableResourceTypes([
    'uid' => [
      new ResourceType('user', 'user', NULL),
    ],
  ]);
  $response = $this->entityResource
    ->getRelationship($resource_type, $this->node, 'uid', Request::create('/jsonapi/node/article/' . $this->node
    ->uuid() . '/relationships/uid'));
  $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());
}