View source
<?php
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
class NodeDisplayConfigurableTest extends NodeTestBase {
public static $modules = [
'quickedit',
'rdf',
];
protected $defaultTheme = 'classy';
public function testDisplayConfigurable() {
$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();
$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());
\Drupal::service('module_installer')
->install([
'node_display_configurable_test',
]);
$display = EntityViewDisplay::load('node.page.default');
$display
->setComponent('uid', [
'type' => 'entity_reference_label',
'label' => 'above',
'settings' => [
'link' => FALSE,
],
])
->save();
$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"]');
$display
->removeComponent('uid')
->removeComponent('created')
->save();
$this
->drupalGet($node
->toUrl());
$assert
->elementNotExists('css', '.field--name-created');
$assert
->elementNotExists('css', '.field--name-uid');
}
}