You are here

public function RestfulViewModeAndFormatterTestCase::testViewModeIntegration in RESTful 7.2

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

Test the view mode integration.

File

tests/RestfulViewModeAndFormatterTestCase.test, line 27
Contains RestfulViewModeFormatterTestCase

Class

RestfulViewModeAndFormatterTestCase

Code

public function testViewModeIntegration() {
  $resource_manager = restful()
    ->getResourceManager();
  $handler = $resource_manager
    ->getPlugin('articles:1.7');
  $nodes[] = restful_test_create_node_with_tags();
  $nodes[] = restful_test_create_node_with_tags();

  // Make sure to get more than one node.
  $handler
    ->setRequest(Request::create('api/articles/v1.7/' . $nodes[0]->nid . ',' . $nodes[1]->nid));
  $handler
    ->setPath($nodes[0]->nid . ',' . $nodes[1]->nid);
  $result = drupal_json_decode(restful()
    ->getFormatterManager()
    ->format($handler
    ->process(), 'json'));
  $result = $result['data'];

  // Make sure that all the fields were mapped.
  $this
    ->assertNotNull($result[0]['body'], 'Body field is populated.');
  $this
    ->assertTrue($result[0]['tags'], 'Tags field is populated.');
  $this
    ->assertNotNull($result[0]['image'], 'Image field is not NULL.');
}