View source
<?php
namespace Drupal\Tests\flat_comments\Kernel;
use Drupal\comment\CommentManagerInterface;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\KernelTests\KernelTestBase;
class FlatCommentsPidTest extends KernelTestBase {
use CommentTestTrait;
public static $modules = [
'comment',
'system',
'field',
'text',
'flat_comments',
'entity_test',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('comment');
$this
->installSchema('comment', [
'comment_entity_statistics',
]);
$this
->installConfig([
'comment',
]);
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'sequences',
'key_value',
]);
$this
->installConfig([
'field',
'system',
]);
$storage = \Drupal::entityTypeManager()
->getStorage('user');
$storage
->create([
'uid' => 1,
'name' => 'entity-test',
'mail' => 'entity@localhost',
'status' => TRUE,
])
->save();
}
public function testPidIsNull() {
$this
->addDefaultCommentField('entity_test', 'entity_test', 'comment');
$field = FieldConfig::loadByName('entity_test', 'entity_test', 'comment');
$field
->setSetting('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT);
$field
->save();
$entity = EntityTest::create();
$entity->name->value = $this
->randomMachineName();
$entity
->save();
$comment = Comment::create([
'subject' => 'My comment title',
'uid' => 1,
'name' => 'entity-test',
'mail' => 'entity@localhost',
'entity_type' => 'entity_test',
'field_name' => 'comment',
'entity_id' => $entity
->id(),
'comment_type' => 'entity_test',
'status' => 1,
]);
$comment
->save();
$comment2 = Comment::create([
'subject' => 'Anonymous comment title',
'uid' => 1,
'name' => 'entity-test',
'mail' => 'entity@localhost',
'entity_type' => 'entity_test',
'field_name' => 'comment',
'entity_id' => $entity
->id(),
'comment_type' => 'entity_test',
'status' => 1,
'pid' => $comment
->id(),
]);
$comment2
->save();
$this
->assertFalse($comment2
->hasParentComment());
$this
->assertTrue($comment2
->getThread() == '02/');
}
}