You are here

public function TokenReplaceWebTest::testTokens in Zircon Profile 8

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

Tests a token replacement on an actual website.

File

core/modules/system/src/Tests/System/TokenReplaceWebTest.php, line 31
Contains \Drupal\system\Tests\System\TokenReplaceWebTest.

Class

TokenReplaceWebTest
Tests the token system integration.

Namespace

Drupal\system\Tests\System

Code

public function testTokens() {
  $node = $this
    ->drupalCreateNode();
  $account = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('token-test/' . $node
    ->id());
  $this
    ->assertText("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-bubleable-metadata/' . $node
    ->id());
  $this
    ->assertText("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',
  ]);
}