public function CommentItemTest::testCommentItem in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/comment/src/Tests/CommentItemTest.php \Drupal\comment\Tests\CommentItemTest::testCommentItem()
Tests using entity fields of the comment field type.
File
- core/
modules/ comment/ src/ Tests/ CommentItemTest.php, line 39 - Contains \Drupal\comment\Tests\CommentItemTest.
Class
- CommentItemTest
- Tests the new entity API for the comment field type.
Namespace
Drupal\comment\TestsCode
public function testCommentItem() {
$this
->addDefaultCommentField('entity_test', 'entity_test', 'comment');
// Verify entity creation.
$entity = entity_create('entity_test');
$entity->name->value = $this
->randomMachineName();
$entity
->save();
// Verify entity has been created properly.
$id = $entity
->id();
$entity = entity_load('entity_test', $id, TRUE);
$this
->assertTrue($entity->comment instanceof FieldItemListInterface, 'Field implements interface.');
$this
->assertTrue($entity->comment[0] instanceof CommentItemInterface, 'Field item implements interface.');
// Test sample item generation.
/** @var \Drupal\entity_test\Entity\EntityTest $entity */
$entity = entity_create('entity_test');
$entity->comment
->generateSampleItems();
$this
->entityValidateAndSave($entity);
$this
->assertTrue(in_array($entity
->get('comment')->status, [
CommentItemInterface::HIDDEN,
CommentItemInterface::CLOSED,
CommentItemInterface::OPEN,
]), 'Comment status value in defined range');
$mainProperty = $entity->comment[0]
->mainPropertyName();
$this
->assertEqual('status', $mainProperty);
}