Make WordPress Core

Opened 5 years ago

Last modified 20 months ago

#38433 new enhancement

Complete test coverage for current_user_can_for_blog()

Reported by: johnbillion Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.3
Component: Role/Capability Keywords: needs-unit-tests good-first-bug has-patch needs-dev-note
Focuses: Cc:


In Tests_User_Capabilities, all roles and capabilities are tested using current_user_can(). They should all be tested using current_user_can_for_blog(), too.

Attachments (3)

38433.diff (1.8 KB) - added by santilinwp 3 years ago.
38433.output (1.0 KB) - added by santilinwp 3 years ago.
38433.2.diff (3.1 KB) - added by santilinwp 3 years ago.
An extended patch which demostrates the duplicating of tests (multisite and not multisite)

Download all attachments as: .zip

Change History (8)

#1 @desrosj
3 years ago

  • Keywords needs-patch good-first-bug added

Marking good-first-bug for someone that would like to dive into writing unit tests.

#2 in reply to: ↑ description ; follow-up: @santilinwp
3 years ago

I'm going to have a try at it!

Version 3, edited 3 years ago by santilinwp (previous) (next) (diff)

3 years ago

3 years ago

#3 in reply to: ↑ 2 @santilinwp
3 years ago

Replying to santilinwp:

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.

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 @santilinwp
3 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.

3 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.

20 months ago

Note: See TracTickets for help on using tickets.