protected function RestfulCommentTestCase::createComment in RESTful 7.2
Creates a comment based on default settings.
Parameters
array $settings: An associative array of settings to change from the defaults, keys are comment properties, for example 'subject' => 'Hello, world!'.
Return value
object Created comment object.
4 calls to RestfulCommentTestCase::createComment()
- RestfulCommentTestCase::testDeleteComment in tests/
RestfulCommentTestCase.test - Test deleting a comment (DELETE method).
- RestfulCommentTestCase::testRetrieve in tests/
RestfulCommentTestCase.test - Test creating a comment (GET method).
- RestfulCommentTestCase::testUpdateCommentAsPatch in tests/
RestfulCommentTestCase.test - Test updating a comment (PATCH method).
- RestfulCommentTestCase::testUpdateCommentAsPut in tests/
RestfulCommentTestCase.test - Test updating a comment (PUT method).
File
- tests/
RestfulCommentTestCase.test, line 272 - Contains RestfulCommentTestCase
Class
- RestfulCommentTestCase
- @file Contains RestfulCommentTestCase
Code
protected function createComment($settings = array()) {
// Populate defaults array.
$settings += array(
'cid' => FALSE,
'pid' => 0,
'subject' => $this
->randomName(8),
'status' => COMMENT_PUBLISHED,
'node_type' => 'comment_node_article',
'language' => LANGUAGE_NONE,
'comment_text' => array(
LANGUAGE_NONE => array(
array(),
),
),
);
// If the comment's user uid is not specified manually, use the currently
// logged in user if available, or else the user running the test.
if (!isset($settings['uid'])) {
if ($this->loggedInUser) {
$settings['uid'] = $this->loggedInUser->uid;
}
else {
global $user;
$settings['uid'] = $user->uid;
}
}
// Merge comment text field value and format separately.
$body = array(
'value' => $this
->randomName(32),
'format' => filter_default_format(),
);
$settings['comment_text'][$settings['language']][0] += $body;
$comment = (object) $settings;
comment_save($comment);
return $comment;
}