3 namespace Drupal\Tests\system\Functional\System;
5 use Drupal\Tests\BrowserTestBase;
8 * Scan token-like patterns in a dummy text to check token scanning.
12 class TokenScanTest extends BrowserTestBase {
15 * Scans dummy text, then tests the output.
17 public function testTokenScan() {
18 // Define text with valid and not valid, fake and existing token-like
20 $text = 'First a [valid:simple], but dummy token, and a dummy [valid:token with: spaces].';
21 $text .= 'Then a [not valid:token].';
22 $text .= 'Then an [:empty token type].';
23 $text .= 'Then an [empty token:].';
24 $text .= 'Then a totally empty token: [:].';
25 $text .= 'Last an existing token: [node:author:name].';
26 $token_wannabes = \Drupal::token()->scan($text);
28 $this->assertTrue(isset($token_wannabes['valid']['simple']), 'A simple valid token has been matched.');
29 $this->assertTrue(isset($token_wannabes['valid']['token with: spaces']), 'A valid token with space characters in the token name has been matched.');
30 $this->assertFalse(isset($token_wannabes['not valid']), 'An invalid token with spaces in the token type has not been matched.');
31 $this->assertFalse(isset($token_wannabes['empty token']), 'An empty token has not been matched.');
32 $this->assertFalse(isset($token_wannabes['']['empty token type']), 'An empty token type has not been matched.');
33 $this->assertFalse(isset($token_wannabes['']['']), 'An empty token and type has not been matched.');
34 $this->assertTrue(isset($token_wannabes['node']), 'An existing valid token has been matched.');