Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (7 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/DimComment.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
    … …  
    5555        public function _test_as_admin( $comment ) {
    5656
    57                 // Reset request
    58                 $this->_clear_post_action();
    59 
    60                 // Become an administrator
     57                // Reset request.
     58                $this->_clear_post_action();
     59
     60                // Become an administrator.
    6161                $this->_setRole( 'administrator' );
    6262
    63                 // Set up a default request
     63                // Set up a default request.
    6464                $_POST['id']          = $comment->comment_ID;
    6565                $_POST['_ajax_nonce'] = wp_create_nonce( 'approve-comment_' . $comment->comment_ID );
    … …  
    6969                $_POST['_url']        = admin_url( 'edit-comments.php' );
    7070
    71                 // Save the comment status
     71                // Save the comment status.
    7272                $prev_status = wp_get_comment_status( $comment->comment_ID );
    7373
    74                 // Make the request
     74                // Make the request.
    7575                try {
    7676                        $this->_handleAjax( 'dim-comment' );
    … …  
    7979                }
    8080
    81                 // Get the response
     81                // Get the response.
    8282                $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
    8383
    84                 // Ensure everything is correct
     84                // Ensure everything is correct.
    8585                $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->comment['id'] );
    8686                $this->assertEquals( 'dim-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
    … …  
    8888                $this->assertLessThanOrEqual( time(), (int) $xml->response[0]->comment[0]->supplemental[0]->time[0] );
    8989
    90                 // Check the status
     90                // Check the status.
    9191                $current = wp_get_comment_status( $comment->comment_ID );
    9292                if ( in_array( $prev_status, array( 'unapproved', 'spam' ), true ) ) {
    … …  
    9696                }
    9797
    98                 // The total is calculated based on a page break -OR- a random number.  Let's look for both possible outcomes
     98                // The total is calculated based on a page break -OR- a random number. Let's look for both possible outcomes.
    9999                $comment_count = wp_count_comments( 0 );
    100100                $recalc_total  = $comment_count->total_comments;
    101101
    102                 // Delta is not specified, it will always be 1 lower than the request
     102                // Delta is not specified, it will always be 1 lower than the request.
    103103                $total = $_POST['_total'] - 1;
    104104
    105                 // Check for either possible total
     105                // Check for either possible total.
    106106                $this->assertTrue( in_array( (int) $xml->response[0]->comment[0]->supplemental[0]->total[0], array( $total, $recalc_total ), true ) );
    107107        }
    … …  
    116116        public function _test_as_subscriber( $comment ) {
    117117
    118                 // Reset request
    119                 $this->_clear_post_action();
    120 
    121                 // Become a subscriber
     118                // Reset request.
     119                $this->_clear_post_action();
     120
     121                // Become a subscriber.
    122122                $this->_setRole( 'subscriber' );
    123123
    124                 // Set up the $_POST request
     124                // Set up the $_POST request.
    125125                $_POST['id']          = $comment->comment_ID;
    126126                $_POST['_ajax_nonce'] = wp_create_nonce( 'approve-comment_' . $comment->comment_ID );
    … …  
    130130                $_POST['_url']        = admin_url( 'edit-comments.php' );
    131131
    132                 // Make the request
     132                // Make the request.
    133133                $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    134134                $this->_handleAjax( 'dim-comment' );
    … …  
    144144        public function _test_with_bad_nonce( $comment ) {
    145145
    146                 // Reset request
    147                 $this->_clear_post_action();
    148 
    149                 // Become a subscriber
     146                // Reset request.
     147                $this->_clear_post_action();
     148
     149                // Become a subscriber.
    150150                $this->_setRole( 'administrator' );
    151151
    152                 // Set up the $_POST request
     152                // Set up the $_POST request.
    153153                $_POST['id']          = $comment->comment_ID;
    154154                $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
    … …  
    158158                $_POST['_url']        = admin_url( 'edit-comments.php' );
    159159
    160                 // Make the request
     160                // Make the request.
    161161                $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    162162                $this->_handleAjax( 'dim-comment' );
    … …  
    171171        public function test_with_bad_id() {
    172172
    173                 // Reset request
    174                 $this->_clear_post_action();
    175 
    176                 // Become a subscriber
     173                // Reset request.
     174                $this->_clear_post_action();
     175
     176                // Become a subscriber.
    177177                $this->_setRole( 'administrator' );
    178178
    179                 // Set up the $_POST request
     179                // Set up the $_POST request.
    180180                $_POST['id']          = 12346789;
    181181                $_POST['_ajax_nonce'] = wp_create_nonce( 'dim-comment_12346789' );
    … …  
    185185                $_POST['_url']        = admin_url( 'edit-comments.php' );
    186186
    187                 // Make the request, look for a timestamp in the exception
     187                // Make the request, look for a timestamp in the exception.
    188188                try {
    189189                        $this->_handleAjax( 'dim-comment' );
    … …  
    191191                } catch ( WPAjaxDieContinueException $e ) {
    192192
    193                         // Get the response
     193                        // Get the response.
    194194                        $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
    195195
    196                         // Ensure everything is correct
     196                        // Ensure everything is correct.
    197197                        $this->assertEquals( '0', (string) $xml->response[0]->comment['id'] );
    198198                        $this->assertEquals( 'dim-comment_0', (string) $xml->response['action'] );
Note: See TracChangeset for help on using the changeset viewer.