function CommentDefaultFormatterCacheTagsTest::setUp

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

Overrides EntityKernelTestBase::setUp

File

core/modules/comment/tests/src/Kernel/CommentDefaultFormatterCacheTagsTest.php, line 33

Class

CommentDefaultFormatterCacheTagsTest
Tests comment cache tag bubbling up when using the Comment list formatter.

Namespace

Drupal\Tests\comment\Kernel

Code

protected function setUp() : void {
    parent::setUp();
    // Create user 1 so that the user created later in the test has a different
    // user ID.
    // @todo Remove in https://www.drupal.org/node/540008.
    $this->createUser([], NULL, FALSE, [
        'uid' => 1,
        'name' => 'user1',
    ])
        ->save();
    $this->container
        ->get('module_handler')
        ->loadInclude('comment', 'install');
    comment_install();
    $session = new Session();
    $request = Request::create('/');
    $request->setSession($session);
    
    /** @var \Symfony\Component\HttpFoundation\RequestStack $stack */
    $stack = $this->container
        ->get('request_stack');
    $stack->pop();
    $stack->push($request);
    // Set the current user to one that can access comments. Specifically, this
    // user does not have access to the 'administer comments' permission, to
    // ensure only published comments are visible to the end user.
    $current_user = $this->container
        ->get('current_user');
    $current_user->setAccount($this->createUser([
        'access comments',
        'post comments',
    ]));
    // Install tables and config needed to render comments.
    $this->installSchema('comment', [
        'comment_entity_statistics',
    ]);
    $this->installConfig([
        'system',
        'filter',
        'comment',
    ]);
    // Set up a field, so that the entity that'll be referenced bubbles up a
    // cache tag when rendering it entirely.
    $this->addDefaultCommentField('entity_test', 'entity_test');
}

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