comparison core/modules/comment/tests/src/Functional/CommentInterfaceTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\Tests\comment\Functional; 3 namespace Drupal\Tests\comment\Functional;
4 4
5 use Drupal\Core\Url;
5 use Drupal\comment\CommentManagerInterface; 6 use Drupal\comment\CommentManagerInterface;
6 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; 7 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
7 use Drupal\comment\Entity\Comment; 8 use Drupal\comment\Entity\Comment;
8 use Drupal\Core\Entity\Entity\EntityViewDisplay; 9 use Drupal\Core\Entity\Entity\EntityViewDisplay;
9 use Drupal\Core\Entity\Entity\EntityViewMode; 10 use Drupal\Core\Entity\Entity\EntityViewMode;
23 protected function setUp() { 24 protected function setUp() {
24 parent::setUp(); 25 parent::setUp();
25 $this->drupalLogin($this->adminUser); 26 $this->drupalLogin($this->adminUser);
26 // Make sure that comment field title is not displayed when there's no 27 // Make sure that comment field title is not displayed when there's no
27 // comments posted. 28 // comments posted.
28 $this->drupalGet($this->node->urlInfo()); 29 $this->drupalGet($this->node->toUrl());
29 $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments title is not displayed.'); 30 $this->assertSession()->responseNotMatches('@<h2[^>]*>Comments</h2>@', 'Comments title is not displayed.');
30 31
31 // Set comments to have subject and preview disabled. 32 // Set comments to have subject and preview disabled.
32 $this->setCommentPreview(DRUPAL_DISABLED); 33 $this->setCommentPreview(DRUPAL_DISABLED);
33 $this->setCommentForm(TRUE); 34 $this->setCommentForm(TRUE);
34 $this->setCommentSubject(FALSE); 35 $this->setCommentSubject(FALSE);
46 $comment_text = $this->randomMachineName(); 47 $comment_text = $this->randomMachineName();
47 $comment = $this->postComment($this->node, $comment_text); 48 $comment = $this->postComment($this->node, $comment_text);
48 $this->assertTrue($this->commentExists($comment), 'Comment found.'); 49 $this->assertTrue($this->commentExists($comment), 'Comment found.');
49 50
50 // Test the comment field title is displayed when there's comments. 51 // Test the comment field title is displayed when there's comments.
51 $this->drupalGet($this->node->urlInfo()); 52 $this->drupalGet($this->node->toUrl());
52 $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments title is displayed.'); 53 $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments title is displayed.');
53 54
54 // Set comments to have subject and preview to required. 55 // Set comments to have subject and preview to required.
55 $this->drupalLogout(); 56 $this->drupalLogout();
56 $this->drupalLogin($this->adminUser); 57 $this->drupalLogin($this->adminUser);
106 $this->drupalGet('node/' . $this->node->id()); 107 $this->drupalGet('node/' . $this->node->id());
107 $this->assertText($random_name . ' (' . t('not verified') . ')', 'Comment author successfully changed to an unverified user.'); 108 $this->assertText($random_name . ' (' . t('not verified') . ')', 'Comment author successfully changed to an unverified user.');
108 109
109 // Test changing the comment author to a verified user. 110 // Test changing the comment author to a verified user.
110 $this->drupalGet('comment/' . $comment->id() . '/edit'); 111 $this->drupalGet('comment/' . $comment->id() . '/edit');
111 $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => $this->webUser->getUsername() . ' (' . $this->webUser->id() . ')']); 112 $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => $this->webUser->getAccountName() . ' (' . $this->webUser->id() . ')']);
112 $this->assertTrue($comment->getAuthorName() == $this->webUser->getUsername() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.'); 113 $this->assertTrue($comment->getAuthorName() == $this->webUser->getAccountName() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.');
113 114
114 $this->drupalLogout(); 115 $this->drupalLogout();
115 116
116 // Reply to comment #2 creating comment #3 with optional preview and no 117 // Reply to comment #2 creating comment #3 with optional preview and no
117 // subject though field enabled. 118 // subject though field enabled.
118 $this->drupalLogin($this->webUser); 119 $this->drupalLogin($this->webUser);
119 // Deliberately use the wrong url to test 120 // Deliberately use the wrong url to test
120 // \Drupal\comment\Controller\CommentController::redirectNode(). 121 // \Drupal\comment\Controller\CommentController::redirectNode().
121 $this->drupalGet('comment/' . $this->node->id() . '/reply'); 122 $this->drupalGet('comment/' . $this->node->id() . '/reply');
122 // Verify we were correctly redirected. 123 // Verify we were correctly redirected.
123 $this->assertUrl(\Drupal::url('comment.reply', ['entity_type' => 'node', 'entity' => $this->node->id(), 'field_name' => 'comment'], ['absolute' => TRUE])); 124 $this->assertUrl(Url::fromRoute('comment.reply', ['entity_type' => 'node', 'entity' => $this->node->id(), 'field_name' => 'comment'], ['absolute' => TRUE])->toString());
124 $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment->id()); 125 $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment->id());
125 $this->assertText($subject_text, 'Individual comment-reply subject found.'); 126 $this->assertText($subject_text, 'Individual comment-reply subject found.');
126 $this->assertText($comment_text, 'Individual comment-reply body found.'); 127 $this->assertText($comment_text, 'Individual comment-reply body found.');
127 $reply = $this->postComment(NULL, $this->randomMachineName(), '', TRUE); 128 $reply = $this->postComment(NULL, $this->randomMachineName(), '', TRUE);
128 $reply_loaded = Comment::load($reply->id()); 129 $reply_loaded = Comment::load($reply->id());