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/DeleteComment.php

    r35242 r35311  
    2020     * @var array
    2121     */
    22     protected $_comments = array();
    23 
    24     /**
    25      * Set up the test fixture
    26      */
    27     public function setUp() {
    28         parent::setUp();
    29         $post_id = self::factory()->post->create();
    30         $this->_comments = self::factory()->comment->create_post_comments( $post_id, 15 );
    31         $this->_comments = array_map( 'get_comment', $this->_comments );
     22    protected static $comments = array();
     23
     24    protected static $admin_id = 0;
     25    protected static $editor_id = 0;
     26    protected static $post;
     27    protected static $post_id;
     28    protected static $user_ids = array();
     29
     30    public static function wpSetUpBeforeClass( $factory ) {
     31        self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
     32        self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
     33
     34        self::$post_id = $factory->post->create();
     35        self::$post = get_post( self::$post_id );
     36
     37        $comment_ids = $factory->comment->create_post_comments( self::$post_id, 8 );
     38        self::$comments = array_map( 'get_comment', $comment_ids );
     39    }
     40
     41    public static function wpTearDownAfterClass() {
     42        foreach ( self::$user_ids as $user_id ) {
     43            self::delete_user( $user_id );
     44        }
     45
     46        wp_delete_post( self::$post_id, true );
     47
     48        foreach ( self::$comments as $c ) {
     49            wp_delete_comment( $c->ID, true );
     50        }
    3251    }
    3352
     
    6786        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    6887        $_POST[$action]       = 1;
    69         $_POST['_total']      = count( $this->_comments );
     88        $_POST['_total']      = count( self::$comments );
    7089        $_POST['_per_page']   = 100;
    7190        $_POST['_page']       = 1;
     
    125144        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    126145        $_POST[$action]       = 1;
    127         $_POST['_total']      = count( $this->_comments );
     146        $_POST['_total']      = count( self::$comments );
    128147        $_POST['_per_page']   = 100;
    129148        $_POST['_page']       = 1;
     
    155174        $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
    156175        $_POST[$action]       = 1;
    157         $_POST['_total']      = count( $this->_comments );
     176        $_POST['_total']      = count( self::$comments );
    158177        $_POST['_per_page']   = 100;
    159178        $_POST['_page']       = 1;
     
    184203        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_12346789' );
    185204        $_POST[$action]       = 1;
    186         $_POST['_total']      = count( $this->_comments );
     205        $_POST['_total']      = count( self::$comments );
    187206        $_POST['_per_page']   = 100;
    188207        $_POST['_page']       = 1;
     
    220239        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    221240        $_POST[$action]       = 1;
    222         $_POST['_total']      = count( $this->_comments );
     241        $_POST['_total']      = count( self::$comments );
    223242        $_POST['_per_page']   = 100;
    224243        $_POST['_page']       = 1;
     
    255274     */
    256275    public function test_ajax_comment_trash_actions_as_administrator() {
    257 
    258         // Test trash/untrash
    259         $comment = array_pop( $this->_comments );
    260         $this->_test_as_admin( $comment, 'trash' );
    261         $this->_test_as_admin( $comment, 'untrash' );
    262 
    263         // Test spam/unspam
    264         $comment = array_pop( $this->_comments );
    265         $this->_test_as_admin( $comment, 'spam' );
    266         $this->_test_as_admin( $comment, 'unspam' );
    267 
    268         // Test delete
    269         $comment = array_pop( $this->_comments );
    270         $this->_test_as_admin( $comment, 'delete' );
     276        // Test trash/untrash
     277        $this->_test_as_admin( self::$comments[0], 'trash' );
     278        $this->_test_as_admin( self::$comments[0], 'untrash' );
     279
     280        // Test spam/unspam
     281        $this->_test_as_admin( self::$comments[1], 'spam' );
     282        $this->_test_as_admin( self::$comments[1], 'unspam' );
     283
     284        // Test delete
     285        $this->_test_as_admin( self::$comments[2], 'delete' );
    271286    }
    272287
     
    276291     */
    277292    public function test_ajax_comment_trash_actions_as_subscriber() {
    278 
    279         // Test trash/untrash
    280         $comment = array_pop( $this->_comments );
    281         $this->_test_as_subscriber( $comment, 'trash' );
    282         $this->_test_as_subscriber( $comment, 'untrash' );
    283 
    284         // Test spam/unspam
    285         $comment = array_pop( $this->_comments );
    286         $this->_test_as_subscriber( $comment, 'spam' );
    287         $this->_test_as_subscriber( $comment, 'unspam' );
    288 
    289         // Test delete
    290         $comment = array_pop( $this->_comments );
    291         $this->_test_as_subscriber( $comment, 'delete' );
     293        // Test trash/untrash
     294        $this->_test_as_subscriber( self::$comments[0], 'trash' );
     295        $this->_test_as_subscriber( self::$comments[0], 'untrash' );
     296
     297        // Test spam/unspam
     298        $this->_test_as_subscriber( self::$comments[1], 'spam' );
     299        $this->_test_as_subscriber( self::$comments[1], 'unspam' );
     300
     301        // Test delete
     302        $this->_test_as_subscriber( self::$comments[2], 'delete' );
    292303    }
    293304
     
    297308     */
    298309    public function test_ajax_trash_comment_no_id() {
    299 
    300         // Test trash/untrash
    301         $comment = array_pop( $this->_comments );
    302         $this->_test_as_admin( $comment, 'trash' );
    303         $this->_test_as_admin( $comment, 'untrash' );
    304 
    305         // Test spam/unspam
    306         $comment = array_pop( $this->_comments );
    307         $this->_test_as_admin( $comment, 'spam' );
    308         $this->_test_as_admin( $comment, 'unspam' );
    309 
    310         // Test delete
    311         $comment = array_pop( $this->_comments );
    312         $this->_test_as_admin( $comment, 'delete' );
     310        // Test trash/untrash
     311        $this->_test_as_admin( self::$comments[0], 'trash' );
     312        $this->_test_as_admin( self::$comments[0], 'untrash' );
     313
     314        // Test spam/unspam
     315        $this->_test_as_admin( self::$comments[1], 'spam' );
     316        $this->_test_as_admin( self::$comments[1], 'unspam' );
     317
     318        // Test delete
     319        $this->_test_as_admin( self::$comments[2], 'delete' );
    313320    }
    314321
     
    318325     */
    319326    public function test_ajax_trash_comment_bad_nonce() {
    320 
    321         // Test trash/untrash
    322         $comment = array_pop( $this->_comments );
    323         $this->_test_with_bad_nonce( $comment, 'trash' );
    324         $this->_test_with_bad_nonce( $comment, 'untrash' );
    325 
    326         // Test spam/unspam
    327         $comment = array_pop( $this->_comments );
    328         $this->_test_with_bad_nonce( $comment, 'spam' );
    329         $this->_test_with_bad_nonce( $comment, 'unspam' );
    330 
    331         // Test delete
    332         $comment = array_pop( $this->_comments );
    333         $this->_test_with_bad_nonce( $comment, 'delete' );
     327        // Test trash/untrash
     328        $this->_test_with_bad_nonce( self::$comments[0], 'trash' );
     329        $this->_test_with_bad_nonce( self::$comments[0], 'untrash' );
     330
     331        // Test spam/unspam
     332        $this->_test_with_bad_nonce( self::$comments[1], 'spam' );
     333        $this->_test_with_bad_nonce( self::$comments[1], 'unspam' );
     334
     335        // Test delete
     336        $this->_test_with_bad_nonce( self::$comments[2], 'delete' );
    334337    }
    335338
     
    339342     */
    340343    public function test_ajax_trash_double_action() {
    341 
    342         // Test trash/untrash
    343         $comment = array_pop( $this->_comments );
    344         $this->_test_double_action( $comment, 'trash' );
    345         $this->_test_double_action( $comment, 'untrash' );
    346 
    347         // Test spam/unspam
    348         $comment = array_pop( $this->_comments );
    349         $this->_test_double_action( $comment, 'spam' );
    350         $this->_test_double_action( $comment, 'unspam' );
    351 
    352         // Test delete
    353         $comment = array_pop( $this->_comments );
    354         $this->_test_double_action( $comment, 'delete' );
     344        // Test trash/untrash
     345        $this->_test_double_action( self::$comments[0], 'trash' );
     346        $this->_test_double_action( self::$comments[0], 'untrash' );
     347
     348        // Test spam/unspam
     349        $this->_test_double_action( self::$comments[1], 'spam' );
     350        $this->_test_double_action( self::$comments[1], 'unspam' );
     351
     352        // Test delete
     353        $this->_test_double_action( self::$comments[2], 'delete' );
    355354    }
    356355}
Note: See TracChangeset for help on using the changeset viewer.