Make WordPress Core


Ignore:
Timestamp:
08/15/2014 03:40:48 PM (10 years ago)
Author:
SergeyBiryukov
Message:

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

props kevinlangleyjr.
fixes #29123.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r29274 r29503  
    6868
    6969    /**
    70      * Saves the action and filter-related globals so they can be restored later
     70     * Saves the action and filter-related globals so they can be restored later.
    7171     *
    7272     * Stores $merged_filters, $wp_actions, $wp_current_filter, and $wp_filter
    73      * on a class variable so they can be restored on tearDown() using _restore_hooks()
    74      * @global array $merged_filters
    75      * @global array $wp_actions
    76      * @global array $wp_current_filter
    77      * @global array $wp_filter
    78      * @return void
    79      */
    80     protected function _backup_hooks() {
    81         $globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' );
    82         foreach ( $globals as $key ) {
    83             self::$hooks_saved[ $key ] = $GLOBALS[ $key ];
    84         }
    85     }
    86 
    87     /**
    88      * Restores the hook-related globals to their state at setUp()
    89      *
    90      * so that future tests aren't affected by hooks set during this last test
     73     * on a class variable so they can be restored on tearDown() using _restore_hooks().
    9174     *
    9275     * @global array $merged_filters
     
    9679     * @return void
    9780     */
    98     protected function _restore_hooks(){
     81    protected function _backup_hooks() {
    9982        $globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' );
    10083        foreach ( $globals as $key ) {
    101             $GLOBALS[ $key ] = self::$hooks_saved[ $key ];
     84            self::$hooks_saved[ $key ] = $GLOBALS[ $key ];
     85        }
     86    }
     87
     88    /**
     89     * Restores the hook-related globals to their state at setUp()
     90     * so that future tests aren't affected by hooks set during this last test.
     91     *
     92     * @global array $merged_filters
     93     * @global array $wp_actions
     94     * @global array $wp_current_filter
     95     * @global array $wp_filter
     96     * @return void
     97     */
     98    protected function _restore_hooks() {
     99        $globals = array( 'merged_filters', 'wp_actions', 'wp_current_filter', 'wp_filter' );
     100        foreach ( $globals as $key ) {
     101            if ( isset( self::$hooks_saved[ $key ] ) ) {
     102                $GLOBALS[ $key ] = self::$hooks_saved[ $key ];
     103            }
    102104        }
    103105    }
Note: See TracChangeset for help on using the changeset viewer.