Make WordPress Core


Ignore:
Timestamp:
10/21/2015 03:17:36 AM (9 years ago)
Author:
wonderboymusic
Message:

AJAX UNIT TESTS: Have you ever wondered why these take 600 forevers to run? They all eventually call do_action( 'admin_init' ), which has _maybe_update_core, _maybe_update_plugins, and _maybe_update_themes hooked to it. REMOVE THEM, and AJAX unit tests run like the wind. Tests_Ajax_Response is still slow.

See #30017, #33968.

File:
1 edited

Legend:

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

    r35242 r35311  
    2727     * @var type
    2828     */
    29     protected $_core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed_cache' );
     29    protected static $_core_actions_get = array(
     30        'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
     31        'autocomplete-user', 'dashboard-widgets', 'logged-in',
     32    );
    3033
    3134    /**
     
    3942     * @var type
    4043     */
    41     protected $_core_actions_post = array(
     44    protected static $_core_actions_post = array(
    4245        'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
    4346        'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
     
    4851        'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
    4952        'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
    50         'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat',
     53        'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat', 'get-revision-diffs',
     54        'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail',
     55        'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
     56        'press-this-add-category', 'crop-image', 'generate-password',
    5157    );
     58
     59    public static function setUpBeforeClass() {
     60        if ( ! defined( 'DOING_AJAX' ) ) {
     61            define( 'DOING_AJAX', true );
     62        }
     63
     64        remove_action( 'admin_init', '_maybe_update_core' );
     65        remove_action( 'admin_init', '_maybe_update_plugins' );
     66        remove_action( 'admin_init', '_maybe_update_themes' );
     67
     68        // Register the core actions
     69        foreach ( array_merge( self::$_core_actions_get, self::$_core_actions_post ) as $action ) {
     70            if ( function_exists( 'wp_ajax_' . str_replace( '-', '_', $action ) ) ) {
     71                add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 );
     72            }
     73        }
     74
     75        parent::setUpBeforeClass();
     76    }
    5277
    5378    /**
     
    5883        parent::setUp();
    5984
    60         // Register the core actions
    61         foreach ( array_merge( $this->_core_actions_get, $this->_core_actions_post ) as $action )
    62             if ( function_exists( 'wp_ajax_' . str_replace( '-', '_', $action ) ) )
    63                 add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 );
    64 
    6585        add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
    66         if ( !defined( 'DOING_AJAX' ) )
    67             define( 'DOING_AJAX', true );
     86
    6887        set_current_screen( 'ajax' );
    6988
Note: See TracChangeset for help on using the changeset viewer.