[wp-trac] [WordPress Trac] #29712: Restore $current_user between unit tests

WordPress Trac noreply at wordpress.org
Fri Oct 24 00:57:00 UTC 2014


#29712: Restore $current_user between unit tests
------------------------------+--------------------
 Reporter:  mnelson4          |       Owner:
     Type:  enhancement       |      Status:  new
 Priority:  normal            |   Milestone:  4.1
Component:  Build/Test Tools  |     Version:  trunk
 Severity:  normal            |  Resolution:
 Keywords:                    |     Focuses:
------------------------------+--------------------
Changes (by boonebgorges):

 * milestone:  Awaiting Review => 4.1


Comment:

 > If the $current_user global is changed during a unit test, that change
 is persisted to all subsequent unit tests, making the tests dependent on
 order.

 Yup, good find.

 > If you do need to set the current user for some reason, you should do
 wp_set_current_user(), then call wp_set_current_user(0) in your tearDown.
 We could do that in our own class's tearDown, we just haven't.

 We should, and we shall :) mnelson4, I see the motivation behind your
 original patch (seems like the safe thing to do) but it only uncovers
 other issues: `$userdata` can get muddled between tests, as well as a
 bunch of other ugly little globals. (See `setup_userdata()`.) Safer not to
 touch the globals at all if we can help it. Core tests expect the current
 user to be 0 for each test, so `wp_set_current_user( 0 )` is a safe bet.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29712#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list