CommentBaseFieldTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Drupal\Tests\comment\Kernel;
  3. use Drupal\comment\CommentInterface;
  4. use Drupal\comment\Entity\Comment;
  5. use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
  6. use Drupal\comment_base_field_test\Entity\CommentTestBaseField;
  7. use Drupal\Core\Language\LanguageInterface;
  8. use Drupal\KernelTests\KernelTestBase;
  9. /**
  10. * Tests that comment as a base field.
  11. *
  12. * @group comment
  13. */
  14. class CommentBaseFieldTest extends KernelTestBase {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public static $modules = [
  19. 'system',
  20. 'user',
  21. 'comment',
  22. 'comment_base_field_test',
  23. ];
  24. protected function setUp() {
  25. parent::setUp();
  26. $this->installEntitySchema('comment_test_base_field');
  27. $this->installEntitySchema('comment');
  28. $this->installSchema('system', ['sequences']);
  29. $this->installEntitySchema('user');
  30. }
  31. /**
  32. * Tests comment as a base field.
  33. */
  34. public function testCommentBaseField() {
  35. // Verify entity creation.
  36. $entity = CommentTestBaseField::create([
  37. 'name' => $this->randomMachineName(),
  38. 'test_comment' => CommentItemInterface::OPEN,
  39. ]);
  40. $entity->save();
  41. $comment = Comment::create([
  42. 'entity_id' => $entity->id(),
  43. 'entity_type' => 'comment_test_base_field',
  44. 'field_name' => 'test_comment',
  45. 'pid' => 0,
  46. 'uid' => 0,
  47. 'status' => CommentInterface::PUBLISHED,
  48. 'subject' => $this->randomMachineName(),
  49. 'hostname' => '127.0.0.1',
  50. 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  51. 'comment_body' => [['value' => $this->randomMachineName()]],
  52. ]);
  53. $comment->save();
  54. $this->assertEquals('test_comment_type', $comment->bundle());
  55. }
  56. }