function CommentFieldsTest::testCommentFieldCreate
Same name in other branches
- 8.9.x core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentFieldCreate()
- 10 core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentFieldCreate()
- 11.x core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentFieldCreate()
Tests creating a comment field through the interface.
File
-
core/
modules/ comment/ tests/ src/ Functional/ CommentFieldsTest.php, line 147
Class
- CommentFieldsTest
- Tests fields on comments.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testCommentFieldCreate() {
// Create user who can administer user fields.
$user = $this->drupalCreateUser([
'administer user fields',
]);
$this->drupalLogin($user);
// Create comment field in account settings.
$edit = [
'new_storage_type' => 'comment',
'label' => 'User comment',
'field_name' => 'user_comment',
];
$this->drupalGet('admin/config/people/accounts/fields/add-field');
$this->submitForm($edit, 'Save and continue');
// Try to save the comment field without selecting a comment type.
$edit = [];
$this->drupalGet('admin/config/people/accounts/fields/user.user.field_user_comment/storage');
$this->submitForm($edit, 'Save field settings');
// We should get an error message.
$this->assertSession()
->pageTextContains('An illegal choice has been detected. Please contact the site administrator.');
// Create a comment type for users.
$bundle = CommentType::create([
'id' => 'user_comment_type',
'label' => 'user_comment_type',
'description' => '',
'target_entity_type_id' => 'user',
]);
$bundle->save();
// Select a comment type and try to save again.
$edit = [
'settings[comment_type]' => 'user_comment_type',
];
$this->drupalGet('admin/config/people/accounts/fields/user.user.field_user_comment/storage');
$this->submitForm($edit, 'Save field settings');
// We shouldn't get an error message.
$this->assertSession()
->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.