Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
#2099131: Use #pre_render pattern for entity render caching added CommentDefaultFormatterCacheTagsTest as a web test instead of as a unit test. This fixes that.
Comment | File | Size | Author |
---|---|---|---|
#5 | comment-unit-test-5.patch | 2.6 KB | Wim Leers |
Comments
Comment #2
Wim Leerscomment-unit-test.patch queued for re-testing.
Comment #3
sunComment #4
Wim LeersNo!
This must explicitly remain a user with only the 'access comments' permission, for the reasons outlined in #2099131-201: Use #pre_render pattern for entity render caching.
Comment #5
Wim LeersComment #6
Wim LeersComment #7
effulgentsia CreditAttribution: effulgentsia commented#5 looks good, but given the comment in the interdiff, is it a problem that the original patch passed? Are we missing an assertion related to unpublished comments?
Comment #8
Wim Leers#7: It says "published comment" in the code comment because that's what
CommentDefaultFormatter
's if-test says. But the reason I'm insisting on using'access comments'
is because the condition to render comments that applies to 99% of users (who don't have the permission to administer comments) looks like this:(($entity->get($field_name)->comment_count && $this->currentUser->hasPermission('access comments'))
And in my work on #2099131: Use #pre_render pattern for entity render caching, I discovered that
$comment->save()
did NOT reset the commented entity's storage cache, which causedcomment_count
to remain at zero, even after comments were posted.Giving users all permissions tests the 1% case, giving the user only permission to access comments tests the 99% case.
Hopefully this is more clear. But I know, it's confusing and frustratingly complex. Again, see #2099131-201: Use #pre_render pattern for entity render caching for all the details, and an interdiff that shows the problems explicitly.
Comment #9
effulgentsia CreditAttribution: effulgentsia commentedIf we don't have one, a separate unit test for this would be good, rather than solely testing it incidentally in a formatter's test. But regardless, that's separate scope from this issue. #5 is closer to HEAD than the original patch, so RTBC.
Comment #10
Wim LeersAgreed.
The key problem is that
CommentDefaultFormatter
was added with ZERO test coverage. I only added the regression test coverage needed to prevent regressions of the bugs I fixed and discovered while working on something completely independent.Comment #11
catchCommitted/pushed to 8.x, thanks!
Comment #13
dawehnerMh, sadly this test does not really work as you would expect it and causes kind of "random" failures on other patches, see #2263329: CommentDefaultFormatterCacheTagsTest just works because nothing uses AccountProxyInterface in HEAD
Comment #14
dawehnerHa, effulgentsia should have know that better.