protected function CommentNotifyTestBase::postComment in Comment Notify 8
Post comment.
Parameters
string $url: The url where the comment will be submitted.
string $subject: Comment subject.
string $comment: Comment body.
array $notify: An array with the notify values.
mixed $contact: Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.
Return value
array|bool return an array with the comment or false if the post comment fails.
8 calls to CommentNotifyTestBase::postComment()
- CommentNotifyAnonymousTest::testAnonymousAllCommentsTest in tests/
src/ Functional/ CommentNotifyAnonymousTest.php - Tests the "All comments" notification option used by an anonymous user.
- CommentNotifyAnonymousTest::testAnonymousRepliesTest in tests/
src/ Functional/ CommentNotifyAnonymousTest.php - Tests the "Replies to my comment" option used by anonymous user.
- CommentNotifyAnonymousTest::testMail in tests/
src/ Functional/ CommentNotifyAnonymousTest.php - Tests that the mail is required for anonymous users.
- CommentNotifyConfigPageTest::testUnsubscribePage in tests/
src/ Functional/ CommentNotifyConfigPageTest.php - Tests the Unsubscribe page.
- CommentNotifyNotificationsTest::testCommentNotification in tests/
src/ Functional/ CommentNotifyNotificationsTest.php - Tests that the Mail notification is sent properly and it is only send once.
File
- tests/
src/ Functional/ CommentNotifyTestBase.php, line 87
Class
- CommentNotifyTestBase
- Comment notify Base Test class.
Namespace
Drupal\Tests\comment_notify\FunctionalCode
protected function postComment($url, $subject, $comment, array $notify, $contact = NULL) {
$edit = [];
$edit['subject[0][value]'] = $subject;
$edit['comment_body[0][value]'] = $comment;
if ($notify !== NULL && is_array($notify)) {
$edit += $notify;
}
if ($contact !== NULL && is_array($contact)) {
$edit += $contact;
}
$this
->drupalPostForm($url, $edit, t('Save'));
$match = [];
// Get comment ID.
preg_match('/#comment-([^"]+)/', $this
->getURL(), $match);
// Get comment.
// If true then attempting to find error message.
if (!empty($match[1])) {
if ($subject) {
$this
->assertTrue($this
->getSession()
->getPage()
->hasContent($subject), 'Comment subject posted.');
}
$this
->assertTrue($this
->getSession()
->getPage()
->hasContent($comment), 'Comment body posted.');
$this
->assertTrue(!empty($match) && !empty($match[1]), t('Comment id found.'));
}
if (isset($match[1])) {
return [
'id' => $match[1],
'subject' => $subject,
'comment' => $comment,
];
}
return FALSE;
}