comparison core/modules/comment/tests/src/Functional/CommentEntityTest.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace Drupal\Tests\comment\Functional;
4
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;
11
12 /**
13 * Tests comments with other entities.
14 *
15 * @group comment
16 */
17 class CommentEntityTest extends CommentTestBase {
18
19 /**
20 * Modules to install.
21 *
22 * @var array
23 */
24 public static $modules = ['block', 'comment', 'node', 'history', 'field_ui', 'datetime', 'taxonomy'];
25
26 use TaxonomyTestTrait;
27
28 protected $vocab;
29 protected $commentType;
30
31 protected function setUp() {
32 parent::setUp();
33
34 $this->vocab = $this->createVocabulary();
35 $this->commentType = CommentType::create([
36 'id' => 'taxonomy_comment',
37 'label' => 'Taxonomy comment',
38 'description' => '',
39 'target_entity_type_id' => 'taxonomy_term',
40 ]);
41 $this->commentType->save();
42 $this->addDefaultCommentField(
43 'taxonomy_term',
44 $this->vocab->id(),
45 'field_comment',
46 CommentItemInterface::OPEN,
47 $this->commentType->id()
48 );
49 }
50
51 /**
52 * Tests CSS classes on comments.
53 */
54 public function testEntityChanges() {
55 $this->drupalLogin($this->webUser);
56 // Create a new node.
57 $term = $this->createTerm($this->vocab, ['uid' => $this->webUser->id()]);
58
59 // Add a comment.
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()]],
70 ]);
71 $comment->save();
72
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.');
78 }
79
80 }