Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

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

    r46586 r47122  
    22
    33/**
    4  * Admin ajax functions to be tested
     4 * Admin Ajax functions to be tested.
    55 */
    66require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    77
    88/**
    9  * Testing ajax comment functionality
     9 * Testing Ajax comment functionality.
    1010 *
    1111 * @package    WordPress
     
    6363    public function _test_as_admin( $comment, $action ) {
    6464
    65         // Reset request
    66         $this->_clear_post_action();
    67 
    68         // Become an administrator
     65        // Reset request.
     66        $this->_clear_post_action();
     67
     68        // Become an administrator.
    6969        $this->_setRole( 'administrator' );
    7070
    71         // Set up a default request
     71        // Set up a default request.
    7272        $_POST['id']          = $comment->comment_ID;
    7373        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
     
    7878        $_POST['_url']        = admin_url( 'edit-comments.php' );
    7979
    80         // Make the request
     80        // Make the request.
    8181        try {
    8282            $this->_handleAjax( 'delete-comment' );
     
    8585        }
    8686
    87         // Get the response
     87        // Get the response.
    8888        $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
    8989
    90         // Ensure everything is correct
     90        // Ensure everything is correct.
    9191        $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->comment['id'] );
    9292        $this->assertEquals( 'delete-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
     
    9494        $this->assertLessThanOrEqual( time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );
    9595
    96         // trash, spam, delete should make the total go down
     96        // 'trash', 'spam', 'delete' should make the total go down.
    9797        if ( in_array( $action, array( 'trash', 'spam', 'delete' ), true ) ) {
    9898            $total = $_POST['_total'] - 1;
    9999
    100             // unspam, untrash should make the total go up
     100            // 'unspam', 'untrash' should make the total go up.
    101101        } elseif ( in_array( $action, array( 'untrash', 'unspam' ), true ) ) {
    102102            $total = $_POST['_total'] + 1;
    103103        }
    104104
    105         // The total is calculated based on a page break -OR- a random number.  Let's look for both possible outcomes
     105        // The total is calculated based on a page break -OR- a random number. Let's look for both possible outcomes.
    106106        $comment_count = wp_count_comments( 0 );
    107107        $recalc_total  = $comment_count->total_comments;
    108108
    109         // Check for either possible total
     109        // Check for either possible total.
    110110        $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 );
    111111        $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ), $message );
     
    122122    public function _test_as_subscriber( $comment, $action ) {
    123123
    124         // Reset request
    125         $this->_clear_post_action();
    126 
    127         // Become a subscriber
     124        // Reset request.
     125        $this->_clear_post_action();
     126
     127        // Become a subscriber.
    128128        $this->_setRole( 'subscriber' );
    129129
    130         // Set up the $_POST request
     130        // Set up the $_POST request.
    131131        $_POST['id']          = $comment->comment_ID;
    132132        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
     
    137137        $_POST['_url']        = admin_url( 'edit-comments.php' );
    138138
    139         // Make the request
     139        // Make the request.
    140140        $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    141141        $this->_handleAjax( 'delete-comment' );
     
    153153    public function _test_with_bad_nonce( $comment, $action ) {
    154154
    155         // Reset request
    156         $this->_clear_post_action();
    157 
    158         // Become a subscriber
     155        // Reset request.
     156        $this->_clear_post_action();
     157
     158        // Become a subscriber.
    159159        $this->_setRole( 'administrator' );
    160160
    161         // Set up the $_POST request
     161        // Set up the $_POST request.
    162162        $_POST['id']          = $comment->comment_ID;
    163163        $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
     
    168168        $_POST['_url']        = admin_url( 'edit-comments.php' );
    169169
    170         // Make the request
     170        // Make the request.
    171171        $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    172172        $this->_handleAjax( 'delete-comment' );
     
    183183    public function _test_with_bad_id( $comment, $action ) {
    184184
    185         // Reset request
    186         $this->_clear_post_action();
    187 
    188         // Become a subscriber
     185        // Reset request.
     186        $this->_clear_post_action();
     187
     188        // Become a subscriber.
    189189        $this->_setRole( 'administrator' );
    190190
    191         // Set up the $_POST request
     191        // Set up the $_POST request.
    192192        $_POST['id']          = 12346789;
    193193        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_12346789' );
     
    198198        $_POST['_url']        = admin_url( 'edit-comments.php' );
    199199
    200         // Make the request, look for a timestamp in the exception
     200        // Make the request, look for a timestamp in the exception.
    201201        try {
    202202            $this->_handleAjax( 'delete-comment' );
     
    220220    public function _test_double_action( $comment, $action ) {
    221221
    222         // Reset request
    223         $this->_clear_post_action();
    224 
    225         // Become a subscriber
     222        // Reset request.
     223        $this->_clear_post_action();
     224
     225        // Become a subscriber.
    226226        $this->_setRole( 'administrator' );
    227227
    228         // Set up the $_POST request
     228        // Set up the $_POST request.
    229229        $_POST['id']          = $comment->comment_ID;
    230230        $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
     
    235235        $_POST['_url']        = admin_url( 'edit-comments.php' );
    236236
    237         // Make the request
     237        // Make the request.
    238238        try {
    239239            $this->_handleAjax( 'delete-comment' );
     
    243243        $this->_last_response = '';
    244244
    245         // Force delete the comment
     245        // Force delete the comment.
    246246        if ( 'delete' === $action ) {
    247247            wp_delete_comment( $comment->comment_ID, true );
    248248        }
    249249
    250         // Make the request again, look for a timestamp in the exception
     250        // Make the request again, look for a timestamp in the exception.
    251251        try {
    252252            $this->_handleAjax( 'delete-comment' );
     
    266266     */
    267267    public function test_ajax_comment_trash_actions_as_administrator() {
    268         // Test trash/untrash
     268        // Test trash/untrash.
    269269        $this->_test_as_admin( self::$comments[0], 'trash' );
    270270        $this->_test_as_admin( self::$comments[0], 'untrash' );
    271271
    272         // Test spam/unspam
     272        // Test spam/unspam.
    273273        $this->_test_as_admin( self::$comments[1], 'spam' );
    274274        $this->_test_as_admin( self::$comments[1], 'unspam' );
    275275
    276         // Test delete
     276        // Test delete.
    277277        $this->_test_as_admin( self::$comments[2], 'delete' );
    278278    }
     
    284284     */
    285285    public function test_ajax_comment_trash_actions_as_subscriber() {
    286         // Test trash/untrash
     286        // Test trash/untrash.
    287287        $this->_test_as_subscriber( self::$comments[0], 'trash' );
    288288        $this->_test_as_subscriber( self::$comments[0], 'untrash' );
    289289
    290         // Test spam/unspam
     290        // Test spam/unspam.
    291291        $this->_test_as_subscriber( self::$comments[1], 'spam' );
    292292        $this->_test_as_subscriber( self::$comments[1], 'unspam' );
    293293
    294         // Test delete
     294        // Test delete.
    295295        $this->_test_as_subscriber( self::$comments[2], 'delete' );
    296296    }
     
    302302     */
    303303    public function test_ajax_trash_comment_no_id() {
    304         // Test trash/untrash
     304        // Test trash/untrash.
    305305        $this->_test_as_admin( self::$comments[0], 'trash' );
    306306        $this->_test_as_admin( self::$comments[0], 'untrash' );
    307307
    308         // Test spam/unspam
     308        // Test spam/unspam.
    309309        $this->_test_as_admin( self::$comments[1], 'spam' );
    310310        $this->_test_as_admin( self::$comments[1], 'unspam' );
    311311
    312         // Test delete
     312        // Test delete.
    313313        $this->_test_as_admin( self::$comments[2], 'delete' );
    314314    }
     
    320320     */
    321321    public function test_ajax_trash_comment_bad_nonce() {
    322         // Test trash/untrash
     322        // Test trash/untrash.
    323323        $this->_test_with_bad_nonce( self::$comments[0], 'trash' );
    324324        $this->_test_with_bad_nonce( self::$comments[0], 'untrash' );
    325325
    326         // Test spam/unspam
     326        // Test spam/unspam.
    327327        $this->_test_with_bad_nonce( self::$comments[1], 'spam' );
    328328        $this->_test_with_bad_nonce( self::$comments[1], 'unspam' );
    329329
    330         // Test delete
     330        // Test delete.
    331331        $this->_test_with_bad_nonce( self::$comments[2], 'delete' );
    332332    }
     
    338338     */
    339339    public function test_ajax_trash_double_action() {
    340         // Test trash/untrash
     340        // Test trash/untrash.
    341341        $this->_test_double_action( self::$comments[0], 'trash' );
    342342        $this->_test_double_action( self::$comments[0], 'untrash' );
    343343
    344         // Test spam/unspam
     344        // Test spam/unspam.
    345345        $this->_test_double_action( self::$comments[1], 'spam' );
    346346        $this->_test_double_action( self::$comments[1], 'unspam' );
    347347
    348         // Test delete
     348        // Test delete.
    349349        $this->_test_double_action( self::$comments[2], 'delete' );
    350350    }
Note: See TracChangeset for help on using the changeset viewer.