CommentLegacyTest.php in Drupal 8
File
core/modules/comment/tests/src/Kernel/CommentLegacyTest.php
View source
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
class CommentLegacyTest extends EntityKernelTestBase {
public static $modules = [
'comment',
];
protected $entity;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('comment');
$this
->installSchema('comment', [
'comment_entity_statistics',
]);
CommentType::create([
'id' => 'comment',
'label' => $this
->randomString(),
'target_entity_type_id' => 'entity_test',
])
->save();
FieldStorageConfig::create([
'entity_type' => 'entity_test',
'type' => 'comment',
'field_name' => 'comments',
'settings' => [
'comment_type' => 'comment',
],
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'field_name' => 'comments',
])
->save();
$this->entity = EntityTest::create([
'name' => $this
->randomString(),
]);
$this->entity
->save();
}
protected function createComment() {
return Comment::create([
'entity_type' => 'entity_test',
'field_name' => 'comments',
'entity_id' => $this->entity
->id(),
'comment_type' => 'comment',
]);
}
public function testCommentView() {
$entity = $this
->createComment();
$this
->assertNotEmpty(comment_view($entity));
$entities = [
$this
->createComment(),
$this
->createComment(),
];
$this
->assertCount(4, comment_view_multiple($entities));
}
public function testGetStatus() {
$entity = $this
->createComment();
$entity
->setPublished();
$this
->assertEquals(CommentInterface::PUBLISHED, $entity
->getStatus());
$entity
->setUnPublished();
$this
->assertEquals(CommentInterface::NOT_PUBLISHED, $entity
->getStatus());
}
}