You are here

public function RestfulListEntityMultipleBundlesTestCase::testList in RESTful 7.2

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

Test listing an entity with multiple bundles.

File

tests/RestfulListEntityMultipleBundlesTestCase.test, line 31
Contains RestfulListEntityMultipleBundlesTestCase

Class

RestfulListEntityMultipleBundlesTestCase
@file Contains RestfulListEntityMultipleBundlesTestCase

Code

public function testList() {
  $user1 = $this
    ->drupalCreateUser();

  /* @var \Entity $entity1 */
  $entity1 = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $user1->uid,
  ));
  $entity1
    ->save();
  $entity2 = entity_create('entity_test', array(
    'name' => 'main',
    'uid' => $user1->uid,
  ));

  /* @var \Entity $entity2 */
  $entity2
    ->save();
  $entity3 = entity_create('entity_test', array(
    'name' => 'test',
    'uid' => $user1->uid,
  ));

  /* @var \Entity $entity3 */
  $entity3
    ->save();
  $handler = restful()
    ->getResourceManager()
    ->getPlugin('entity_tests:1.0');
  $formatter = restful()
    ->getFormatterManager()
    ->getPlugin('json');
  $formatter
    ->setResource($handler);
  $expected_result = array(
    array(
      'id' => $entity1->pid,
      'label' => 'Main test type',
      'self' => url('api/v1.0/entity_tests/' . $entity1->pid, array(
        'absolute' => TRUE,
      )),
      'main_bundle' => array(
        'id' => $entity1->pid,
        'label' => 'Main test type',
        'self' => url('api/v1.0/main/' . $entity1->pid, array(
          'absolute' => TRUE,
        )),
      ),
      'tests_bundle' => NULL,
    ),
    array(
      'id' => $entity2->pid,
      'label' => 'Main test type',
      'self' => url('api/v1.0/entity_tests/' . $entity2->pid, array(
        'absolute' => TRUE,
      )),
      'main_bundle' => array(
        'id' => $entity2->pid,
        'label' => 'Main test type',
        'self' => url('api/v1.0/main/' . $entity2->pid, array(
          'absolute' => TRUE,
        )),
      ),
      'tests_bundle' => NULL,
    ),
    array(
      'id' => $entity3->pid,
      'label' => 'label',
      'self' => url('api/v1.0/entity_tests/' . $entity3->pid, array(
        'absolute' => TRUE,
      )),
      'main_bundle' => NULL,
      'tests_bundle' => array(
        'type' => 'test',
        'id' => $entity3->pid,
        'label' => 'label',
        'self' => url('api/v1.0/tests/' . $entity3->pid, array(
          'absolute' => TRUE,
        )),
      ),
    ),
  );
  $result = $formatter
    ->prepare($handler
    ->doGet());
  $this
    ->assertEqual($result['data'], $expected_result);
}