public function FlatCommentsPidTest::testPidIsNull in Flatcomments 8
Tests using entity fields of the comment field type.
File
- tests/src/ Kernel/ FlatCommentsPidTest.php, line 63 
Class
- FlatCommentsPidTest
- Tests the new entity API for the comment field type.
Namespace
Drupal\Tests\flat_comments\KernelCode
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();
  // Verify entity creation.
  $entity = EntityTest::create();
  $entity->name->value = $this
    ->randomMachineName();
  $entity
    ->save();
  // Create some comments.
  $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();
  // Even that explicitly was set a parent comment it be will removed thanks
  // to the flat comments module.
  $this
    ->assertFalse($comment2
    ->hasParentComment());
  // And the thread must be '02/' instead of '01.00/'.
  $this
    ->assertTrue($comment2
    ->getThread() == '02/');
}