You are here

protected function CommentDefaultFormatterCacheTagsTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/comment/tests/src/Kernel/CommentDefaultFormatterCacheTagsTest.php \Drupal\Tests\comment\Kernel\CommentDefaultFormatterCacheTagsTest::setUp()
  2. 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 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() : 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([
    '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');
}