Problem/Motivation
Found this bug while review #2318875-20: Redo CommentStatisticsInterface
This broken at least from #2101183: Move {comment_entity_statistics} to proper service
Proposed resolution
Fix and cover with tests
Remaining tasks
Write tests, probably unittest because:
1) entity without owner interface - will always get 0 as author now (bug)
2) needs test if owner on entity is not set
both cases could mock the current user service with [0-1-2] permutations
User interface changes
no
API changes
no
Evaluation
| Issue category | Bug because broken |
|---|---|
| Issue priority | no Major because ... data will regenerate on next comment |
| Disruption | No |
| Unfrozen/prioritized changes | The issue fixes a bug in 8.x new code |
| Target | Given above, should be good for 8.0..x |
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | 2422443-40.patch | 15.62 KB | ameymudras |
| #37 | interdiff-2422443-35-37.txt | 5.6 KB | mohit_aghera |
| #37 | 2422443-37.patch | 14.98 KB | mohit_aghera |
| #35 | interdiff-2422443-33-35.txt | 4.87 KB | mohit_aghera |
| #35 | 2422443-35.patch | 12.28 KB | mohit_aghera |
Issue fork drupal-2422443
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2422443-fix-default-value
changes, plain diff MR !3200
Comments
Comment #1
larowlanComment #2
mgiffordWhat's the easiest way to test this? Code looks fine.
Comment #3
andypostStep to reproduce:
1) add comment field to entity (user, term, entity_test) that does not implements
EntityOwnerInterface2) create entity and check comment statistics
last_comment_uidshould be 0, but current user is expectedComment #4
roderikI my first thought "...if it's buggy but not failing, don't we need a test?"
But no, I don't think so. Just reading those lines of code makes clear that something is off and should be fixed. We don't need automated tests to see whether code is bad.
--- BUT -
The current patch is not consistent with the code comments around it (which are visible in the patch context). The comments indicate that getOwnerId() could return NULL.
(I got confused by the interface docs but Just checked with fago: it can return NULL.)
So the patch attached here in #4 actually does what the comments say.
P.S. I did test the steps in #3 manually, for completeness. #3 is correct.
Comment #6
roderikSo that was just a wrong interdiff name.
(Taking tag away to match my comment #4.)
Comment #7
andypostWe need tests, probably unittest because:
1) entity without owner interface - will always get 0 as author now (bug)
2) needs test if owner on entity is not set
3) permutation on current user ID [0-1]
Updated summary
;) define as undefined
Comment #8
roderikI'm just going to post this for review if the test covers what you want, in the way you want it. I still don't have a 'natural' feeling for unit tests. I probably have not done yet, what was mentioned about permutation on the user ID.
(I started writing a unit test in april, but then decided to try a simpletest based test instead, for checking the values on 'real life' fields. But I don't remember why I decided to do that anymore... so will leave the simpletest out of the patch. It's not completely finished anyway.)
(No interdiff because #7 was so small.)
Comment #10
roderikOK that still needed cleanup.
We are allowed to use PHP superglobals like $_SERVER?
Comment #11
roderikIn hindsight, I don't know what I was doing in #10. Never mind, let's start again. Uploading a new patch without interdiff - one test-only, one including code change.
The comments from #8 / about #7 still stand, I guess:(edit: I turned my brain on and it could parse what is clearly in the issue description)Comment #13
roderikRe-summarized prioritization: 8.0.x. (I don't know of a specified template for that; just used what makes sense to me.)
Comment #14
dawehnerInstead of doing that just use
$request->server->get('REQUEST_TIME')in the actual code.Note: You can use
AccountInterface::classComment #15
roderikre 14.1. OK so that's why I couldn't find references to $SERVER['REQUEST_TIME'] in the source. I think this is OK now.
1a. As a result of turning my brain on and reading the summary, now we're testing several entity creations with different UIDs.
re 14.2. I cannot grok this.
Comment #27
quietone commentedThis appears to be still applicable.
Comment #28
ankithashettyHere is the rerolled patch. Noticed a few long array syntax issues in the old patch, and handled them in the new patch.
Thanks!
Comment #29
ranjith_kumar_k_u commentedComment #31
Madhu Kumar M E commentedComment #33
mohit_aghera commentedLooks like patch in #31 is removing the changes by mistake.
I've put back the original code and changes.
- Fixing the test case failures.
- Interdiff is taken against patch from #29
- Tests seem to be passing on local now.
Comment #34
andypostI got some collision in #2318875-53: Redo CommentStatisticsInterface
it should be a method with Request $request argument, no reason to inject request stack here if there's only a request time here required or request object
Comment #35
mohit_aghera commentedThanks @andypost
That totally makes sense.
I have updated the patch and removed the service.
Comment #36
andypostI thought it will be picked from request not from global, see #2902895: [meta][no patch] Replace uses of REQUEST_TIME and time() with time service
Comment #37
mohit_aghera commentedThanks @andypost
I didn't realised about that service.
Fixed it.
Comment #39
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
Removing the needs tests tag as that seemed to be resolved.
See we have a change record but that still needs work. Description is currently TBD
#37 doesn't apply to 10.1.x either.
Moving to NW for the change record
Comment #40
ameymudras commentedRe rolling to 10.1.x
Comment #41
ameymudras commentedComment #44
smustgrave commentedChange record is still TBD.