function ServicesResourceNodetests::testCommentLoadNodeComments in Services 7.3
Same name and namespace in other branches
- 6.3 tests/functional/ServicesResourceNodeTests.test \ServicesResourceNodetests::testCommentLoadNodeComments()
Test loadNodeComments method.
File
- tests/
functional/ ServicesResourceNodeTests.test, line 132 - Call the endpoint tests when no authentication is being used.
Class
- ServicesResourceNodetests
- Run test cases for the endpoint with no authentication turned on.
Code
function testCommentLoadNodeComments() {
$path = $this->endpoint->path;
$this->privileged_user = $this
->drupalCreateUser();
$this
->drupalLogin($this->privileged_user);
// Create node with commenting.
$node = $this
->drupalCreateNode();
$nid = $node->nid;
// Generate 15 comments for node.
$comments = array();
for ($i = 1; $i <= 15; $i++) {
$comment = (object) $this
->getCommentValues($nid);
comment_save($comment);
$comments[$i] = comment_load($comment->cid);
}
// Generate some comments for another node.
$node2 = $this
->drupalCreateNode();
for ($i = 1; $i <= 5; $i++) {
$comment = (object) $this
->getCommentValues($node2->nid);
comment_save($comment);
}
// Load all comments of the first node.
$response = $this
->servicesGet($path . '/node/' . $nid . '/comments');
$this
->assertEqual($comments, $response['body'], '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), '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']), 'Received 5 comments starting from fifth comment.', 'NodeResource: comments');
}