class NodeDisplayConfigurableTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Functional/NodeDisplayConfigurableTest.php \Drupal\Tests\node\Functional\NodeDisplayConfigurableTest
- 9 core/modules/rdf/tests/src/Functional/Node/NodeDisplayConfigurableTest.php \Drupal\Tests\rdf\Functional\Node\NodeDisplayConfigurableTest
Tests making node base fields' displays configurable.
@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\PhpunitCompatibilityTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\node\Functional\NodeTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\node\Functional\NodeDisplayConfigurableTest extends \Drupal\Tests\node\Functional\NodeTestBase
- class \Drupal\Tests\node\Functional\NodeTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NodeDisplayConfigurableTest
File
-
core/
modules/ node/ tests/ src/ Functional/ NodeDisplayConfigurableTest.php, line 12
Namespace
Drupal\Tests\node\FunctionalView source
class NodeDisplayConfigurableTest extends NodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'quickedit',
'rdf',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'classy';
/**
* Sets base fields to configurable display and check settings are respected.
*/
public function testDisplayConfigurable() {
// 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->drupalLogin($user);
$node = $this->drupalCreateNode([
'uid' => $user->id(),
]);
$assert = $this->assertSession();
// Check the node with Drupal default non-configurable display.
$this->drupalGet($node->toUrl());
$assert->elementTextContains('css', 'span.field--name-created', \Drupal::service('date.formatter')->format($node->getCreatedTime()));
$assert->elementTextContains('css', 'span.field--name-uid[data-quickedit-field-id="node/1/uid/en/full"]', $user->getAccountName());
$assert->elementTextContains('css', 'div.node__submitted', 'Submitted by');
$assert->elementTextContains('css', 'span.field--name-title', $node->getTitle());
// 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());
$assert->elementTextContains('css', 'span.field--name-created', \Drupal::service('date.formatter')->format($node->getCreatedTime()));
$assert->elementTextContains('css', 'span.field--name-uid[data-quickedit-field-id="node/1/uid/en/full"]', $user->getAccountName());
$assert->elementNotExists('css', 'span.field--name-uid a');
$assert->elementTextContains('css', 'span.field--name-title', $node->getTitle());
$assert->elementExists('css', 'span[property="schema:dateCreated"]');
// Remove from display.
$display->removeComponent('uid')
->removeComponent('created')
->save();
$this->drupalGet($node->toUrl());
$assert->elementNotExists('css', '.field--name-created');
$assert->elementNotExists('css', '.field--name-uid');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.