You are here

RestfulCreatePrivateNodeTestCase.test in RESTful 7

Same filename and directory in other branches
  1. 7.2 tests/RestfulCreatePrivateNodeTestCase.test

Contains RestfulCreatePrivateNodeTestCase

File

tests/RestfulCreatePrivateNodeTestCase.test
View source
<?php

/**
 * @file
 * Contains RestfulCreatePrivateNodeTestCase
 */
class RestfulCreatePrivateNodeTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Node access integration',
      'description' => 'Test the creation of a node entity type with private access.',
      'group' => 'RESTful',
    );
  }
  function setUp() {
    parent::setUp('restful_example', 'restful_node_access_test');

    // Add entity reference fields.
    restful_test_add_fields('node', 'article');

    // Rebuild node access.
    node_access_rebuild();
  }

  /**
   * 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 restful_node_access_test_node_access_records()
   */
  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.');
  }

}

Classes

Namesort descending Description
RestfulCreatePrivateNodeTestCase @file Contains RestfulCreatePrivateNodeTestCase