You are here

protected function InventoryTest::requestApiEntity in farmOS 2.x

Helper function to request an entity from the API.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to request.

Return value

array The json-decoded response.

1 call to InventoryTest::requestApiEntity()
InventoryTest::testApiInventory in modules/core/inventory/tests/src/Functional/InventoryTest.php
Test retrieving asset inventory via API.

File

modules/core/inventory/tests/src/Functional/InventoryTest.php, line 127

Class

InventoryTest
Tests for farmOS inventory logic.

Namespace

Drupal\Tests\farm_inventory\Functional

Code

protected function requestApiEntity(EntityInterface $entity) {
  $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
  $asset_uri = "base://api/{$entity->getEntityType()->id()}/{$entity->bundle()}/{$entity->uuid()}";
  $response = $this
    ->request('GET', Url::fromUri($asset_uri), $request_options);
  return Json::decode((string) $response
    ->getBody());
}