Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/DeleteComment.php

    r42342 r42343  
    1818    /**
    1919     * List of comments
     20     *
    2021     * @var array
    2122     */
     
    2425    /**
    2526     * ID of a post.
     27     *
    2628     * @var int
    2729     */
     
    3133        self::$post_id = $factory->post->create();
    3234
    33         $comment_ids = $factory->comment->create_post_comments( self::$post_id, 8 );
     35        $comment_ids    = $factory->comment->create_post_comments( self::$post_id, 8 );
    3436        self::$comments = array_map( 'get_comment', $comment_ids );
    3537    }
     
    3941     */
    4042    protected function _clear_post_action() {
    41         unset($_POST['trash']);
    42         unset($_POST['untrash']);
    43         unset($_POST['spam']);
    44         unset($_POST['unspam']);
    45         unset($_POST['delete']);
     43        unset( $_POST['trash'] );
     44        unset( $_POST['untrash'] );
     45        unset( $_POST['spam'] );
     46        unset( $_POST['unspam'] );
     47        unset( $_POST['delete'] );
    4648        $this->_last_response = '';
    4749    }
     
    5456     * Test as a privilged user (administrator)
    5557     * Expects test to pass
     58     *
    5659     * @param mixed $comment Comment object
    5760     * @param string action trash, untrash, etc.
     
    6972        $_POST['id']          = $comment->comment_ID;
    7073        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    71         $_POST[$action]       = 1;
     74        $_POST[ $action ]     = 1;
    7275        $_POST['_total']      = count( self::$comments );
    7376        $_POST['_per_page']   = 100;
     
    9598            $total = $_POST['_total'] - 1;
    9699
    97         // unspam, untrash should make the total go up
     100            // unspam, untrash should make the total go up
    98101        } elseif ( in_array( $action, array( 'untrash', 'unspam' ) ) ) {
    99102            $total = $_POST['_total'] + 1;
     
    102105        // The total is calculated based on a page break -OR- a random number.  Let's look for both possible outcomes
    103106        $comment_count = wp_count_comments( 0 );
    104         $recalc_total = $comment_count->total_comments;
     107        $recalc_total  = $comment_count->total_comments;
    105108
    106109        // Check for either possible total
    107         $message = sprintf( 'returned value: %1$d $total: %2$d  $recalc_total: %3$d', (int)  $xml->response[0]->comment[0]->supplemental[0]->total[0], $total, $recalc_total );
    108         $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0] , array( $total, $recalc_total ) ), $message );
     110        $message = sprintf( 'returned value: %1$d $total: %2$d  $recalc_total: %3$d', (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], $total, $recalc_total );
     111        $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ) ), $message );
    109112    }
    110113
     
    112115     * Test as a non-privileged user (subscriber)
    113116     * Expects test to fail
     117     *
    114118     * @param mixed $comment Comment object
    115119     * @param string action trash, untrash, etc.
     
    127131        $_POST['id']          = $comment->comment_ID;
    128132        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    129         $_POST[$action]       = 1;
     133        $_POST[ $action ]     = 1;
    130134        $_POST['_total']      = count( self::$comments );
    131135        $_POST['_per_page']   = 100;
     
    142146     * Test with a bad nonce
    143147     * Expects test to fail
     148     *
    144149     * @param mixed $comment Comment object
    145150     * @param string action trash, untrash, etc.
     
    157162        $_POST['id']          = $comment->comment_ID;
    158163        $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
    159         $_POST[$action]       = 1;
     164        $_POST[ $action ]     = 1;
    160165        $_POST['_total']      = count( self::$comments );
    161166        $_POST['_per_page']   = 100;
     
    171176     * Test with a bad id
    172177     * Expects test to fail
     178     *
    173179     * @param mixed $comment Comment object
    174180     * @param string action trash, untrash, etc.
     
    186192        $_POST['id']          = 12346789;
    187193        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_12346789' );
    188         $_POST[$action]       = 1;
     194        $_POST[ $action ]     = 1;
    189195        $_POST['_total']      = count( self::$comments );
    190196        $_POST['_per_page']   = 100;
     
    207213     * Test doubling the action (e.g. trash a trashed comment)
    208214     * Expects test to fail
     215     *
    209216     * @param mixed $comment Comment object
    210217     * @param string action trash, untrash, etc.
     
    222229        $_POST['id']          = $comment->comment_ID;
    223230        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    224         $_POST[$action]       = 1;
     231        $_POST[ $action ]     = 1;
    225232        $_POST['_total']      = count( self::$comments );
    226233        $_POST['_per_page']   = 100;
     
    255262    /**
    256263     * Delete a comment as an administrator (expects success)
     264     *
    257265     * @return void
    258266     */
     
    272280    /**
    273281     * Delete a comment as a subscriber (expects permission denied)
     282     *
    274283     * @return void
    275284     */
     
    289298    /**
    290299     * Delete a comment with no id
     300     *
    291301     * @return void
    292302     */
     
    306316    /**
    307317     * Delete a comment with a bad nonce
     318     *
    308319     * @return void
    309320     */
     
    323334    /**
    324335     * Test trashing an already trashed comment, etc.
     336     *
    325337     * @return void
    326338     */
Note: See TracChangeset for help on using the changeset viewer.