#38433 closed enhancement (fixed)
Complete test coverage for current_user_can_for_site()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 6.7 | Priority: | normal |
| Severity: | normal | Version: | 4.3 |
| Component: | Role/Capability | Keywords: | good-first-bug has-patch has-unit-tests |
| Focuses: | Cc: |
Description (last modified by )
In Tests_User_Capabilities, all roles and capabilities are tested using current_user_can(). They should all be tested using current_user_can_for_site(), too.
Attachments (4)
Change History (15)
#2
in reply to:
↑ description
;
follow-up:
↓ 3
@
7 years ago
I'v duplicated the calls in one function: test_subscriber_cant_edit_posts with the desired result, but then I have added a new function to test that an editor CAN edit their posts but no others in another site, but it looks like current_user_can_for_blog takes the current site when the other site doesn't exist.
I'll attach the diff and the output.
#3
in reply to:
↑ 2
@
7 years ago
Replying to santilinwp:
I'v duplicated the calls in one function:
test_subscriber_cant_edit_postswith the desired result, but then I have added a new function to test that an editor CAN edit their posts but no others in another site, but it looks likecurrent_user_can_for_blogtakes the current site when the other site doesn't exist.
I'll attach the diff and the output.
Digging a little bit more in the code I've learnt that current_user_can_for_blog just disregards the $blog_id parameter if not is_multisite, so the test is allright.
#4
@
7 years ago
- Keywords has-patch needs-dev-note added; needs-patch removed
I understand that the way to go is duplicate most of the functions to make multisite and not multisite versions, like in the attached example.
@
7 years ago
An extended patch which demostrates the duplicating of tests (multisite and not multisite)
This ticket was mentioned in Slack in #core by backermann1978. View the logs.
5 years ago
#6
@
10 months ago
While looking for a good first ticket to contribute I looked at this one.
I think this ticket can be closed, and marked as done. Seeing current_user__can_for_blog has been deprecated: * @deprecated 6.7.0 Use current_user_can_for_site() instead. I don't know the test coverage, but there are multiple tests for current_user_can_for_site.
#7
@
3 months ago
Added current_user_can_for_blog() assertions to Tests_User_Capabilities for full coverage.
#8
@
3 months ago
- Description modified (diff)
- Keywords has-unit-tests added; needs-unit-tests needs-dev-note removed
- Summary changed from Complete test coverage for current_user_can_for_blog() to Complete test coverage for current_user_can_for_site()
Thanks so much for the patch @sachinrajcp123 . Would you like to open a GitHub pull request with those changes please so the test suite can run?
Also the function has been deprecated since this ticket was opened so I've changed the title. The preferred function name is now current_user_can_for_site().
#9
@
3 months ago
- Milestone changed from Future Release to 6.7
- Resolution set to fixed
- Status changed from new to closed
Oh you know what, @michaelwp85 is correct. This function actually has test coverage now since #45197. Thanks everyone!
This ticket was mentioned in Slack in #core-committers by johnbillion. View the logs.
3 months ago
This ticket was mentioned in PR #9454 on WordPress/wordpress-develop by @sachinrajcp123.
3 months ago
#11
Adds test coverage for current_user_can_for_site() and user_can_for_site().
Replaces remaining uses of deprecated current_user_can_for_blog() in tests.
Marking
good-first-bugfor someone that would like to dive into writing unit tests.