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