WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#21742 closed enhancement (fixed)

Allow unit tests to override is_*_admin()

Reported by: ryan Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.4.1
Component: Unit Tests Keywords:
Focuses: Cc:

Description

Unit tests sometimes need to fake being in the user, network, or blog admin or on the front page. This is currently impossible due to the use of constants. A possible solution is to consult the current screen if it is setup and fallback to the constants otherwise. Alternatively, add filters in the is_*_admin() functions.

Attachments (6)

21742.diff (3.2 KB) - added by ryan 3 years ago.
Rough take on using WP_Screen
21742.2.diff (3.8 KB) - added by ryan 3 years ago.
21742.3.diff (4.6 KB) - added by ryan 3 years ago.
21742-ut.diff (2.2 KB) - added by ryan 3 years ago.
21742.4.diff (4.6 KB) - added by ryan 3 years ago.
21742.5.diff (38.1 KB) - added by nacin 3 years ago.

Download all attachments as: .zip

Change History (11)

@ryan3 years ago

Rough take on using WP_Screen

@ryan3 years ago

@ryan3 years ago

@ryan3 years ago

@ryan3 years ago

comment:1 @ryan3 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [21687]:

Introduce WP_Screen::in_admin() for determining which admin the screen is in.
Change is_*_admin() to reference in_admin() with fallback to the WP_*_ADMIN constants during early bootstrap. This allows unit tests and ajax handlers to set the admin context.

fixes #21742

comment:2 @SergeyBiryukov3 years ago

  • Milestone changed from Awaiting Review to 3.5

@nacin3 years ago

comment:3 @ocean903 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Missing dashboard widgets: http://cl.ly/J9gm

comment:4 @ryan3 years ago

In [21693]:

s/blog/site/. see #21742

comment:5 @ocean903 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.