Fix the unit test added in [32173] to run correctly in PHP 5.2.

git-svn-id: https://develop.svn.wordpress.org/trunk@32177 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2015-04-20 09:40:11 +00:00
parent 05710aaa41
commit 8453d41a44
1 changed files with 15 additions and 17 deletions

View File

@ -704,30 +704,28 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
$orig_blog_id = get_current_blog_id();
$blog_id = $this->factory->blog->create();
$nullify_current_user = function() {
// Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog()
$function_stack = wp_debug_backtrace_summary( null, 0, false );
if ( in_array( 'restore_current_blog', $function_stack ) ) {
return;
}
$GLOBALS['current_user'] = null;
};
$this->_nullify_current_user();
$nullify_current_user_and_keep_nullifying_user = function() use ( $nullify_current_user ) {
$nullify_current_user();
add_action( 'set_current_user', $nullify_current_user );
};
$nullify_current_user();
add_action( 'switch_blog', $nullify_current_user_and_keep_nullifying_user );
add_action( 'switch_blog', array( $this, '_nullify_current_user_and_keep_nullifying_user' ) );
current_user_can_for_blog( $blog_id, 'edit_posts' );
$this->assertEquals( $orig_blog_id, get_current_blog_id() );
}
function _nullify_current_user() {
// Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog()
$function_stack = wp_debug_backtrace_summary( null, 0, false );
if ( in_array( 'restore_current_blog', $function_stack ) ) {
return;
}
$GLOBALS['current_user'] = null;
}
function _nullify_current_user_and_keep_nullifying_user() {
add_action( 'set_current_user', array( $this, '_nullify_current_user' ) );
}
/**
* @ticket 28374
*/