You are here

protected function CommentDefaultFormatterCacheTagsTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 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 34

Class

CommentDefaultFormatterCacheTagsTest
Tests the bubbling up of comment cache tags when using the Comment list formatter on an entity.

Namespace

Drupal\Tests\comment\Kernel

Code

protected function setUp() {
  parent::setUp();
  $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',
  ]));

  // Install tables and config needed to render comments.
  $this
    ->installSchema('comment', [
    'comment_entity_statistics',
  ]);
  $this
    ->installConfig([
    'system',
    'filter',
    'comment',
  ]);

  // Comment rendering generates links, so build the router.
  $this->container
    ->get('router.builder')
    ->rebuild();

  // 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');
}