Chris@0: install(['comment_empty_title_test']); Chris@0: Chris@0: // Set comments to have a subject with preview disabled. Chris@0: $this->setCommentPreview(DRUPAL_DISABLED); Chris@0: $this->setCommentForm(TRUE); Chris@0: $this->setCommentSubject(TRUE); Chris@0: Chris@0: // Create a node. Chris@0: $this->drupalLogin($this->webUser); Chris@0: $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]); Chris@0: Chris@0: // Post comment #1 and verify that h3's are not rendered. Chris@0: $subject_text = $this->randomMachineName(); Chris@0: $comment_text = $this->randomMachineName(); Chris@0: $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); Chris@0: Chris@0: // The entity fields for name and mail have no meaning if the user is not Chris@0: // Anonymous. Chris@0: $this->assertNull($comment->name->value); Chris@0: $this->assertNull($comment->mail->value); Chris@0: Chris@0: // Confirm that the comment was created. Chris@18: $regex = '/id() . '"(.*?)'; Chris@0: $regex .= $comment->comment_body->value . '(.*?)'; Chris@0: $regex .= '/s'; Chris@0: $this->assertPattern($regex, 'Comment is created successfully'); Chris@0: // Tests that markup is not generated for the comment without header. Chris@18: $this->assertSession()->responseNotMatches('|]*>|', 'Comment title H3 element not found when title is an empty string.'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests markup for comments with populated titles. Chris@0: */ Chris@0: public function testCommentPopulatedTitles() { Chris@0: // Set comments to have a subject with preview disabled. Chris@0: $this->setCommentPreview(DRUPAL_DISABLED); Chris@0: $this->setCommentForm(TRUE); Chris@0: $this->setCommentSubject(TRUE); Chris@0: Chris@0: // Create a node. Chris@0: $this->drupalLogin($this->webUser); Chris@0: $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]); Chris@0: Chris@0: // Post comment #1 and verify that title is rendered in h3. Chris@0: $subject_text = $this->randomMachineName(); Chris@0: $comment_text = $this->randomMachineName(); Chris@0: $comment1 = $this->postComment($this->node, $comment_text, $subject_text, TRUE); Chris@0: Chris@0: // The entity fields for name and mail have no meaning if the user is not Chris@0: // Anonymous. Chris@0: $this->assertNull($comment1->name->value); Chris@0: $this->assertNull($comment1->mail->value); Chris@0: Chris@0: // Confirm that the comment was created. Chris@0: $this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.'); Chris@0: // Tests that markup is created for comment with heading. Chris@0: $this->assertPattern('|]*>]*>' . $subject_text . '|', 'Comment title is rendered in h3 when title populated.'); Chris@0: // Tests that the comment's title link is the permalink of the comment. Chris@0: $comment_permalink = $this->cssSelect('.permalink'); Chris@0: $comment_permalink = $comment_permalink[0]->getAttribute('href'); Chris@0: // Tests that the comment's title link contains the url fragment. Chris@0: $this->assertTrue(strpos($comment_permalink, '#comment-' . $comment1->id()), "The comment's title link contains the url fragment."); Chris@0: $this->assertEqual($comment1->permalink()->toString(), $comment_permalink, "The comment's title has the correct link."); Chris@0: } Chris@0: Chris@0: }