3 namespace Drupal\Tests\comment\Functional;
5 use Drupal\comment\Entity\CommentType;
6 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
7 use Drupal\Core\Language\LanguageInterface;
8 use Drupal\comment\CommentInterface;
9 use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
10 use Drupal\comment\Entity\Comment;
13 * Tests comments with other entities.
17 class CommentEntityTest extends CommentTestBase {
24 public static $modules = ['block', 'comment', 'node', 'history', 'field_ui', 'datetime', 'taxonomy'];
26 use TaxonomyTestTrait;
29 protected $commentType;
31 protected function setUp() {
34 $this->vocab = $this->createVocabulary();
35 $this->commentType = CommentType::create([
36 'id' => 'taxonomy_comment',
37 'label' => 'Taxonomy comment',
39 'target_entity_type_id' => 'taxonomy_term',
41 $this->commentType->save();
42 $this->addDefaultCommentField(
46 CommentItemInterface::OPEN,
47 $this->commentType->id()
52 * Tests CSS classes on comments.
54 public function testEntityChanges() {
55 $this->drupalLogin($this->webUser);
57 $term = $this->createTerm($this->vocab, ['uid' => $this->webUser->id()]);
60 /** @var \Drupal\comment\CommentInterface $comment */
61 $comment = Comment::create([
62 'entity_id' => $term->id(),
63 'entity_type' => 'taxonomy_term',
64 'field_name' => 'field_comment',
65 'uid' => $this->webUser->id(),
66 'status' => CommentInterface::PUBLISHED,
67 'subject' => $this->randomMachineName(),
68 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
69 'comment_body' => [LanguageInterface::LANGCODE_NOT_SPECIFIED => [$this->randomMachineName()]],
73 // Request the node with the comment.
74 $this->drupalGet('taxonomy/term/' . $term->id());
75 $settings = $this->getDrupalSettings();
76 $this->assertFalse(isset($settings['ajaxPageState']['libraries']) && in_array('comment/drupal.comment-new-indicator', explode(',', $settings['ajaxPageState']['libraries'])), 'drupal.comment-new-indicator library is present.');
77 $this->assertFalse(isset($settings['history']['lastReadTimestamps']) && in_array($term->id(), array_keys($settings['history']['lastReadTimestamps'])), 'history.lastReadTimestamps is present.');