TokenReplaceWebTest.php 1.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<?php

/**
 * @file
 * Contains \Drupal\system\Tests\System\TokenReplaceWebTest.
 */

namespace Drupal\system\Tests\System;

use Drupal\simpletest\WebTestBase;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;

/**
 * Tests the token system integration.
 *
 * @group system
 */
class TokenReplaceWebTest extends WebTestBase {

  use AssertPageCacheContextsAndTagsTrait;

  /**
   * {@inheritdoc}
   */
  public static $modules = ['token_test', 'filter', 'node'];

  /**
   * Tests a token replacement on an actual website.
   */
  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', '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', 'user']);
  }

}