annotate core/modules/comment/tests/src/Functional/CommentEntityTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\comment\Functional;
Chris@0 4
Chris@0 5 use Drupal\comment\Entity\CommentType;
Chris@0 6 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
Chris@0 7 use Drupal\Core\Language\LanguageInterface;
Chris@0 8 use Drupal\comment\CommentInterface;
Chris@0 9 use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
Chris@0 10 use Drupal\comment\Entity\Comment;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Tests comments with other entities.
Chris@0 14 *
Chris@0 15 * @group comment
Chris@0 16 */
Chris@0 17 class CommentEntityTest extends CommentTestBase {
Chris@0 18
Chris@0 19 /**
Chris@0 20 * Modules to install.
Chris@0 21 *
Chris@0 22 * @var array
Chris@0 23 */
Chris@0 24 public static $modules = ['block', 'comment', 'node', 'history', 'field_ui', 'datetime', 'taxonomy'];
Chris@0 25
Chris@0 26 use TaxonomyTestTrait;
Chris@0 27
Chris@0 28 protected $vocab;
Chris@0 29 protected $commentType;
Chris@0 30
Chris@0 31 protected function setUp() {
Chris@0 32 parent::setUp();
Chris@0 33
Chris@0 34 $this->vocab = $this->createVocabulary();
Chris@0 35 $this->commentType = CommentType::create([
Chris@0 36 'id' => 'taxonomy_comment',
Chris@0 37 'label' => 'Taxonomy comment',
Chris@0 38 'description' => '',
Chris@0 39 'target_entity_type_id' => 'taxonomy_term',
Chris@0 40 ]);
Chris@0 41 $this->commentType->save();
Chris@0 42 $this->addDefaultCommentField(
Chris@0 43 'taxonomy_term',
Chris@0 44 $this->vocab->id(),
Chris@0 45 'field_comment',
Chris@0 46 CommentItemInterface::OPEN,
Chris@0 47 $this->commentType->id()
Chris@0 48 );
Chris@0 49 }
Chris@0 50
Chris@0 51 /**
Chris@0 52 * Tests CSS classes on comments.
Chris@0 53 */
Chris@0 54 public function testEntityChanges() {
Chris@0 55 $this->drupalLogin($this->webUser);
Chris@0 56 // Create a new node.
Chris@0 57 $term = $this->createTerm($this->vocab, ['uid' => $this->webUser->id()]);
Chris@0 58
Chris@0 59 // Add a comment.
Chris@0 60 /** @var \Drupal\comment\CommentInterface $comment */
Chris@0 61 $comment = Comment::create([
Chris@0 62 'entity_id' => $term->id(),
Chris@0 63 'entity_type' => 'taxonomy_term',
Chris@0 64 'field_name' => 'field_comment',
Chris@0 65 'uid' => $this->webUser->id(),
Chris@0 66 'status' => CommentInterface::PUBLISHED,
Chris@0 67 'subject' => $this->randomMachineName(),
Chris@0 68 'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
Chris@0 69 'comment_body' => [LanguageInterface::LANGCODE_NOT_SPECIFIED => [$this->randomMachineName()]],
Chris@0 70 ]);
Chris@0 71 $comment->save();
Chris@0 72
Chris@0 73 // Request the node with the comment.
Chris@0 74 $this->drupalGet('taxonomy/term/' . $term->id());
Chris@0 75 $settings = $this->getDrupalSettings();
Chris@0 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.');
Chris@0 77 $this->assertFalse(isset($settings['history']['lastReadTimestamps']) && in_array($term->id(), array_keys($settings['history']['lastReadTimestamps'])), 'history.lastReadTimestamps is present.');
Chris@0 78 }
Chris@0 79
Chris@0 80 }