function CommentIntegrationTest::testCommentDefaultOwner

Same name in other branches
  1. 9 core/modules/comment/tests/src/Kernel/CommentIntegrationTest.php \Drupal\Tests\comment\Kernel\CommentIntegrationTest::testCommentDefaultOwner()
  2. 8.9.x core/modules/comment/tests/src/Kernel/CommentIntegrationTest.php \Drupal\Tests\comment\Kernel\CommentIntegrationTest::testCommentDefaultOwner()
  3. 11.x core/modules/comment/tests/src/Kernel/CommentIntegrationTest.php \Drupal\Tests\comment\Kernel\CommentIntegrationTest::testCommentDefaultOwner()

Tests the default owner of comment entities.

File

core/modules/comment/tests/src/Kernel/CommentIntegrationTest.php, line 154

Class

CommentIntegrationTest
Tests integration of comment with other components.

Namespace

Drupal\Tests\comment\Kernel

Code

public function testCommentDefaultOwner() : void {
    $comment = Comment::create([
        'comment_type' => 'comment',
    ]);
    $this->assertEquals(0, $comment->getOwnerId());
    $user = $this->createUser();
    $this->container
        ->get('current_user')
        ->setAccount($user);
    $comment = Comment::create([
        'comment_type' => 'comment',
    ]);
    $this->assertEquals($user->id(), $comment->getOwnerId());
}

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