Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\comment\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 /**
|
Chris@0
|
6 * Tests to ensure that appropriate and accessible markup is created for comment
|
Chris@0
|
7 * titles.
|
Chris@0
|
8 *
|
Chris@0
|
9 * @group comment
|
Chris@0
|
10 */
|
Chris@0
|
11 class CommentTitleTest extends CommentTestBase {
|
Chris@0
|
12 /**
|
Chris@0
|
13 * Tests markup for comments with empty titles.
|
Chris@0
|
14 */
|
Chris@0
|
15 public function testCommentEmptyTitles() {
|
Chris@0
|
16 // Installs module that sets comments to an empty string.
|
Chris@0
|
17 \Drupal::service('module_installer')->install(['comment_empty_title_test']);
|
Chris@0
|
18
|
Chris@0
|
19 // Set comments to have a subject with preview disabled.
|
Chris@0
|
20 $this->setCommentPreview(DRUPAL_DISABLED);
|
Chris@0
|
21 $this->setCommentForm(TRUE);
|
Chris@0
|
22 $this->setCommentSubject(TRUE);
|
Chris@0
|
23
|
Chris@0
|
24 // Create a node.
|
Chris@0
|
25 $this->drupalLogin($this->webUser);
|
Chris@0
|
26 $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]);
|
Chris@0
|
27
|
Chris@0
|
28 // Post comment #1 and verify that h3's are not rendered.
|
Chris@0
|
29 $subject_text = $this->randomMachineName();
|
Chris@0
|
30 $comment_text = $this->randomMachineName();
|
Chris@0
|
31 $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
|
Chris@0
|
32
|
Chris@0
|
33 // The entity fields for name and mail have no meaning if the user is not
|
Chris@0
|
34 // Anonymous.
|
Chris@0
|
35 $this->assertNull($comment->name->value);
|
Chris@0
|
36 $this->assertNull($comment->mail->value);
|
Chris@0
|
37
|
Chris@0
|
38 // Confirm that the comment was created.
|
Chris@0
|
39 $regex = '/<a id="comment-' . $comment->id() . '"(.*?)';
|
Chris@0
|
40 $regex .= $comment->comment_body->value . '(.*?)';
|
Chris@0
|
41 $regex .= '/s';
|
Chris@0
|
42 $this->assertPattern($regex, 'Comment is created successfully');
|
Chris@0
|
43 // Tests that markup is not generated for the comment without header.
|
Chris@0
|
44 $this->assertNoPattern('|<h3[^>]*></h3>|', 'Comment title H3 element not found when title is an empty string.');
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@0
|
47 /**
|
Chris@0
|
48 * Tests markup for comments with populated titles.
|
Chris@0
|
49 */
|
Chris@0
|
50 public function testCommentPopulatedTitles() {
|
Chris@0
|
51 // Set comments to have a subject with preview disabled.
|
Chris@0
|
52 $this->setCommentPreview(DRUPAL_DISABLED);
|
Chris@0
|
53 $this->setCommentForm(TRUE);
|
Chris@0
|
54 $this->setCommentSubject(TRUE);
|
Chris@0
|
55
|
Chris@0
|
56 // Create a node.
|
Chris@0
|
57 $this->drupalLogin($this->webUser);
|
Chris@0
|
58 $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]);
|
Chris@0
|
59
|
Chris@0
|
60 // Post comment #1 and verify that title is rendered in h3.
|
Chris@0
|
61 $subject_text = $this->randomMachineName();
|
Chris@0
|
62 $comment_text = $this->randomMachineName();
|
Chris@0
|
63 $comment1 = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
|
Chris@0
|
64
|
Chris@0
|
65 // The entity fields for name and mail have no meaning if the user is not
|
Chris@0
|
66 // Anonymous.
|
Chris@0
|
67 $this->assertNull($comment1->name->value);
|
Chris@0
|
68 $this->assertNull($comment1->mail->value);
|
Chris@0
|
69
|
Chris@0
|
70 // Confirm that the comment was created.
|
Chris@0
|
71 $this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.');
|
Chris@0
|
72 // Tests that markup is created for comment with heading.
|
Chris@0
|
73 $this->assertPattern('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|', 'Comment title is rendered in h3 when title populated.');
|
Chris@0
|
74 // Tests that the comment's title link is the permalink of the comment.
|
Chris@0
|
75 $comment_permalink = $this->cssSelect('.permalink');
|
Chris@0
|
76 $comment_permalink = $comment_permalink[0]->getAttribute('href');
|
Chris@0
|
77 // Tests that the comment's title link contains the url fragment.
|
Chris@0
|
78 $this->assertTrue(strpos($comment_permalink, '#comment-' . $comment1->id()), "The comment's title link contains the url fragment.");
|
Chris@0
|
79 $this->assertEqual($comment1->permalink()->toString(), $comment_permalink, "The comment's title has the correct link.");
|
Chris@0
|
80 }
|
Chris@0
|
81
|
Chris@0
|
82 }
|