CommentDisplayConfigurableTest.php in Drupal 10
File
core/modules/comment/tests/src/Functional/CommentDisplayConfigurableTest.php
View source
<?php
namespace Drupal\Tests\comment\Functional;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\user\RoleInterface;
class CommentDisplayConfigurableTest extends CommentTestBase {
protected $defaultTheme = 'olivero';
protected function setUp() : void {
parent::setUp();
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
'access comments',
'access content',
]);
}
public function testDisplayConfigurable() {
$nid = $this->node
->id();
$comment = Comment::create([
'entity_id' => $nid,
'entity_type' => 'node',
'field_name' => 'comment',
'uid' => $this->webUser
->id(),
'status' => CommentInterface::PUBLISHED,
'subject' => $this
->randomMachineName(),
'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'comment_body' => [
LanguageInterface::LANGCODE_NOT_SPECIFIED => [
$this
->randomMachineName(),
],
],
]);
$comment
->save();
$assert = $this
->assertSession();
$this
->drupalGet('node/' . $nid);
$assert
->elementExists('css', 'p.comment__author span');
\Drupal::service('module_installer')
->install([
'comment_display_configurable_test',
]);
$display = EntityViewDisplay::load('comment.comment.default');
$display
->setComponent('uid', [
'type' => 'entity_reference_label',
'label' => 'above',
'settings' => [
'link' => FALSE,
],
])
->save();
$this
->drupalGet('node/' . $nid);
$assert
->elementExists('css', '.field--name-uid .field__item');
$display
->removeComponent('uid')
->removeComponent('created')
->save();
$this
->drupalGet('node/' . $this->node
->id());
$assert
->elementNotExists('css', '.field--name-uid .field__item');
}
}