function CommentTypeTest::testCommentTypeCreation
Same name in other branches
- 9 core/modules/comment/tests/src/Functional/CommentTypeTest.php \Drupal\Tests\comment\Functional\CommentTypeTest::testCommentTypeCreation()
- 10 core/modules/comment/tests/src/Functional/CommentTypeTest.php \Drupal\Tests\comment\Functional\CommentTypeTest::testCommentTypeCreation()
- 11.x core/modules/comment/tests/src/Functional/CommentTypeTest.php \Drupal\Tests\comment\Functional\CommentTypeTest::testCommentTypeCreation()
Tests creating a comment type programmatically and via a form.
File
-
core/
modules/ comment/ tests/ src/ Functional/ CommentTypeTest.php, line 57
Class
- CommentTypeTest
- Ensures that comment type functions work correctly.
Namespace
Drupal\Tests\comment\FunctionalCode
public function testCommentTypeCreation() {
// Create a comment type programmatically.
$type = $this->createCommentType('other');
$comment_type = CommentType::load('other');
$this->assertInstanceOf(CommentType::class, $comment_type);
// Log in a test user.
$this->drupalLogin($this->adminUser);
// Ensure that the new comment type admin page can be accessed.
$this->drupalGet('admin/structure/comment/manage/' . $type->id());
$this->assertSession()
->statusCodeEquals(200);
// Create a comment type via the user interface.
$edit = [
'id' => 'foo',
'label' => 'title for foo',
'description' => '',
'target_entity_type_id' => 'node',
];
$this->drupalPostForm('admin/structure/comment/types/add', $edit, t('Save'));
$comment_type = CommentType::load('foo');
$this->assertInstanceOf(CommentType::class, $comment_type);
// Check that the comment type was created in site default language.
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()
->getId();
$this->assertEqual($comment_type->language()
->getId(), $default_langcode);
// Edit the comment-type and ensure that we cannot change the entity-type.
$this->drupalGet('admin/structure/comment/manage/foo');
$this->assertNoField('target_entity_type_id', 'Entity type file not present');
$this->assertText(t('Target entity type'));
// Save the form and ensure the entity-type value is preserved even though
// the field isn't present.
$this->drupalPostForm(NULL, [], t('Save'));
\Drupal::entityTypeManager()->getStorage('comment_type')
->resetCache([
'foo',
]);
$comment_type = CommentType::load('foo');
$this->assertEqual($comment_type->getTargetEntityTypeId(), 'node');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.