You are here

function RestfulListEntityMultipleBundlesTestCase::testList in RESTful 7

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

Test listing an entity with multiple bundles.

File

tests/RestfulListEntityMultipleBundlesTestCase.test, line 25
Contains RestfulListEntityMultipleBundlesTestCase

Class

RestfulListEntityMultipleBundlesTestCase
@file Contains RestfulListEntityMultipleBundlesTestCase

Code

function testList() {
  $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' => 'test',
    'uid' => $user1->uid,
  ));
  $entity3
    ->save();
  $handler = restful_get_restful_handler('entity_tests');
  $expected_result = array(
    array(
      'id' => $entity1->pid,
      'label' => 'Main test type',
      'self' => url('api/v1.0/main/' . $entity1->pid, array(
        'absolute' => TRUE,
      )),
    ),
    array(
      'id' => $entity2->pid,
      'label' => 'Main test type',
      'self' => url('api/v1.0/main/' . $entity2->pid, array(
        'absolute' => TRUE,
      )),
    ),
    array(
      'id' => $entity3->pid,
      'label' => 'label',
      'self' => url('api/v1.0/tests/' . $entity3->pid, array(
        'absolute' => TRUE,
      )),
      // The "test" bundle also exposes the "type" property.
      'type' => 'test',
    ),
  );
  $result = $handler
    ->get();
  $this
    ->assertEqual($result, $expected_result);
}