3 namespace Drupal\token\Tests;
5 use Drupal\block_content\Entity\BlockContent;
6 use Drupal\block_content\Entity\BlockContentType;
13 class TokenBlockTest extends TokenTestBase {
20 public static $modules = ['block', 'node', 'views', 'block_content'];
25 public function setUp($modules = []) {
27 $this->admin_user = $this->drupalCreateUser(['access content', 'administer blocks']);
28 $this->drupalLogin($this->admin_user);
31 public function testBlockTitleTokens() {
32 $label = 'tokenblock';
33 $bundle = BlockContentType::create([
40 $block_content = BlockContent::create([
42 'label' => '[current-page:title] block title',
43 'info' => 'Test token title block',
44 'body[value]' => 'This is the test token title block.',
46 $block_content->save();
48 $block = $this->drupalPlaceBlock('block_content:' . $block_content->uuid(), [
49 'label' => '[user:name]',
51 $this->drupalGet($block->toUrl());
52 // Ensure that the link to available tokens is present and correctly
54 $this->assertLink('Browse available tokens.');
55 $this->assertText('This field supports tokens. Browse available tokens.');
56 $this->drupalPostForm(NULL, [], t('Save block'));
57 // Ensure token validation is working on the block.
58 $this->assertText('Title is using the following invalid tokens: [user:name].');
60 // Create the block for real now with a valid title.
61 $settings = $block->get('settings');
62 $settings['label'] = '[current-page:title] block title';
63 $block->set('settings', $settings);
66 // Ensure that tokens are not double-escaped when output as a block title.
67 $this->drupalCreateContentType(['type' => 'page']);
68 $node = $this->drupalCreateNode(['title' => "Site's first node"]);
69 $this->drupalGet('node/' . $node->id());
70 // The apostraphe should only be escaped once.
71 $this->assertRaw("Site's first node block title");