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
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | 2886615-23.patch | 3.1 KB | quietone |
| #23 | 2886615-23-fail.patch | 2.45 KB | quietone |
| #23 | diff-16-23.txt | 3.12 KB | quietone |
| #16 | interdiff-2886615-11-16.txt | 865 bytes | scott_euser |
| #16 | drupal-comment-empty-title-2886615-16-D8.patch | 1.71 KB | scott_euser |
Comments
Comment #2
clemens.tolboomComment #3
clemens.tolboomComment #4
clemens.tolboomNo sure why the regex succeed always.
so I replaced it with
Comment #5
clemens.tolboomComment #10
joachim commentedWe've lost this comment.
Comment #11
scott_euser commentedSince 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
Comment #13
scott_euser commentedBack to needs review since second patch was meant to fail to prove test is now working (where it was previously a false positive)
Comment #14
vijaycs85Great find!
Comment #15
alexpottNice find!
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.Comment #16
scott_euser commentedMakes 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\FunctionalSo I followed that recommendation and the check for no empty element uses the recommended responseNotMatches().
Thanks!
Comment #23
quietone commentedLocal 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'.
Comment #25
lendudeLooks 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.
Comment #26
alexpottCommitted and pushed d7082acf60 to 10.0.x and dd103d843e to 9.4.x and aeb8420a93 to 9.3.x. Thanks!