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