class NodeFieldTokensTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Functional/Views/NodeFieldTokensTest.php \Drupal\Tests\node\Functional\Views\NodeFieldTokensTest
Tests replacement of Views tokens supplied by the Node module.
@group node
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\node\Functional\Views\NodeTestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\node\Functional\Views\NodeFieldTokensTest implements \Drupal\Tests\node\Functional\Views\NodeTestBase
- class \Drupal\Tests\node\Functional\Views\NodeTestBase implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NodeFieldTokensTest
See also
\Drupal\node\Tests\NodeTokenReplaceTest
File
-
core/
modules/ node/ tests/ src/ Functional/ Views/ NodeFieldTokensTest.php, line 14
Namespace
Drupal\Tests\node\Functional\ViewsView source
class NodeFieldTokensTest extends NodeTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_node_tokens',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests token replacement for Views tokens supplied by the Node module.
*/
public function testViewsTokenReplacement() {
// Create the Article content type with a standard body field.
/** @var \Drupal\node\NodeTypeInterface $node_type */
$node_type = NodeType::create([
'type' => 'article',
'name' => 'Article',
]);
$node_type->save();
node_add_body_field($node_type);
// Create a user and a node.
$account = $this->createUser();
$body = $this->randomMachineName(32);
$summary = $this->randomMachineName(16);
/** @var \Drupal\node\NodeInterface $node */
$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');
// Body: {{ body }}<br />
$this->assertSession()
->responseContains("Body: <p>{$body}</p>");
// Raw value: {{ body__value }}<br />
$this->assertSession()
->responseContains("Raw value: {$body}");
// Raw summary: {{ body__summary }}<br />
$this->assertSession()
->responseContains("Raw summary: {$summary}");
// Raw format: {{ body__format }}<br />
$this->assertSession()
->responseContains("Raw format: plain_text");
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.