class TokenScanTest
Same name and namespace in other branches
- 7.x modules/system/system.test \TokenScanTest
- 8.9.x core/modules/system/tests/src/Functional/System/TokenScanTest.php \Drupal\Tests\system\Functional\System\TokenScanTest
Scan token-like patterns in a dummy text to check token scanning.
@group system
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\System\TokenScanTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of TokenScanTest
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ TokenScanTest.php, line 12
Namespace
Drupal\Tests\system\Functional\SystemView source
class TokenScanTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Scans dummy text, then tests the output.
*/
public function testTokenScan() {
// Define text with valid and not valid, fake and existing token-like
// strings.
$text = 'First a [valid:simple], but dummy token, and a dummy [valid:token with: spaces].';
$text .= 'Then a [not valid:token].';
$text .= 'Then an [:empty token type].';
$text .= 'Then an [empty token:].';
$text .= 'Then a totally empty token: [:].';
$text .= 'Last an existing token: [node:author:name].';
$token_wannabes = \Drupal::token()->scan($text);
$this->assertTrue(isset($token_wannabes['valid']['simple']), 'A simple valid token has been matched.');
$this->assertTrue(isset($token_wannabes['valid']['token with: spaces']), 'A valid token with space characters in the token name has been matched.');
$this->assertFalse(isset($token_wannabes['not valid']), 'An invalid token with spaces in the token type has not been matched.');
$this->assertFalse(isset($token_wannabes['empty token']), 'An empty token has not been matched.');
$this->assertFalse(isset($token_wannabes['']['empty token type']), 'An empty token type has not been matched.');
$this->assertFalse(isset($token_wannabes['']['']), 'An empty token and type has not been matched.');
$this->assertTrue(isset($token_wannabes['node']), 'An existing valid token has been matched.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.