Skip to content
Snippets Groups Projects

Resolve #3506444 "Preprocess username caching"

1 unresolved thread
Files
4
@@ -55,6 +55,9 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
$user = $this->drupalCreateUser([
'administer nodes',
], $this->randomMachineName(14));
$profile_viewer_user = $this->drupalCreateUser([
'access user profiles',
], $this->randomMachineName(14));
$this->drupalLogin($user);
$node = $this->drupalCreateNode(['uid' => $user->id()]);
$assert = $this->assertSession();
@@ -62,6 +65,9 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
// Check the node with Drupal default non-configurable display.
$this->drupalGet($node->toUrl());
$this->assertNodeHtml($node, $user, TRUE, $metadata_region, $field_classes, $field_classes);
$this->drupalLogin($profile_viewer_user);
$this->drupalGet($node->toUrl());
$this->assertNodeHtml($node, $user, TRUE, $metadata_region, $field_classes, $field_classes, TRUE);
// Enable module to make base fields' displays configurable.
\Drupal::service('module_installer')->install(['node_display_configurable_test']);
@@ -78,6 +84,7 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
->save();
// Recheck the node with configurable display.
$this->drupalLogin($user);
$this->drupalGet($node->toUrl());
$this->assertNodeHtml($node, $user, FALSE, $metadata_region, $field_classes, FALSE);
@@ -97,7 +104,7 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
* @param \Drupal\node\NodeInterface $node
* The node being tested.
* @param \Drupal\user\UserInterface $user
* The logged in user.
* The author of the node.
* @param bool $is_inline
* Whether the fields are rendered inline or not.
* @param string $metadata_region
@@ -106,10 +113,13 @@ public function testDisplayConfigurable(string $theme, string $metadata_region,
* If TRUE, check for field--name-XXX classes on created/uid fields.
* @param bool $title_classes
* If TRUE, check for field--name-XXX classes on title field.
* @param bool $author_inline_as_link
* If TRUE and fields are inline, the author field should be displayed as
* a link.
*
* @internal
*/
protected function assertNodeHtml(NodeInterface $node, UserInterface $user, bool $is_inline, string $metadata_region, bool $field_classes, bool $title_classes): void {
protected function assertNodeHtml(NodeInterface $node, UserInterface $user, bool $is_inline, string $metadata_region, bool $field_classes, bool $title_classes, bool $author_inline_as_link = FALSE): void {
$assert = $this->assertSession();
$html_element = $is_inline ? 'span' : 'div';
@@ -144,7 +154,14 @@ protected function assertNodeHtml(NodeInterface $node, UserInterface $user, bool
}
}
else {
$assert->elementTextContains('css', $uid_selector . ' a', $user->getAccountName());
if ($author_inline_as_link) {
$assert->elementTextContains('css', $uid_selector . ' a', $user->getAccountName());
}
else {
$assert->elementTextContains('css', $uid_selector, $user->getAccountName());
$assert->elementNotExists('css', $uid_selector . ' a');
}
$assert->elementTextContains('css', 'article ' . $metadata_region, 'Submitted by');
}
}
Loading