55de3b98814d0b0da1bd3875a82cd465f66a9ca2
[yaffs-website] / web / modules / contrib / token / src / Tests / TokenBlockTest.php
1 <?php
2
3 namespace Drupal\token\Tests;
4
5 use Drupal\block_content\Entity\BlockContent;
6 use Drupal\block_content\Entity\BlockContentType;
7
8 /**
9  * Tests block tokens.
10  *
11  * @group token
12  */
13 class TokenBlockTest extends TokenTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['block', 'node', 'views', 'block_content'];
21
22   /**
23    * {@inheritdoc}
24    */
25   public function setUp($modules = []) {
26     parent::setUp();
27     $this->admin_user = $this->drupalCreateUser(['access content', 'administer blocks']);
28     $this->drupalLogin($this->admin_user);
29   }
30
31   public function testBlockTitleTokens() {
32     $label = 'tokenblock';
33     $bundle = BlockContentType::create([
34       'id' => $label,
35       'label' => $label,
36       'revision' => FALSE
37     ]);
38     $bundle->save();
39
40     $block_content = BlockContent::create([
41       'type' => $label,
42       'label' => '[current-page:title] block title',
43       'info' => 'Test token title block',
44       'body[value]' => 'This is the test token title block.',
45     ]);
46     $block_content->save();
47
48     $block = $this->drupalPlaceBlock('block_content:' . $block_content->uuid(), [
49       'label' => '[user:name]',
50     ]);
51     $this->drupalGet($block->toUrl());
52     // Ensure that the link to available tokens is present and correctly
53     // positioned.
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].');
59
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);
64     $block->save();
65
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&#039;s first node block title");
72   }
73 }