You are here

public function ReadTest::testResourceStructure in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rest/src/Tests/ReadTest.php \Drupal\rest\Tests\ReadTest::testResourceStructure()

Tests the resource structure.

File

core/modules/rest/src/Tests/ReadTest.php, line 104
Contains \Drupal\rest\Tests\ReadTest.

Class

ReadTest
Tests the retrieval of resources.

Namespace

Drupal\rest\Tests

Code

public function testResourceStructure() {

  // Enable a service with a format restriction but no authentication.
  $this
    ->enableService('entity:node', 'GET', 'json');

  // Create a user account that has the required permissions to read
  // resources via the REST API.
  $permissions = $this
    ->entityPermissions('node', 'view');
  $permissions[] = 'restful get entity:node';
  $account = $this
    ->drupalCreateUser($permissions);
  $this
    ->drupalLogin($account);

  // Create an entity programmatically.
  $entity = $this
    ->entityCreate('node');
  $entity
    ->save();

  // Read it over the REST API.
  $response = $this
    ->httpRequest($entity
    ->urlInfo()
    ->setRouteParameter('_format', 'json'), 'GET');
  $this
    ->assertResponse('200', 'HTTP response code is correct.');
}