function CommentEntityTest::testEntityChanges
Tests CSS classes on comments.
File
- 
              core/
modules/ comment/ tests/ src/ Functional/ CommentEntityTest.php, line 67  
Class
- CommentEntityTest
 - Tests comments with other entities.
 
Namespace
Drupal\Tests\comment\FunctionalCode
public function testEntityChanges() {
  $this->drupalLogin($this->webUser);
  // Create a new node.
  $term = $this->createTerm($this->vocab, [
    'uid' => $this->webUser
      ->id(),
  ]);
  // Add a comment.
  /** @var \Drupal\comment\CommentInterface $comment */
  $comment = Comment::create([
    'entity_id' => $term->id(),
    'entity_type' => 'taxonomy_term',
    'field_name' => 'field_comment',
    'uid' => $this->webUser
      ->id(),
    'status' => CommentInterface::PUBLISHED,
    'subject' => $this->randomMachineName(),
    'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
    'comment_body' => [
      LanguageInterface::LANGCODE_NOT_SPECIFIED => [
        $this->randomMachineName(),
      ],
    ],
  ]);
  $comment->save();
  // Request the node with the comment.
  $this->drupalGet('taxonomy/term/' . $term->id());
  $settings = $this->getDrupalSettings();
  $this->assertFalse(isset($settings['ajaxPageState']['libraries']) && in_array('comment/drupal.comment-new-indicator', explode(',', $settings['ajaxPageState']['libraries'])), 'drupal.comment-new-indicator library is present.');
  $this->assertFalse(isset($settings['history']['lastReadTimestamps']) && in_array($term->id(), array_keys($settings['history']['lastReadTimestamps'])), 'history.lastReadTimestamps is present.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.