Make WordPress Core

Opened 7 years ago

Last modified 4 years ago

#38433 new enhancement

Complete test coverage for current_user_can_for_blog()

Reported by: johnbillion's profile 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:

Description

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 5 years ago.
38433.output (1.0 KB) - added by santilinwp 5 years ago.
38433.2.diff (3.1 KB) - added by santilinwp 5 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
5 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
5 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.

Last edited 5 years ago by santilinwp (previous) (diff)

@santilinwp
5 years ago

@santilinwp
5 years ago

#3 in reply to: ↑ 2 @santilinwp
5 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
5 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.

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


4 years ago

Note: See TracTickets for help on using tickets.