NodeFieldTokensTest.php in Drupal 10
File
core/modules/node/tests/src/Functional/Views/NodeFieldTokensTest.php
View source
<?php
namespace Drupal\Tests\node\Functional\Views;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
class NodeFieldTokensTest extends NodeTestBase {
public static $testViews = [
'test_node_tokens',
];
protected $defaultTheme = 'stark';
public function testViewsTokenReplacement() {
$node_type = NodeType::create([
'type' => 'article',
'name' => 'Article',
]);
$node_type
->save();
node_add_body_field($node_type);
$account = $this
->createUser();
$body = $this
->randomMachineName(32);
$summary = $this
->randomMachineName(16);
$node = Node::create([
'type' => 'article',
'tnid' => 0,
'uid' => $account
->id(),
'title' => 'Testing Views tokens',
'body' => [
[
'value' => $body,
'summary' => $summary,
'format' => 'plain_text',
],
],
]);
$node
->save();
$this
->drupalGet('test_node_tokens');
$this
->assertSession()
->responseContains("Body: <p>{$body}</p>");
$this
->assertSession()
->responseContains("Raw value: {$body}");
$this
->assertSession()
->responseContains("Raw summary: {$summary}");
$this
->assertSession()
->responseContains("Raw format: plain_text");
}
}