Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / node / tests / src / Functional / Views / NodeFieldTokensTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional\Views;
4
5 use Drupal\node\Entity\Node;
6 use Drupal\node\Entity\NodeType;
7
8 /**
9  * Tests replacement of Views tokens supplied by the Node module.
10  *
11  * @group node
12  * @see \Drupal\node\Tests\NodeTokenReplaceTest
13  */
14 class NodeFieldTokensTest extends NodeTestBase {
15
16   /**
17    * Views used by this test.
18    *
19    * @var array
20    */
21   public static $testViews = ['test_node_tokens'];
22
23   /**
24    * Tests token replacement for Views tokens supplied by the Node module.
25    */
26   public function testViewsTokenReplacement() {
27     // Create the Article content type with a standard body field.
28     /* @var $node_type \Drupal\node\NodeTypeInterface */
29     $node_type = NodeType::create(['type' => 'article', 'name' => 'Article']);
30     $node_type->save();
31     node_add_body_field($node_type);
32
33     // Create a user and a node.
34     $account = $this->createUser();
35     $body = $this->randomMachineName(32);
36     $summary = $this->randomMachineName(16);
37
38     /** @var $node \Drupal\node\NodeInterface */
39     $node = Node::create([
40       'type' => 'article',
41       'tnid' => 0,
42       'uid' => $account->id(),
43       'title' => 'Testing Views tokens',
44       'body' => [['value' => $body, 'summary' => $summary, 'format' => 'plain_text']],
45     ]);
46     $node->save();
47
48     $this->drupalGet('test_node_tokens');
49
50     // Body: {{ body }}<br />
51     $this->assertRaw("Body: <p>$body</p>");
52
53     // Raw value: {{ body__value }}<br />
54     $this->assertRaw("Raw value: $body");
55
56     // Raw summary: {{ body__summary }}<br />
57     $this->assertRaw("Raw summary: $summary");
58
59     // Raw format: {{ body__format }}<br />
60     $this->assertRaw("Raw format: plain_text");
61   }
62
63 }