function CommentAttributesTest::saveComment

Same name in other branches
  1. 8.9.x core/modules/rdf/tests/src/Functional/CommentAttributesTest.php \Drupal\Tests\rdf\Functional\CommentAttributesTest::saveComment()

Creates a comment entity.

Parameters

$nid: Node id which will hold the comment.

$uid: User id of the author of the comment. Can be NULL if $contact provided.

$contact: Set to NULL for no contact info, TRUE to ignore success checking, and array of values to set contact info.

$pid: Comment id of the parent comment in a thread.

Return value

\Drupal\comment\Entity\Comment The saved comment.

4 calls to CommentAttributesTest::saveComment()
CommentAttributesTest::testCommentRdfaMarkup in core/modules/rdf/tests/src/Functional/CommentAttributesTest.php
Tests if RDFa markup for meta information is present in comments.
CommentAttributesTest::testCommentRdfAuthorMarkup in core/modules/rdf/tests/src/Functional/CommentAttributesTest.php
Tests comment author link markup has not been broken by RDF.
CommentAttributesTest::testCommentReplyOfRdfaMarkup in core/modules/rdf/tests/src/Functional/CommentAttributesTest.php
Tests RDF comment replies.
CommentAttributesTest::testNumberOfCommentsRdfaMarkup in core/modules/rdf/tests/src/Functional/CommentAttributesTest.php
Tests the presence of the RDFa markup for the number of comments.

File

core/modules/rdf/tests/src/Functional/CommentAttributesTest.php, line 358

Class

CommentAttributesTest
Tests the RDFa markup of comments.

Namespace

Drupal\Tests\rdf\Functional

Code

public function saveComment($nid, $uid, $contact = NULL, $pid = 0) {
    $values = [
        'entity_id' => $nid,
        'entity_type' => 'node',
        'field_name' => 'comment',
        'uid' => $uid,
        'pid' => $pid,
        'subject' => $this->randomMachineName(),
        'comment_body' => $this->randomMachineName(),
        'status' => 1,
    ];
    if ($contact) {
        $values += $contact;
    }
    $comment = Comment::create($values);
    $comment->save();
    return $comment;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.