class CommentDisplayConfigurableTest
Same name and namespace in other branches
- 11.x core/modules/comment/tests/src/Functional/CommentDisplayConfigurableTest.php \Drupal\Tests\comment\Functional\CommentDisplayConfigurableTest
- 10 core/modules/comment/tests/src/Functional/CommentDisplayConfigurableTest.php \Drupal\Tests\comment\Functional\CommentDisplayConfigurableTest
Tests making comment base fields' displays configurable.
@group comment
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\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\comment\Functional\CommentTestBase uses \Drupal\comment\Tests\CommentTestTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\comment\Functional\CommentDisplayConfigurableTest extends \Drupal\Tests\comment\Functional\CommentTestBase
- class \Drupal\Tests\comment\Functional\CommentTestBase uses \Drupal\comment\Tests\CommentTestTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of CommentDisplayConfigurableTest
File
-
core/
modules/ comment/ tests/ src/ Functional/ CommentDisplayConfigurableTest.php, line 16
Namespace
Drupal\Tests\comment\FunctionalView source
class CommentDisplayConfigurableTest extends CommentTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'olivero';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Allow anonymous users to see comments.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
'access comments',
'access content',
]);
}
/**
* Sets base fields to configurable display and check settings are respected.
*/
public function testDisplayConfigurable() {
// Add a comment.
$nid = $this->node
->id();
/** @var \Drupal\comment\CommentInterface $comment */
$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();
// Check the comment author with Drupal default non-configurable display.
$this->drupalGet('node/' . $nid);
$assert->elementExists('css', 'p.comment__author span');
// Enable module to make base fields' displays configurable.
\Drupal::service('module_installer')->install([
'comment_display_configurable_test',
]);
// Configure display.
$display = EntityViewDisplay::load('comment.comment.default');
$display->setComponent('uid', [
'type' => 'entity_reference_label',
'label' => 'above',
'settings' => [
'link' => FALSE,
],
])
->save();
// Recheck the comment author with configurable display.
$this->drupalGet('node/' . $nid);
$assert->elementExists('css', '.field--name-uid .field__item');
// Remove from display.
$display->removeComponent('uid')
->removeComponent('created')
->save();
$this->drupalGet('node/' . $this->node
->id());
$assert->elementNotExists('css', '.field--name-uid .field__item');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.