annotate core/modules/comment/tests/src/Functional/CommentEntityTest.php @ 19:fa3358dc1485 tip

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