Problem/Motivation

The hook name uses plural titles instead of single title for hook comment_empty_title_test_preprocess_comment.

The test

    // Tests that markup is not generated for the comment without header.
    $this->assertNoPattern('|<h3[^>]*></h3>|', 'Comment title H3 element not found when title is an empty string.');

somehow succeeds instead of failing.

Proposed resolution

Fix the test and the test module.

Remaining tasks

Review
Commit

User interface changes

N/A

API changes

N/A

Data model changes

Comments

clemens.tolboom created an issue. See original summary.

clemens.tolboom’s picture

Issue summary: View changes
clemens.tolboom’s picture

Issue summary: View changes
clemens.tolboom’s picture

StatusFileSize
new741 bytes
new1.37 KB

No sure why the regex succeed always.

    // Tests that markup is not generated for the comment without header.
    $this->assertNoPattern('|<h3[^>]*></h3>|', 'Comment title H3 element not found when title is an empty string.');

so I replaced it with

    $this->assertNoText($subject_text, 'No comment title');
clemens.tolboom’s picture

Issue summary: View changes

The last submitted patch, 4: 2886615-4-test-only.patch, failed testing. View results

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

+++ b/core/modules/comment/src/Tests/CommentTitleTest.php
@@ -34,8 +34,7 @@ public function testCommentEmptyTitles() {
-    // Tests that markup is not generated for the comment without header.

We've lost this comment.

scott_euser’s picture

Since this issue was created, the tests were refactored into core/modules/comment/tests/src/Functional/CommentTitleTest.php but the issue still remains.

Issue
Test regex checks that title is missing and passes but simpletest output shows the title is actually on the page
Reason
Hook is incorrectly implement

drupal-comment-empty-title-2886615-11-D8__test_fail.patch
Updates test to cause it to correctly fail without changing the invalid hook

drupal-comment-empty-title-2886615-11-D8.patch
Fixes the invalid hook

Status: Needs review » Needs work
scott_euser’s picture

Status: Needs work » Needs review

Back to needs review since second patch was meant to fail to prove test is now working (where it was previously a false positive)

vijaycs85’s picture

Status: Needs review » Reviewed & tested by the community

Great find!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Nice find!

+++ b/core/modules/comment/src/Tests/CommentTitleTest.php
@@ -34,8 +34,7 @@ public function testCommentEmptyTitles() {
-    // Tests that markup is not generated for the comment without header.
-    $this->assertNoPattern('|<h3[^>]*></h3>|', 'Comment title H3 element not found when title is an empty string.');

I think this test is also trying to assert that no <h3></h3> is being adding to the page. Now we're not covering that case. I think we should still assert that there are no H3s empty on the page. So let's leave this assert in there. But we need the new assert to prove that the hook is working.

scott_euser’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB
new865 bytes

Makes sense, thanks for the review! I have updated the test to ensure there is no empty element. On my local I got the following error with the original code:
Remaining deprecation notices (1) 1x: assertNoPattern() is deprecated and scheduled for removal in Drupal 9.0.0. Use $this->assertSession()->responseNotMatches($pattern) instead. See https://www.drupal.org/node/2864262. 1x in CommentTitleTest::testCommentEmptyTitles from Drupal\Tests\comment\Functional
So I followed that recommendation and the check for no empty element uses the recommended responseNotMatches().

Thanks!

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Issue tags: +Bug Smash Initiative
StatusFileSize
new3.12 KB
new2.45 KB
new3.1 KB

Local testing showed that the test is not doing what the comments say it is. There are two errors here, one is the name of the hook in the test module is wrong and therefor never executes and the other is that the regex for finding 'h3' tags wasn't actually finding them.

This patch adds a test to verify that the regex for finding 'h3' tags works. Then it installs the test module and runs the test as before, with the exception of using the new regex for finding 'h3'.

The last submitted patch, 23: 2886615-23-fail.patch, failed testing. View results

lendude’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, we have the positive assertion that the regex is testing what we want and the positive assert that the comment is rendered after posing the second comment, so in that way it looks acceptable to end on the negative assertions.

alexpott’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed d7082acf60 to 10.0.x and dd103d843e to 9.4.x and aeb8420a93 to 9.3.x. Thanks!

  • alexpott committed d7082ac on 10.0.x
    Issue #2886615 by scott_euser, clemens.tolboom, quietone, joachim,...

  • alexpott committed dd103d8 on 9.4.x
    Issue #2886615 by scott_euser, clemens.tolboom, quietone, joachim,...

  • alexpott committed aeb8420 on 9.3.x
    Issue #2886615 by scott_euser, clemens.tolboom, quietone, joachim,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.