public function CommentFieldsTest::testCommentFieldCreate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/comment/src/Tests/CommentFieldsTest.php \Drupal\comment\Tests\CommentFieldsTest::testCommentFieldCreate()
Tests creating a comment field through the interface.
File
- core/
modules/ comment/ src/ Tests/ CommentFieldsTest.php, line 149 - Contains \Drupal\comment\Tests\CommentFieldsTest.
Class
- CommentFieldsTest
- Tests fields on comments.
Namespace
Drupal\comment\TestsCode
public function testCommentFieldCreate() {
// Create user who can administer user fields.
$user = $this
->drupalCreateUser(array(
'administer user fields',
));
$this
->drupalLogin($user);
// Create comment field in account settings.
$edit = array(
'new_storage_type' => 'comment',
'label' => 'User comment',
'field_name' => 'user_comment',
);
$this
->drupalPostForm('admin/config/people/accounts/fields/add-field', $edit, 'Save and continue');
// Try to save the comment field without selecting a comment type.
$edit = array();
$this
->drupalPostForm('admin/config/people/accounts/fields/user.user.field_user_comment/storage', $edit, t('Save field settings'));
// We should get an error message.
$this
->assertText(t('An illegal choice has been detected. Please contact the site administrator.'));
// Create a comment type for users.
$bundle = CommentType::create(array(
'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 = array(
'settings[comment_type]' => 'user_comment_type',
);
$this
->drupalPostForm('admin/config/people/accounts/fields/user.user.field_user_comment/storage', $edit, t('Save field settings'));
// We shouldn't get an error message.
$this
->assertNoText(t('An illegal choice has been detected. Please contact the site administrator.'));
}