Make WordPress Core

Ticket #28535: ticket-28535.diff

File ticket-28535.diff, 2.6 KB (added by mnelson4, 10 years ago)

patch to backup hooks between each test

  • src

  • tests/phpunit/includes/testcase.php

    Property changes on: src
    ___________________________________________________________________
    Modified: svn:ignore
    ## -1,2 +1,3 ##
    +.htaccess
     .wp-tests-version
    -.htaccess
    +wp-config.php
     
    1010        protected $caught_deprecated = array();
    1111        protected $expected_doing_it_wrong = array();
    1212        protected $caught_doing_it_wrong = array();
     13        protected $hooks_saved = array();
    1314
    1415        /**
    1516         * @var WP_UnitTest_Factory
     
    2021                set_time_limit(0);
    2122
    2223                global $wpdb;
     24                $this->_backup_hooks();
    2325                $wpdb->suppress_errors = false;
    2426                $wpdb->show_errors = true;
    2527                $wpdb->db_connect();
     
    4143                remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
    4244                remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
    4345                remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     46                $this->_restore_hooks();
    4447        }
    4548
    4649        function clean_up_global_scope() {
     
    4952                $this->flush_cache();
    5053        }
    5154
     55        /**
     56         * Saves the action and filter-related globals so they can be restored later
     57         *
     58         * Stores $merged_filters, $wp_actions, $wp_current_filter, and $wp_filter
     59         * on a class variable so they can be restored on tearDown() using _restore_hooks()
     60         * @global array $merged_filters
     61         * @global array $wp_actions
     62         * @global array $wp_current_filter
     63         * @global array $wp_filter
     64         * @return void
     65         */
     66        protected function _backup_hooks(){
     67                global  $merged_filters, $wp_actions, $wp_current_filter, $wp_filter;
     68                //create a copy of each as an array element of hooks_saved
     69                $this->hooks_saved = array(
     70                        'merged_filters' => $merged_filters,
     71                        'wp_actions' => $wp_actions,
     72                        'wp_current_filter' => $wp_current_filter,
     73                        'wp_filter' => $wp_filter
     74                );
     75        }
     76
     77        /**
     78         * Restores the hook-related globals to their state at setUp()
     79         *
     80         * so that future tests aren't affected by hooks set during this last test
     81         *
     82         * @global array $merged_filters
     83         * @global array $wp_actions
     84         * @global array $wp_current_filter
     85         * @global array $wp_filter
     86         * @return void
     87         */
     88        protected function _restore_hooks(){
     89                global  $merged_filters, $wp_actions, $wp_current_filter, $wp_filter;
     90                extract( $this->hooks_saved, EXTR_OVERWRITE );
     91        }
    5292        function flush_cache() {
    5393                global $wp_object_cache;
    5494                $wp_object_cache->group_ops = array();