function ServicesResourceNodetests::testCommentLoadNodeComments in Services 6.3
Same name and namespace in other branches
- 7.3 tests/functional/ServicesResourceNodeTests.test \ServicesResourceNodetests::testCommentLoadNodeComments()
Test loadNodeComments method.
File
- tests/
functional/ ServicesResourceNodeTests.test, line 285
Class
- ServicesResourceNodetests
- Run test cases for the endpoint with no authentication turned on.
Code
function testCommentLoadNodeComments() {
$path = $this->endpoint->path;
$this->privilegedUser = $this
->drupalCreateUser(array(
'administer services',
));
$this
->drupalLogin($this->privilegedUser);
// Create node with commenting.
$settings = array(
'comment' => COMMENT_NODE_READ_WRITE,
);
$node = $this
->drupalCreateNode($settings);
$nid = $node->nid;
// Generate 15 comments for node.
$comments = array();
for ($i = 0; $i < 15; $i++) {
$comment = array(
'uid' => $this->privilegedUser->uid,
'nid' => $nid,
'subject' => $this
->randomString(),
'comment' => $this
->randomString(),
);
$cid = comment_save($comment);
$comments[] = _comment_load($cid);
}
$comments = array_reverse($comments);
// Generate some comments for another node.
$settings = array(
'comment' => COMMENT_NODE_READ_WRITE,
);
$node2 = $this
->drupalCreateNode($settings);
for ($i = 0; $i < 5; $i++) {
$comment = array(
'uid' => $this->privilegedUser->uid,
'nid' => $node2->nid,
'subject' => $this
->randomString(),
'comment' => $this
->randomString(),
);
$cid = comment_save($comment);
}
// Load all comments of the first node.
$response = $this
->servicesGet($path . '/node/' . $nid . '/comments');
$this
->assertEqual($comments, $response['body'], t('Received all 15 comments.'), 'NodeResource: comments');
// Load only 5 comments of the first node.
$response = $this
->servicesGet($path . '/node/' . $nid . '/comments', array(
'count' => 5,
));
$this
->assertEqual(array_slice($comments, 0, 5), array_slice($response['body'], 0, 5), t('Received last 5 comments.'), 'NodeResource: comments');
// Load only 5 comments of the first node starting from fifth comment.
$response = $this
->servicesGet($path . '/node/' . $nid . '/comments', array(
'count' => 5,
'offset' => 5,
));
$this
->assertEqual(array_slice($comments, 5, 5), array_merge(array(), $response['body']), t('Received 5 comments starting from fifth comment.'), 'NodeResource: comments');
}