You are here

public function NodeDisplayConfigurableTest::testDisplayConfigurable in Drupal 9

Same name and namespace in other branches
  1. 8 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\Functional

Code

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([
    'access in-place editing',
    '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, 'span', $metadata_region, $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,
    ],
  ])
    ->save();

  // Recheck the node with configurable display.
  $this
    ->drupalGet($node
    ->toUrl());
  $this
    ->assertNodeHtml($node, $user, 'div', $metadata_region, $field_classes);

  // Remove from display.
  $display
    ->removeComponent('uid')
    ->removeComponent('created')
    ->save();
  $this
    ->drupalGet($node
    ->toUrl());
  $assert
    ->elementNotExists('css', 'div[data-quickedit-field-id="node/1/uid/en/full"]');
  $assert
    ->elementTextNotContains('css', 'article[data-quickedit-entity-id="node/1"]', $user
    ->getAccountName());
}