Make WordPress Core

Ticket #30017: 30017.diff

File 30017.diff, 876 bytes (added by jdgrimes, 8 years ago)

Speed up the Ajax tests by calling admin_init only once

  • tests/phpunit/includes/testcase-ajax.php

     
    1717abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
    1818
    1919        /**
     20         * Whether the admin_init action has been called.
     21         *
     22         * @since 4.2.0
     23         *
     24         * @var bool
     25         */
     26        protected static $did_admin_init = false;
     27
     28        /**
    2029         * Last AJAX response.  This is set via echo -or- wp_die.
    2130         * @var type
    2231         */
     
    171180                $_REQUEST        = array_merge( $_POST, $_GET );
    172181
    173182                // Call the hooks
    174                 do_action( 'admin_init' );
     183                if ( ! self::$did_admin_init ) {
     184                        do_action( 'admin_init' );
     185                        self::$did_admin_init = true;
     186                }
     187
    175188                do_action( 'wp_ajax_' . $_REQUEST['action'], null );
    176189
    177190                // Save the output