Avoid undefined index notices in WP_UnitTestCase::_restore_hooks().

props kevinlangleyjr.
fixes #29123.

git-svn-id: https://develop.svn.wordpress.org/trunk@29503 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2014-08-15 15:40:48 +00:00
parent b6f0d0c208
commit 262929004d

View File

@ -67,10 +67,11 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
}
/**
* Saves the action and filter-related globals so they can be restored later
* Saves the action and filter-related globals so they can be restored later.
*
* Stores $merged_filters, $wp_actions, $wp_current_filter, and $wp_filter
* on a class variable so they can be restored on tearDown() using _restore_hooks()
* on a class variable so they can be restored on tearDown() using _restore_hooks().
*
* @global array $merged_filters
* @global array $wp_actions
* @global array $wp_current_filter
@ -86,8 +87,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
/**
* Restores the hook-related globals to their state at setUp()
*
* so that future tests aren't affected by hooks set during this last test
* so that future tests aren't affected by hooks set during this last test.
*
* @global array $merged_filters
* @global array $wp_actions
@ -95,10 +95,12 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
* @global array $wp_filter
* @return void
*/
protected function _restore_hooks(){
protected function _restore_hooks() {
$globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' );
foreach ( $globals as $key ) {
$GLOBALS[ $key ] = self::$hooks_saved[ $key ];
if ( isset( self::$hooks_saved[ $key ] ) ) {
$GLOBALS[ $key ] = self::$hooks_saved[ $key ];
}
}
}