You are here

function RestfulCreatePrivateNodeTestCase::testCreateNodeWithReference in RESTful 7

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

Test creating a node (POST method) with reference to existing private node.

In this test we make sure that entity_metadata_no_hook_node_access() returns TRUE, thus allows access to set the entity reference property.

See also

restful_node_access_test_node_access_records()

File

tests/RestfulCreatePrivateNodeTestCase.test, line 35
Contains RestfulCreatePrivateNodeTestCase

Class

RestfulCreatePrivateNodeTestCase
@file Contains RestfulCreatePrivateNodeTestCase

Code

function testCreateNodeWithReference() {
  $user1 = $this
    ->drupalCreateUser(array(
    'create article content',
  ));
  $user2 = $this
    ->drupalCreateUser(array(
    'create article content',
  ));
  $this
    ->drupalLogin($user1);
  $settings = array(
    'type' => 'article',
    'uid' => $user1->uid,
  );

  // Create a node that will be set to private.
  $node1 = $this
    ->drupalCreateNode($settings);

  // Assert user has access to the node.
  $this
    ->assertTrue(node_access('view', $node1, $user1), 'Author has access to view node.');

  // Assert another user doesn't have access to the node.
  $this
    ->assertFalse(node_access('view', $node1, $user2), 'Authenticated user, but not author does not have access to view the node.');
  $handler = restful_get_restful_handler('test_articles', 1, 2);
  $handler
    ->setAccount($user1);
  $request = array(
    'label' => $this
      ->randomName(),
    'entity_reference_single' => $node1->nid,
  );
  $result = $handler
    ->post('', $request);
  $this
    ->assertTrue($result, 'Private node with reference to another private node was created.');
}