function CommentActionsTest::setUp

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

Overrides EntityKernelTestBase::setUp

File

core/modules/comment/tests/src/Kernel/CommentActionsTest.php, line 44

Class

CommentActionsTest
Tests actions provided by the Comment module.

Namespace

Drupal\Tests\comment\Kernel

Code

protected function setUp() : void {
    parent::setUp();
    $this->installConfig([
        'user',
        'comment',
    ]);
    $this->installSchema('comment', [
        'comment_entity_statistics',
    ]);
    // Create a comment type.
    CommentType::create([
        'id' => 'comment',
        'label' => 'Default comments',
        'description' => 'Default comment field',
        'target_entity_type_id' => 'entity_test',
    ])->save();
    $this->addDefaultCommentField('entity_test', 'entity_test', 'comment');
    // Setup date format to render comment date.
    DateFormat::create([
        'id' => 'fallback',
        'pattern' => 'D, m/d/Y - H:i',
        'label' => 'Fallback',
    ])->save();
    // Create format without filters to prevent filtering.
    FilterFormat::create([
        'format' => 'no_filters',
        'name' => 'No filters',
        'filters' => [],
    ])->save();
    // Set current user to allow filters display comment body.
    $this->drupalSetCurrentUser($this->drupalCreateUser());
    $this->keywords = [
        $this->randomMachineName(),
        $this->randomMachineName(),
    ];
    // Create a comment against a test entity.
    $host = EntityTest::create();
    $host->save();
    $this->comment = Comment::create([
        'entity_type' => 'entity_test',
        'name' => $this->randomString(),
        'hostname' => 'magic.example.com',
        'mail' => 'tonythemagicalpony@example.com',
        'subject' => $this->keywords[0],
        'comment_body' => $this->keywords[1],
        'entity_id' => $host->id(),
        'comment_type' => 'comment',
        'field_name' => 'comment',
    ]);
    $this->comment
        ->get('comment_body')->format = 'no_filters';
    $this->comment
        ->setPublished();
}

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