class TextSummaryNodeFieldsTokenTest
Same name in this branch
- 11.x core/modules/text/tests/src/Functional/TextSummaryNodeFieldsTokenTest.php \Drupal\Tests\text\Functional\TextSummaryNodeFieldsTokenTest
Same name and namespace in other branches
- main core/modules/text/tests/src/Functional/TextSummaryNodeFieldsTokenTest.php \Drupal\Tests\text\Functional\TextSummaryNodeFieldsTokenTest
Tests replacement of Views tokens supplied by the Node module.
Attributes
#[Group('text_with_summary')]
#[IgnoreDeprecations]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\node\Functional\Views\NodeTestBase extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\text_with_summary\Functional\TextSummaryNodeFieldsTokenTest extends \Drupal\Tests\node\Functional\Views\NodeTestBase
- class \Drupal\Tests\node\Functional\Views\NodeTestBase extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of TextSummaryNodeFieldsTokenTest
See also
\Drupal\node\Tests\NodeTokenReplaceTest
File
-
core/
modules/ text_with_summary/ tests/ src/ Functional/ TextSummaryNodeFieldsTokenTest.php, line 20
Namespace
Drupal\Tests\text_with_summary\FunctionalView source
class TextSummaryNodeFieldsTokenTest extends NodeTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_node_tokens',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'text_with_summary',
];
/**
* Tests token replacement for Views tokens supplied by the Node module.
*/
public function testViewsTokenReplacement() : void {
// Create the Article content type with a standard body field.
$this->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
], FALSE);
FieldStorageConfig::loadByName('node', 'body')->delete();
FieldStorageConfig::create([
'field_name' => 'body',
'type' => 'text_with_summary',
'entity_type' => 'node',
'cardinality' => 1,
])->save();
$fieldStorage = FieldStorageConfig::loadByName('node', 'body');
FieldConfig::create([
'field_storage' => $fieldStorage,
'bundle' => 'article',
'label' => 'Body Test',
'settings' => [
'display_summary' => TRUE,
'allowed_formats' => [],
],
])->save();
// 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',
'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.