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/tests/ajax/ReplytoComment.php

    r35242 r35311  
    2020     * @var mixed
    2121     */
    22     protected $_comment_post = null;
     22    protected static $comment_post = null;
    2323
    2424    /**
     
    2626     * @var mixed
    2727     */
    28     protected $_draft_post = null;
    29 
    30     /**
    31      * Set up the test fixture
    32      */
    33     public function setUp() {
    34         parent::setUp();
    35         $post_id = self::factory()->post->create();
    36         self::factory()->comment->create_post_comments( $post_id, 5 );
    37         $this->_comment_post = get_post( $post_id );
    38 
    39         $post_id = self::factory()->post->create( array( 'post_status' => 'draft' ) );
    40         $this->_draft_post = get_post( $post_id );
     28    protected static $draft_post = null;
     29
     30    protected static $comment_ids = array();
     31
     32    public static function wpSetUpBeforeClass( $factory ) {
     33        self::$comment_post = $factory->post->create_and_get();
     34        self::$comment_ids = $factory->comment->create_post_comments( self::$comment_post->ID, 5 );
     35        self::$draft_post = $factory->post->create_and_get( array( 'post_status' => 'draft' ) );
     36    }
     37
     38    public static function wpTearDownAfterClass() {
     39        foreach ( self::$comment_ids as $comment_id ) {
     40            wp_delete_comment( $comment_id, true );
     41        }
     42
     43        wp_delete_post( self::$comment_post->ID, true );
     44        wp_delete_post( self::$draft_post->ID, true );
    4145    }
    4246
     
    5862        // Get a comment
    5963        $comments = get_comments( array(
    60             'post_id' => $this->_comment_post->ID
     64            'post_id' => self::$comment_post->ID
    6165        ) );
    6266        $comment = array_pop( $comments );
     
    6670        $_POST['comment_ID']                  = $comment->comment_ID;
    6771        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    68         $_POST['comment_post_ID']             = $this->_comment_post->ID;
     72        $_POST['comment_post_ID']             = self::$comment_post->ID;
    6973
    7074        // Make the request
     
    102106        // Get a comment
    103107        $comments = get_comments( array(
    104         'post_id' => $this->_comment_post->ID
     108        'post_id' => self::$comment_post->ID
    105109        ) );
    106110        $comment = array_pop( $comments );
     
    110114        $_POST['comment_ID']                  = $comment->comment_ID;
    111115        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    112         $_POST['comment_post_ID']             = $this->_comment_post->ID;
     116        $_POST['comment_post_ID']             = self::$comment_post->ID;
    113117
    114118        // Make the request
     
    129133        // Get a comment
    130134        $comments = get_comments( array(
    131             'post_id' => $this->_comment_post->ID
     135            'post_id' => self::$comment_post->ID
    132136        ) );
    133137        $comment = array_pop( $comments );
     
    137141        $_POST['comment_ID']                  = $comment->comment_ID;
    138142        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    139         $_POST['comment_post_ID']             = $this->_comment_post->ID;
     143        $_POST['comment_post_ID']             = self::$comment_post->ID;
    140144
    141145        // Make the request
     
    177181        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    178182        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    179         $_POST['comment_post_ID']             = $this->_draft_post->ID;
     183        $_POST['comment_post_ID']             = self::$draft_post->ID;
    180184
    181185        // Make the request
     
    199203        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    200204        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    201         $_POST['comment_post_ID']             = $this->_comment_post->ID;
     205        $_POST['comment_post_ID']             = self::$comment_post->ID;
    202206
    203207        // Block comments from being saved, simulate a DB error
Note: See TracChangeset for help on using the changeset viewer.