Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / system / tests / src / Functional / System / TokenScanTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\System;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Scan token-like patterns in a dummy text to check token scanning.
9  *
10  * @group system
11  */
12 class TokenScanTest extends BrowserTestBase {
13
14   /**
15    * Scans dummy text, then tests the output.
16    */
17   public function testTokenScan() {
18     // Define text with valid and not valid, fake and existing token-like
19     // strings.
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);
27
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.');
35   }
36
37 }