You are here

function RestfulHalJsonTestCase::testHalEmbeddedResources in RESTful 7

Same name and namespace in other branches
  1. 7.2 tests/RestfulHalJsonTestCase.test \RestfulHalJsonTestCase::testHalEmbeddedResources()

Test embedded resources.

File

tests/RestfulHalJsonTestCase.test, line 27
Contains RestfulHalJsonTestCase

Class

RestfulHalJsonTestCase
@file Contains RestfulHalJsonTestCase

Code

function testHalEmbeddedResources() {
  $user1 = $this
    ->drupalCreateUser();
  $entity1 = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $user1->uid,
  ));
  $entity1
    ->save();
  $entity2 = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $user1->uid,
  ));
  $entity2
    ->save();
  $entity3 = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $user1->uid,
  ));
  $wrapper = entity_metadata_wrapper('entity_test', $entity3);
  $text1 = $this
    ->randomName();
  $text2 = $this
    ->randomName();
  $wrapper->text_single
    ->set($text1);
  $wrapper->text_multiple
    ->set(array(
    $text1,
    $text2,
  ));
  $wrapper->entity_reference_single
    ->set($entity1);
  $wrapper->entity_reference_multiple[] = $entity1;
  $wrapper->entity_reference_multiple[] = $entity2;
  $wrapper
    ->save();
  $response = $this
    ->httpRequest('api/main/' . $wrapper
    ->getIdentifier(), \RestfulInterface::GET, NULL, array(
    'X-API-Version' => 'v1.1',
    'Accept' => 'application/hal+json',
  ));
  $results = drupal_json_decode($response['body']);
  $this
    ->assertEqual($wrapper->entity_reference_multiple
    ->count() + 1, count($results['_embedded']['hal:main']));
}