function CommentFieldsTest::testCommentFieldCreate
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/CommentFieldsTest.php \Drupal\Tests\comment\Functional\CommentFieldsTest::testCommentFieldCreate()
- 8.9.x 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 146
Class
- CommentFieldsTest
- Tests fields on comments.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testCommentFieldCreate() : void {
// 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',
];
$this->drupalGet('admin/config/people/accounts/fields/add-field');
$this->submitForm($edit, 'Continue');
$edit = [
'label' => 'User comment',
'field_name' => 'user_comment',
];
$this->submitForm($edit, 'Continue');
// Try to save the comment field without selecting a comment type.
$edit = [];
$this->submitForm($edit, 'Update settings');
// We should get an error message.
$this->assertSession()
->pageTextContains('The submitted value in the Comment type element is not allowed.');
// 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 = [
'field_storage[subform][settings][comment_type]' => 'user_comment_type',
];
$this->drupalGet('admin/config/people/accounts/add-field/user/field_user_comment');
$this->submitForm($edit, 'Update settings');
// We shouldn't get an error message.
$this->assertSession()
->pageTextNotContains('The submitted value in the Comment type element is not allowed.');
// Try to save the comment field with "Comments per page"
// setting value as zero.
$edit = [
'settings[per_page]' => 0,
];
$this->drupalGet('admin/config/people/accounts/add-field/user/field_user_comment');
$this->submitForm($edit, 'Save settings');
$this->assertSession()
->statusMessageContains('Saved User comment configuration.', 'status');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.