3 namespace Drupal\Tests\node\Functional\Views;
5 use Drupal\node\Entity\Node;
6 use Drupal\node\Entity\NodeType;
9 * Tests replacement of Views tokens supplied by the Node module.
12 * @see \Drupal\node\Tests\NodeTokenReplaceTest
14 class NodeFieldTokensTest extends NodeTestBase {
17 * Views used by this test.
21 public static $testViews = ['test_node_tokens'];
24 * Tests token replacement for Views tokens supplied by the Node module.
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']);
31 node_add_body_field($node_type);
33 // Create a user and a node.
34 $account = $this->createUser();
35 $body = $this->randomMachineName(32);
36 $summary = $this->randomMachineName(16);
38 /** @var $node \Drupal\node\NodeInterface */
39 $node = Node::create([
42 'uid' => $account->id(),
43 'title' => 'Testing Views tokens',
44 'body' => [['value' => $body, 'summary' => $summary, 'format' => 'plain_text']],
48 $this->drupalGet('test_node_tokens');
50 // Body: {{ body }}<br />
51 $this->assertRaw("Body: <p>$body</p>");
53 // Raw value: {{ body__value }}<br />
54 $this->assertRaw("Raw value: $body");
56 // Raw summary: {{ body__summary }}<br />
57 $this->assertRaw("Raw summary: $summary");
59 // Raw format: {{ body__format }}<br />
60 $this->assertRaw("Raw format: plain_text");