mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@35311 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -26,7 +26,10 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
|
||||
* List of ajax actions called via POST
|
||||
* @var type
|
||||
*/
|
||||
protected $_core_actions_get = array( 'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed_cache' );
|
||||
protected static $_core_actions_get = array(
|
||||
'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
|
||||
'autocomplete-user', 'dashboard-widgets', 'logged-in',
|
||||
);
|
||||
|
||||
/**
|
||||
* Saved error reporting level
|
||||
@@ -38,7 +41,7 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
|
||||
* List of ajax actions called via GET
|
||||
* @var type
|
||||
*/
|
||||
protected $_core_actions_post = array(
|
||||
protected static $_core_actions_post = array(
|
||||
'oembed_cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
|
||||
'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
|
||||
'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
|
||||
@@ -47,9 +50,31 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
|
||||
'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
|
||||
'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
|
||||
'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
|
||||
'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat',
|
||||
'wp-remove-post-lock', 'dismiss-wp-pointer', 'heartbeat', 'nopriv_heartbeat', 'get-revision-diffs',
|
||||
'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail',
|
||||
'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
|
||||
'press-this-add-category', 'crop-image', 'generate-password',
|
||||
);
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
if ( ! defined( 'DOING_AJAX' ) ) {
|
||||
define( 'DOING_AJAX', true );
|
||||
}
|
||||
|
||||
remove_action( 'admin_init', '_maybe_update_core' );
|
||||
remove_action( 'admin_init', '_maybe_update_plugins' );
|
||||
remove_action( 'admin_init', '_maybe_update_themes' );
|
||||
|
||||
// Register the core actions
|
||||
foreach ( array_merge( self::$_core_actions_get, self::$_core_actions_post ) as $action ) {
|
||||
if ( function_exists( 'wp_ajax_' . str_replace( '-', '_', $action ) ) ) {
|
||||
add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 );
|
||||
}
|
||||
}
|
||||
|
||||
parent::setUpBeforeClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the test fixture.
|
||||
* Override wp_die(), pretend to be ajax, and suppres E_WARNINGs
|
||||
@@ -57,14 +82,8 @@ abstract class WP_Ajax_UnitTestCase extends WP_UnitTestCase {
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Register the core actions
|
||||
foreach ( array_merge( $this->_core_actions_get, $this->_core_actions_post ) as $action )
|
||||
if ( function_exists( 'wp_ajax_' . str_replace( '-', '_', $action ) ) )
|
||||
add_action( 'wp_ajax_' . $action, 'wp_ajax_' . str_replace( '-', '_', $action ), 1 );
|
||||
|
||||
add_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
|
||||
if ( !defined( 'DOING_AJAX' ) )
|
||||
define( 'DOING_AJAX', true );
|
||||
|
||||
set_current_screen( 'ajax' );
|
||||
|
||||
// Clear logout cookies
|
||||
|
||||
Reference in New Issue
Block a user