Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (5 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/EditComment.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
     
    4141    public function test_as_admin() {
    4242
    43         // Become an administrator
     43        // Become an administrator.
    4444        $this->_setRole( 'administrator' );
    4545
    46         // Get a comment
    47         $comments = get_comments(
    48             array(
    49                 'post_id' => $this->_comment_post->ID,
    50             )
    51         );
    52         $comment  = array_pop( $comments );
    53 
    54         // Set up a default request
    55         $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    56         $_POST['comment_ID']                  = $comment->comment_ID;
    57         $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    58 
    59         // Make the request
     46        // Get a comment.
     47        $comments = get_comments(
     48            array(
     49                'post_id' => $this->_comment_post->ID,
     50            )
     51        );
     52        $comment  = array_pop( $comments );
     53
     54        // Set up a default request.
     55        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     56        $_POST['comment_ID']                  = $comment->comment_ID;
     57        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     58
     59        // Make the request.
    6060        try {
    6161            $this->_handleAjax( 'edit-comment' );
     
    6464        }
    6565
    66         // Get the response
     66        // Get the response.
    6767        $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
    6868
    69         // Check the meta data
     69        // Check the meta data.
    7070        $this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] );
    7171        $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] );
    7272        $this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
    7373
    74         // Check the payload
     74        // Check the payload.
    7575        $this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data );
    7676
    77         // And supplemental is empty
     77        // And supplemental is empty.
    7878        $this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental );
    7979    }
     
    8585        global $wpdb;
    8686
    87         // Become an editor
     87        // Become an editor.
    8888        $this->_setRole( 'editor' );
    8989
    90         // Get a comment
    91         $comments = get_comments(
    92             array(
    93                 'post_id' => $this->_comment_post->ID,
    94             )
    95         );
    96         $comment  = array_pop( $comments );
    97 
    98         // Manually update the comment_post_ID, because wp_update_comment() will prevent it.
     90        // Get a comment.
     91        $comments = get_comments(
     92            array(
     93                'post_id' => $this->_comment_post->ID,
     94            )
     95        );
     96        $comment  = array_pop( $comments );
     97
     98        // Manually update the comment_post_ID, because wp_update_comment() will prevent it..
    9999        $wpdb->update( $wpdb->comments, array( 'comment_post_ID' => 0 ), array( 'comment_ID' => $comment->comment_ID ) );
    100100        clean_comment_cache( $comment->comment_ID );
    101101
    102         // Set up a default request
    103         $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    104         $_POST['comment_ID']                  = $comment->comment_ID;
    105         $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    106 
    107         // Make the request
     102        // Set up a default request.
     103        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     104        $_POST['comment_ID']                  = $comment->comment_ID;
     105        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     106
     107        // Make the request.
    108108        try {
    109109            $this->_handleAjax( 'edit-comment' );
     
    112112        }
    113113
    114         // Get the response
     114        // Get the response.
    115115        $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
    116116
    117         // Check the meta data
     117        // Check the meta data.
    118118        $this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] );
    119119        $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] );
    120120        $this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
    121121
    122         // Check the payload
     122        // Check the payload.
    123123        $this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data );
    124124
    125         // And supplemental is empty
     125        // And supplemental is empty.
    126126        $this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental );
    127127    }
     
    135135    public function test_as_subscriber() {
    136136
    137         // Become an administrator
     137        // Become a subscriber.
    138138        $this->_setRole( 'subscriber' );
    139139
    140         // Get a comment
    141         $comments = get_comments(
    142             array(
    143                 'post_id' => $this->_comment_post->ID,
    144             )
    145         );
    146         $comment  = array_pop( $comments );
    147 
    148         // Set up a default request
    149         $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    150         $_POST['comment_ID']                  = $comment->comment_ID;
    151         $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    152 
    153         // Make the request
     140        // Get a comment.
     141        $comments = get_comments(
     142            array(
     143                'post_id' => $this->_comment_post->ID,
     144            )
     145        );
     146        $comment  = array_pop( $comments );
     147
     148        // Set up a default request.
     149        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     150        $_POST['comment_ID']                  = $comment->comment_ID;
     151        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     152
     153        // Make the request.
    154154        $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    155155        $this->_handleAjax( 'edit-comment' );
     
    164164    public function test_bad_nonce() {
    165165
    166         // Become an administrator
     166        // Become an administrator.
    167167        $this->_setRole( 'administrator' );
    168168
    169         // Get a comment
    170         $comments = get_comments(
    171             array(
    172                 'post_id' => $this->_comment_post->ID,
    173             )
    174         );
    175         $comment  = array_pop( $comments );
    176 
    177         // Set up a default request
     169        // Get a comment.
     170        $comments = get_comments(
     171            array(
     172                'post_id' => $this->_comment_post->ID,
     173            )
     174        );
     175        $comment  = array_pop( $comments );
     176
     177        // Set up a default request.
    178178        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() );
    179179        $_POST['comment_ID']                  = $comment->comment_ID;
    180180        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    181181
    182         // Make the request
     182        // Make the request.
    183183        $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    184184        $this->_handleAjax( 'get-comments' );
     
    193193    public function test_invalid_comment() {
    194194
    195         // Become an administrator
     195        // Become an administrator.
    196196        $this->_setRole( 'administrator' );
    197197
    198         // Set up a default request
     198        // Set up a default request.
    199199        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    200200        $_POST['comment_ID']                  = 123456789;
    201201        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    202202
    203         // Make the request
     203        // Make the request.
    204204        $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    205205        $this->_handleAjax( 'edit-comment' );
Note: See TracChangeset for help on using the changeset viewer.