function CommentEntityReferenceTest::setUp

Same name and namespace in other branches
  1. 10 core/modules/comment/tests/src/Functional/CommentEntityReferenceTest.php \Drupal\Tests\comment\Functional\CommentEntityReferenceTest::setUp()

Overrides CommentTestBase::setUp

File

core/modules/comment/tests/src/Functional/CommentEntityReferenceTest.php, line 41

Class

CommentEntityReferenceTest
Tests that comments behave correctly when added as entity references.

Namespace

Drupal\Tests\comment\Functional

Code

protected function setUp() : void {
    parent::setUp();
    $this->createEntityReferenceField('node', 'article', 'entity_reference_comment', 'Entity Reference Comment', 'comment', 'default', [
        'target_bundles' => [
            'comment',
        ],
    ]);
    \Drupal::service('entity_display.repository')->getFormDisplay('node', 'article')
        ->setComponent('entity_reference_comment', [
        'type' => 'options_select',
    ])
        ->save();
    \Drupal::service('entity_display.repository')->getViewDisplay('node', 'article')
        ->setComponent('entity_reference_comment', [
        'type' => 'entity_reference_label',
    ])
        ->save();
    $administratorUser = $this->drupalCreateUser([
        'skip comment approval',
        'post comments',
        'access comments',
        'access content',
        'administer nodes',
        'administer comments',
        'bypass node access',
    ]);
    $this->drupalLogin($administratorUser);
    $this->node = $this->drupalCreateNode([
        'type' => 'article',
        'promote' => 1,
        'uid' => $this->webUser
            ->id(),
    ]);
    $this->comment = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
    $this->assertInstanceOf(Comment::class, $this->comment);
    $this->node2 = $this->drupalCreateNode([
        'title' => $this->randomMachineName(),
        'type' => 'article',
    ]);
}

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