You are here

function RestfulListTestCase::testAccessHandeling in RESTful 7

Test error handeling when no access is granted to an entity in a list.

File

tests/RestfulListTestCase.test, line 757
Contains RestfulListTestCase

Class

RestfulListTestCase
@file Contains RestfulListTestCase

Code

function testAccessHandeling() {
  $settings = array(
    'type' => 'article',
  );
  $node1 = $this
    ->drupalCreateNode($settings);
  $node2 = $this
    ->drupalCreateNode($settings);
  $node3 = $this
    ->drupalCreateNode($settings);
  $user1 = $this
    ->drupalCreateUser();

  // Deny access via hook_node_access() to a specific node.
  restful_test_deny_access_node($node2->nid);
  $handler = restful_get_restful_handler('articles');
  $handler
    ->setAccount($user1);
  $result = $handler
    ->get();
  $this
    ->assertEqual(count($result), 2, 'List returned and ignored un-accessible entity.');

  // Get a list with specific IDs.
  $ids = array(
    $node1->nid,
    $node2->nid,
    $node3->nid,
  );
  try {
    $handler
      ->get(implode(',', $ids));
    $this
      ->fail('Exception was not thrown for un-accessible node for specific IDs list.');
  } catch (\RestfulForbiddenException $e) {
    $this
      ->pass('Exception was thrown for un-accessible node for specific IDs list.');
  } catch (\Exception $e) {
    $this
      ->fail('Exception of wrong type was thrown for un-accessible node for specific IDs list.');
  }
}