You are here

function ServicesResourceCommentTests::testCommentCountNew in Services 7.3

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

Test countNew method.

File

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

Class

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

Code

function testCommentCountNew() {
  $path = $this->endpoint->path;

  // Generate comments.
  $node = $this
    ->drupalCreateNode();
  $nid = $node->nid;
  for ($i = 0; $i < 5; $i++) {
    $comment = (object) $this
      ->getCommentValues($nid);
    $comment->created = REQUEST_TIME + $i;
    comment_save($comment);
    $comments[] = comment_load($comment->cid);
  }
  $response = $this
    ->servicesPost($path . '/comment/countNew', array(
    'nid' => $node->nid,
  ));
  $this
    ->assertEqual($response['body'], 5, 'Received number of all new comments.', 'CommentResource: countNew');
  $since = $comments[2]->created;
  $response = $this
    ->servicesPost($path . '/comment/countNew', array(
    'nid' => $node->nid,
    'since' => $since,
  ));
  $this
    ->assertEqual($response['body'], 2, 'Received number of new comments.', 'CommentResource: countNew');
}