admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer permissions'));
$this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content'));
$this->drupalLogin($this->web_user);
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$this->drupalLogout();
}
/**
* Test comments as part of RSS feed.
*/
function testCommentRSS() {
$this->drupalLogin($this->web_user);
$comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
$this->drupalGet('rss.xml');
$raw = '' . url('node/' . $this->node->nid, array('fragment' => 'comments', 'absolute' => TRUE)) . '';
$this->assertRaw($raw, t('Comments as part of RSS feed.'));
}
/**
* Post comment.
*
* @param object $node Node to post comment on.
* @param string $subject Comment subject.
* @param string $comment Comment body.
* @param boolean $preview Should preview be required.
* @param mixed $contact Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.
*/
function postComment($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->assertNoFieldByName('op', t('Save'), t('Save button not found.')); // Preview required so no save button should be found.
$this->drupalPost(NULL, $edit, t('Preview'));
}
$this->drupalPost(NULL, $edit, t('Save'));
$match = array();
// Get comment ID
preg_match('/#comment-([^"]+)/', $this->getURL(), $match);
// Get comment.
if ($contact !== TRUE) { // If true then attempting to find error message.
$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);
}
}
/**
* Checks current page for specified comment.
*
* @param object $comment Comment object.
* @param boolean $reply The comment is a reply to another comment.
* @return boolean Comment found.
*/
function commentExists($comment, $reply = FALSE) {
if ($comment && is_object($comment)) {
$regex = '/' . ($reply ? '
(.*?)' : '');
$regex .= '