You are here

public function TokenReplaceWebTest::testTokens in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/System/TokenReplaceWebTest.php \Drupal\Tests\system\Functional\System\TokenReplaceWebTest::testTokens()
  2. 9 core/modules/system/tests/src/Functional/System/TokenReplaceWebTest.php \Drupal\Tests\system\Functional\System\TokenReplaceWebTest::testTokens()

Tests a token replacement on an actual website.

File

core/modules/system/tests/src/Functional/System/TokenReplaceWebTest.php, line 31

Class

TokenReplaceWebTest
Tests the token system integration.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testTokens() {
  $node = $this
    ->drupalCreateNode();
  $account = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('token-test/' . $node
    ->id());
  $this
    ->assertSession()
    ->pageTextContains("Tokens: {$node->id()} {$account->id()}");
  $this
    ->assertCacheTags([
    'node:1',
    'rendered',
    'user:2',
  ]);
  $this
    ->assertCacheContexts([
    'languages:language_interface',
    'theme',
    'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT,
    'user',
  ]);
  $this
    ->drupalGet('token-test-without-bubbleable-metadata/' . $node
    ->id());
  $this
    ->assertSession()
    ->pageTextContains("Tokens: {$node->id()} {$account->id()}");
  $this
    ->assertCacheTags([
    'node:1',
    'rendered',
    'user:2',
  ]);
  $this
    ->assertCacheContexts([
    'languages:language_interface',
    'theme',
    'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT,
    'user',
  ]);
}