You are here

public function ServicesResourceCommentTests::testCommentCreate in Services 7.3

Same name and namespace in other branches
  1. 6.3 tests/functional/ServicesResourceCommentTests.test \ServicesResourceCommentTests::testCommentCreate()

Test create comment.

File

tests/functional/ServicesResourceCommentTests.test, line 102
Call the endpoint tests when no authentication is being used.

Class

ServicesResourceCommentTests
Run test cases for the endpoint with no authentication turned on.

Code

public function testCommentCreate() {
  $node = $this
    ->drupalCreateNode();

  // Create comment.
  $comment = $this
    ->getCommentValues($node->nid);
  $response_array = $this
    ->servicesPost($this->endpoint->path . '/comment', $comment);
  $commentResourceCreateReturn = $response_array['body'];
  $this
    ->assertTrue(isset($commentResourceCreateReturn['cid']), 'Comment was successfully created', 'CommentResource: Create');

  // Assert subject and body of comment are the same as we created.
  $newComment = comment_load($commentResourceCreateReturn['cid']);
  $this
    ->assertTrue($newComment->subject == $comment['subject'], 'Subject was the same', 'CommentResource: Create');
  $this
    ->assertTrue($newComment->comment_body[LANGUAGE_NONE][0]['value'] == $comment['comment_body'][LANGUAGE_NONE][0]['value'], 'Body was the same', 'CommentResource: Create');

  // Try to create comment with full_html filter that is disabled by default.
  $comment = array(
    'subject' => $this
      ->randomString(),
    'comment_body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $this
            ->randomString(),
          'format' => 'full_html',
        ),
      ),
    ),
    'name' => $this->privileged_user->name,
    'language' => LANGUAGE_NONE,
    'nid' => $node->nid,
    'uid' => $this->privileged_user->uid,
    'cid' => NULL,
    'pid' => 0,
  );
  $response_array = $this
    ->servicesPost($this->endpoint->path . '/comment', $comment);
  $this
    ->assertTrue(strpos($response_array['status'], 'An illegal choice has been detected.'), 'User cannot post comment with full_html filter chosen.', 'CommentResource: Create');
}