function CommentFieldsTest::testCommentDefaultFields in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/comment/src/Tests/CommentFieldsTest.php \Drupal\comment\Tests\CommentFieldsTest::testCommentDefaultFields()
Tests that the default 'comment_body' field is correctly added.
File
- core/
modules/ comment/ src/ Tests/ CommentFieldsTest.php, line 32 - Contains \Drupal\comment\Tests\CommentFieldsTest.
Class
- CommentFieldsTest
- Tests fields on comments.
Namespace
Drupal\comment\TestsCode
function testCommentDefaultFields() {
// Do not make assumptions on default node types created by the test
// installation profile, and create our own.
$this
->drupalCreateContentType(array(
'type' => 'test_node_type',
));
$this
->addDefaultCommentField('node', 'test_node_type');
// Check that the 'comment_body' field is present on the comment bundle.
$field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$this
->assertTrue(!empty($field), 'The comment_body field is added when a comment bundle is created');
$field
->delete();
// Check that the 'comment_body' field is not deleted since it is persisted
// even if it has no fields.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this
->assertTrue($field_storage, 'The comment_body field storage was not deleted');
// Create a new content type.
$type_name = 'test_node_type_2';
$this
->drupalCreateContentType(array(
'type' => $type_name,
));
$this
->addDefaultCommentField('node', $type_name);
// Check that the 'comment_body' field exists and has an instance on the
// new comment bundle.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this
->assertTrue($field_storage, 'The comment_body field exists');
$field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$this
->assertTrue(isset($field), format_string('The comment_body field is present for comments on type @type', array(
'@type' => $type_name,
)));
// Test adding a field that defaults to CommentItemInterface::CLOSED.
$this
->addDefaultCommentField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies');
$field = FieldConfig::load('node.test_node_type.who_likes_ponies');
$this
->assertEqual($field
->getDefaultValueLiteral()[0]['status'], CommentItemInterface::CLOSED);
}