function ViewsContentCacheTest::postComment in Views content cache 6.2
Same name and namespace in other branches
- 7.3 tests/views_content_cache.test \ViewsContentCacheTest::postComment()
Post comment.
Parameters
$node: Node to post comment on.
$comment: Comment body.
$subject: Comment subject.
$contact: Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.
1 call to ViewsContentCacheTest::postComment()
- ViewsContentCacheTest::testCommentAdded in tests/
views_content_cache.test - Test that when a comment is added to a story the timestamp is recorded.
File
- tests/
views_content_cache.test, line 117
Class
Code
function postComment($node, $comment, $subject = '', $contact = NULL) {
$edit = array();
$edit['comment'] = $comment;
$preview_mode = variable_get('comment_preview_' . $node->type, COMMENT_PREVIEW_REQUIRED);
$subject_mode = variable_get('comment_subject_field_' . $node->type, 1);
// Must get the page before we test for fields.
if ($node !== NULL) {
$this
->drupalGet('comment/reply/' . $node->nid);
}
if ($subject_mode == TRUE) {
$edit['subject'] = $subject;
}
if ($contact !== NULL && is_array($contact)) {
$edit += $contact;
}
switch ($preview_mode) {
case COMMENT_PREVIEW_REQUIRED:
// Preview required so no save button should be found.
$this
->assertNoFieldByName('op', t('Save'), t('Save button not found.'));
$this
->drupalPost(NULL, $edit, t('Preview'));
// Don't break here so that we can test post-preview field presence and
// function below.
case COMMENT_PREVIEW_OPTIONAL:
$this
->assertFieldByName('op', t('Preview'), t('Preview button found.'));
$this
->assertFieldByName('op', t('Save'), t('Save button found.'));
$this
->drupalPost(NULL, $edit, t('Save'));
break;
}
$match = array();
// Get comment ID
preg_match('/#comment-([0-9]+)/', $this
->getURL(), $match);
// Get comment.
if ($contact !== TRUE) {
// If true then attempting to find error message.
if ($subject) {
$this
->assertText($subject, 'Comment subject posted.');
}
$this
->assertText($comment, 'Comment body posted.');
$this
->assertTrue(!empty($match) && !empty($match[1]), t('Comment id found.'));
}
if (isset($match[1])) {
return (object) array(
'id' => $match[1],
'subject' => $subject,
'comment' => $comment,
);
}
}