function UnpublishByKeywordCommentTest::setUp

Overrides EntityKernelTestBase::setUp

File

core/modules/action/tests/src/Kernel/UnpublishByKeywordCommentTest.php, line 46

Class

UnpublishByKeywordCommentTest
@group action

Namespace

Drupal\Tests\action\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.