public function TokenBlockTest::testBlockTitleTokens in Token 8
File
- tests/src/Functional/TokenBlockTest.php, line 31
Class
- TokenBlockTest
- Tests block tokens.
Namespace
Drupal\Tests\token\Functional
Code
public function testBlockTitleTokens() {
$label = 'tokenblock';
$bundle = BlockContentType::create([
'id' => $label,
'label' => $label,
'revision' => FALSE,
]);
$bundle
->save();
$block_content = BlockContent::create([
'type' => $label,
'label' => '[current-page:title] block title',
'info' => 'Test token title block',
'body[value]' => 'This is the test token title block.',
]);
$block_content
->save();
$block = $this
->drupalPlaceBlock('block_content:' . $block_content
->uuid(), [
'label' => '[user:name]',
]);
$this
->drupalGet($block
->toUrl());
$this
->assertSession()
->linkExists('Browse available tokens.');
$this
->assertText('This field supports tokens. Browse available tokens.');
$this
->drupalPostForm(NULL, [], 'Save block');
$this
->assertText('Title is using the following invalid tokens: [user:name].');
$settings = $block
->get('settings');
$settings['label'] = '[current-page:title] block title';
$block
->set('settings', $settings);
$block
->save();
$this
->drupalCreateContentType([
'type' => 'page',
]);
$node = $this
->drupalCreateNode([
'title' => "Site's first node",
]);
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->responseContains("Site's first node block title");
}