public function NodeDisplayConfigurableTest::testDisplayConfigurable in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php \Drupal\Tests\node\Functional\NodeDisplayConfigurableTest::testDisplayConfigurable()
- 9 core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php \Drupal\Tests\node\Functional\NodeDisplayConfigurableTest::testDisplayConfigurable()
Sets base fields to configurable display and check settings are respected.
@dataProvider provideThemes
Parameters
string $theme: The name of the theme being tested.
string $metadata_region: The region of the node html content where meta data is expected.
bool $field_classes: If TRUE, check for field--name-XXX classes.
File
- core/
modules/ node/ tests/ src/ Functional/ NodeDisplayConfigurableTest.php, line 57
Class
- NodeDisplayConfigurableTest
- Tests making node base fields' displays configurable.
Namespace
Drupal\Tests\node\FunctionalCode
public function testDisplayConfigurable(string $theme, string $metadata_region, bool $field_classes) {
// Change the node type setting to show submitted by information.
$node_type = \Drupal::entityTypeManager()
->getStorage('node_type')
->load('page');
$node_type
->setDisplaySubmitted(TRUE);
$node_type
->save();
$user = $this
->drupalCreateUser([
'administer nodes',
], $this
->randomMachineName(14));
$this
->drupalLogin($user);
$node = $this
->drupalCreateNode([
'uid' => $user
->id(),
]);
$assert = $this
->assertSession();
// Check the node with Drupal default non-configurable display.
$this
->drupalGet($node
->toUrl());
$this
->assertNodeHtml($node, $user, TRUE, $metadata_region, $field_classes, $field_classes);
// Enable module to make base fields' displays configurable.
\Drupal::service('module_installer')
->install([
'node_display_configurable_test',
]);
// Configure display.
$display = EntityViewDisplay::load('node.page.default');
$display
->setComponent('uid', [
'type' => 'entity_reference_label',
'label' => 'above',
'settings' => [
'link' => FALSE,
],
])
->removeComponent('title')
->save();
// Recheck the node with configurable display.
$this
->drupalGet($node
->toUrl());
$this
->assertNodeHtml($node, $user, FALSE, $metadata_region, $field_classes, FALSE);
// Remove from display.
$display
->removeComponent('uid')
->removeComponent('created')
->save();
$this
->drupalGet($node
->toUrl());
$assert
->elementTextNotContains('css', 'article', $user
->getAccountName());
}