You are here

public function TreeTest::testUserTokens in Token 8

Tests if the token browser displays the user tokens.

File

tests/src/Functional/Tree/TreeTest.php, line 84

Class

TreeTest
Tests token tree page.

Namespace

Drupal\Tests\token\Functional\Tree

Code

public function testUserTokens() {
  $this
    ->drupalGet($this
    ->getTokenTreeUrl([
    'token_types' => [
      'user',
    ],
  ]));
  $this
    ->assertTokenGroup('Users');
  $this
    ->assertTokenInTree('[user:account-name]', 'user');
  $this
    ->assertTokenInTree('[user:original:account-name]', 'user--original');

  // Assert some of the restricted tokens to ensure they are not shown.
  $this
    ->assertTokenNotInTree('[user:one-time-login-url]', 'user');
  $this
    ->assertTokenNotInTree('[user:original:cancel-url]', 'user--original');

  // Request with show_restricted set to TRUE to show restricted tokens and
  // check for them.
  $this
    ->drupalGet($this
    ->getTokenTreeUrl([
    'token_types' => [
      'user',
    ],
    'show_restricted' => TRUE,
  ]));
  $this
    ->assertEquals('MISS', $this
    ->drupalGetHeader('x-drupal-dynamic-cache'), 'Cache was not hit');
  $this
    ->assertTokenInTree('[user:one-time-login-url]', 'user');
  $this
    ->assertTokenInTree('[user:original:cancel-url]', 'user--original');
}