You are here

public function RestfulCommentTestCase::testUpdateCommentAsPut in RESTful 7.2

Test updating a comment (PUT method).

File

tests/RestfulCommentTestCase.test, line 117
Contains RestfulCommentTestCase

Class

RestfulCommentTestCase
@file Contains RestfulCommentTestCase

Code

public function testUpdateCommentAsPut() {
  $resource_manager = restful()
    ->getResourceManager();
  $label = $this
    ->randomName();
  $new_label = $this
    ->randomName();
  $text = $this
    ->randomName();
  $settings = array(
    'node_type' => 'comment_node_article',
    'nid' => $this->node->nid,
    'uid' => $this->account->uid,
    'subject' => $label,
  );
  $settings['comment_text'][LANGUAGE_NONE][0]['value'] = $text;
  $comment = $this
    ->createComment($settings);
  $id = $comment->cid;
  $handler = $resource_manager
    ->getPlugin('comments:1.0');
  $handler
    ->setAccount($this->account);
  $request = array(
    'label' => $new_label,
  );
  $result = drupal_json_decode(restful()
    ->getFormatterManager()
    ->format($handler
    ->doPut($id, $request), 'json'));
  $result = $result['data'];
  $expected_result = array(
    array(
      'id' => $id,
      'label' => $new_label,
      'self' => $handler
        ->versionedUrl($id),
      'nid' => $this->node->nid,
      'comment_text' => NULL,
    ),
  );
  $result[0]['comment_text'] = trim(strip_tags($result[0]['comment_text']));
  $this
    ->assertEqual($result, $expected_result);
}