You are here

public function RestfulReferenceTestCase::testPropertyReference in RESTful 7.2

Same name and namespace in other branches
  1. 7 tests/RestfulReferenceTestCase.test \RestfulReferenceTestCase::testPropertyReference()

Test property reference.

File

tests/RestfulReferenceTestCase.test, line 37
Contains RestfulReferenceTestCase.

Class

RestfulReferenceTestCase
Class RestfulReferenceTestCase.

Code

public function testPropertyReference() {
  $resource_manager = restful()
    ->getResourceManager();
  $user1 = $this
    ->drupalCreateUser();
  $settings = array(
    'type' => 'article',
    'uid' => $user1->uid,
  );
  $node1 = $this
    ->drupalCreateNode($settings);
  $node2 = $this
    ->drupalCreateNode($settings);
  variable_set('restful_test_reference_simple', TRUE);
  $resource_manager
    ->clearPluginCache('test_articles:1.2');
  $handler = $resource_manager
    ->getPlugin('test_articles:1.2');
  $handler
    ->setRequest(Request::create('api/test_articles/v1.2/' . $node1->nid));
  $handler
    ->setPath($node1->nid);
  $result = drupal_json_decode(restful()
    ->getFormatterManager()
    ->format($handler
    ->process(), 'json'));
  $result = $result['data'];
  $this
    ->assertEqual($result[0]['user']['uid'], $user1->uid, 'Property is not defined as resource, thus the referenced entity appears as the entity.');
  variable_set('restful_test_reference_resource', TRUE);
  $resource_manager
    ->clearPluginCache('test_articles:1.2');
  $handler = $resource_manager
    ->getPlugin('test_articles:1.2');
  $handler
    ->setRequest(Request::create('api/test_articles/v1.2/' . $node2->nid));
  $handler
    ->setPath($node2->nid);
  $result = drupal_json_decode(restful()
    ->getFormatterManager()
    ->format($handler
    ->process(), 'json'));
  $result = $result['data'];
  $this
    ->assertEqual($result[0]['user']['id'], $user1->uid, 'Property is defined as resource, thus the referenced entity appears as the rendered resource.');
}