function CommentModuleTestCase::post_comment in SimpleTest 6
Post comment.
Parameters
object $node Node to post comment on.:
string $subject Comment subject.:
string $comment Comment body.:
boolean $preview Should preview be required.:
mixed $contact Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.:
2 calls to CommentModuleTestCase::post_comment()
- CommentModuleTestCase::testAnonymous in tests/
comment_module.test - Test anonymous comment functionality.
- CommentModuleTestCase::testFormOnPage in tests/
comment_module.test - Test comment form on node page.
File
- tests/
comment_module.test, line 203
Class
Code
function post_comment($node, $subject, $comment, $preview = TRUE, $contact = NULL) {
$edit = array();
$edit['subject'] = $subject;
$edit['comment'] = $comment;
if ($contact !== NULL && is_array($contact)) {
$edit += $contact;
}
if ($node !== NULL) {
$this
->drupalGet('comment/reply/' . $node->nid);
}
if ($preview) {
$this
->assertFieldById('edit-comment');
$this
->assertNoPattern('/(input)(.*?)(value="Save")/', 'Save button not found.');
// Preview required so no save button should be found.
$this
->drupalPost(NULL, $edit, 'Preview');
}
$this
->drupalPost(NULL, array(), 'Save');
$match = array();
// Get comment ID
preg_match('/#comment-([^"]+)/', $this->_browser
->getURL(), $match);
// get comment
if ($contact !== TRUE) {
// If true then attempting to find error message.
$this
->assertText($subject, 'Comment posted.');
$this
->assertTrue(!empty($match) && !empty($match[1]), 'Comment id found.');
}
if (isset($match[1])) {
return (object) array(
'id' => $match[1],
'subject' => $subject,
'comment' => $comment,
);
}
else {
return NULL;
}
}