You are here

public function RestfulCreateNodeTestCase::testCreateNode in RESTful 7.2

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

Test creating a node (POST method).

File

tests/RestfulCreateNodeTestCase.test, line 28
Contains RestfulCreateNodeTestCase

Class

RestfulCreateNodeTestCase

Code

public function testCreateNode() {
  $resource_manager = restful()
    ->getResourceManager();
  $user1 = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($user1);
  $handler = $resource_manager
    ->getPlugin('articles:1.1');

  // Set a different user from the logged in user, to assert the node's author
  // is set correctly.
  $user2 = $this
    ->drupalCreateUser(array(
    'create article content',
  ));
  $handler
    ->setAccount($user2);
  $text1 = $this
    ->randomName();
  $request = array(
    'label' => $text1,
  );
  $handler
    ->setRequest(Request::create('', array(), RequestInterface::METHOD_POST, NULL, FALSE, NULL, array(), array(), array(), $request));
  $handler
    ->setPath('');
  $result = drupal_json_decode(restful()
    ->getFormatterManager()
    ->format($handler
    ->process(), 'json'));
  $result = $result['data'];
  $node = node_load($result[0]['id']);
  $this
    ->assertEqual($node->uid, $user2->uid, 'Correct user was set to be the author of the node.');
  $this
    ->assertEqual($node->title, $text1, 'Correct title set.');
}