Make WordPress Core

Changeset 48220


Ignore:
Timestamp:
06/30/2020 12:41:30 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve documentation for Ajax comment tests per the documentation standards.

See #49572.

Location:
trunk/tests/phpunit/tests/ajax
Files:
6 edited

Legend:

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

    r47198 r48220  
    4040
    4141    /**
    42      * Set up the test fixture
     42     * Sets up the test fixture.
    4343     */
    4444    public function setUp() {
     
    4949
    5050    /**
    51      * Test autosaving a post
    52      *
    53      * @return void
     51     * Tests autosaving a post.
    5452     */
    5553    public function test_autosave_post() {
     
    9290
    9391    /**
    94      * Test autosaving a locked post
    95      *
    96      * @return void
     92     * Tests autosaving a locked post.
    9793     */
    9894    public function test_autosave_locked_post() {
     
    145141
    146142    /**
    147      * Test with an invalid nonce
    148      *
    149      * @return void
     143     * Tests with an invalid nonce.
    150144     */
    151145    public function test_with_invalid_nonce() {
  • trunk/tests/phpunit/tests/ajax/DeleteComment.php

    r47198 r48220  
    1717
    1818    /**
    19      * List of comments
     19     * List of comments.
    2020     *
    2121     * @var array
     
    3838
    3939    /**
    40      * Clear the POST actions in between requests
     40     * Clears the POST actions in between requests.
    4141     */
    4242    protected function _clear_post_action() {
     
    5454
    5555    /**
    56      * Test as a privilged user (administrator)
    57      * Expects test to pass
    58      *
    59      * @param mixed $comment Comment object
    60      * @param string action trash, untrash, etc.
    61      * @return void
     56     * Tests as a privileged user (administrator).
     57     *
     58     * Expects test to pass.
     59     *
     60     * @param WP_Comment $comment Comment object.
     61     * @param string     $action  Action: 'trash', 'untrash', etc.
    6262     */
    6363    public function _test_as_admin( $comment, $action ) {
     
    113113
    114114    /**
    115      * Test as a non-privileged user (subscriber)
    116      * Expects test to fail
    117      *
    118      * @param mixed $comment Comment object
    119      * @param string action trash, untrash, etc.
    120      * @return void
     115     * Tests as a non-privileged user (subscriber).
     116     *
     117     * Expects test to fail.
     118     *
     119     * @param WP_Comment $comment Comment object.
     120     * @param string     $action  Action: 'trash', 'untrash', etc.
    121121     */
    122122    public function _test_as_subscriber( $comment, $action ) {
     
    144144
    145145    /**
    146      * Test with a bad nonce
    147      * Expects test to fail
    148      *
    149      * @param mixed $comment Comment object
    150      * @param string action trash, untrash, etc.
    151      * @return void
     146     * Tests with a bad nonce.
     147     *
     148     * Expects test to fail.
     149     *
     150     * @param WP_Comment $comment Comment object.
     151     * @param string     $action  Action: 'trash', 'untrash', etc.
    152152     */
    153153    public function _test_with_bad_nonce( $comment, $action ) {
     
    174174
    175175    /**
    176      * Test with a bad id
    177      * Expects test to fail
    178      *
    179      * @param mixed $comment Comment object
    180      * @param string action trash, untrash, etc.
    181      * @return void
     176     * Tests with a bad ID.
     177     *
     178     * Expects test to fail.
     179     *
     180     * @param WP_Comment $comment Comment object.
     181     * @param string     $action  Action: 'trash', 'untrash', etc.
    182182     */
    183183    public function _test_with_bad_id( $comment, $action ) {
     
    211211
    212212    /**
    213      * Test doubling the action (e.g. trash a trashed comment)
    214      * Expects test to fail
    215      *
    216      * @param mixed $comment Comment object
    217      * @param string action trash, untrash, etc.
    218      * @return void
     213     * Tests doubling the action (e.g. trash a trashed comment).
     214     *
     215     * Expects test to fail.
     216     *
     217     * @param WP_Comment $comment Comment object.
     218     * @param string     $action  Action: 'trash', 'untrash', etc.
    219219     */
    220220    public function _test_double_action( $comment, $action ) {
     
    261261
    262262    /**
    263      * Delete a comment as an administrator (expects success)
    264      *
    265      * @return void
     263     * Deletes a comment as an administrator (expects success).
    266264     */
    267265    public function test_ajax_comment_trash_actions_as_administrator() {
     
    279277
    280278    /**
    281      * Delete a comment as a subscriber (expects permission denied)
    282      *
    283      * @return void
     279     * Deletes a comment as a subscriber (expects permission denied).
    284280     */
    285281    public function test_ajax_comment_trash_actions_as_subscriber() {
     
    297293
    298294    /**
    299      * Delete a comment with no id
    300      *
    301      * @return void
     295     * Deletes a comment with no ID.
    302296     */
    303297    public function test_ajax_trash_comment_no_id() {
     
    315309
    316310    /**
    317      * Delete a comment with a bad nonce
    318      *
    319      * @return void
     311     * Deletes a comment with a bad nonce.
    320312     */
    321313    public function test_ajax_trash_comment_bad_nonce() {
     
    333325
    334326    /**
    335      * Test trashing an already trashed comment, etc.
    336      *
    337      * @return void
     327     * Tests trashing an already trashed comment, etc.
    338328     */
    339329    public function test_ajax_trash_double_action() {
  • trunk/tests/phpunit/tests/ajax/DimComment.php

    r47198 r48220  
    1717
    1818    /**
    19      * List of comments
     19     * List of comments.
    2020     *
    2121     * @var array
     
    2424
    2525    /**
    26      * Set up the test fixture
     26     * Sets up the test fixture.
    2727     */
    2828    public function setUp() {
     
    3434
    3535    /**
    36      * Clear the POST actions in between requests
     36     * Clears the POST actions in between requests.
    3737     */
    3838    protected function _clear_post_action() {
     
    4747
    4848    /**
    49      * Test as a privilged user (administrator)
    50      * Expects test to pass
    51      *
    52      * @param mixed $comment Comment object
    53      * @return void
     49     * Tests as a privileged user (administrator).
     50     *
     51     * Expects test to pass.
     52     *
     53     * @param WP_Comment $comment Comment object.
    5454     */
    5555    public function _test_as_admin( $comment ) {
     
    108108
    109109    /**
    110      * Test as a non-privileged user (subscriber)
    111      * Expects test to fail
    112      *
    113      * @param mixed $comment Comment object
    114      * @return void
     110     * Tests as a non-privileged user (subscriber).
     111     *
     112     * Expects test to fail.
     113     *
     114     * @param WP_Comment $comment Comment object.
    115115     */
    116116    public function _test_as_subscriber( $comment ) {
     
    136136
    137137    /**
    138      * Test with a bad nonce
    139      * Expects test to fail
    140      *
    141      * @param mixed $comment Comment object
    142      * @return void
     138     * Tests with a bad nonce.
     139     *
     140     * Expects test to fail.
     141     *
     142     * @param WP_Comment $comment Comment object.
    143143     */
    144144    public function _test_with_bad_nonce( $comment ) {
     
    164164
    165165    /**
    166      * Test with a bad id
    167      * Expects test to fail
    168      *
    169      * @return void
     166     * Tests with a bad ID.
     167     *
     168     * Expects test to fail.
    170169     */
    171170    public function test_with_bad_id() {
     
    205204
    206205    /**
    207      * Dim a comment as an administrator (expects success)
    208      *
    209      * @return void
     206     * Dims a comment as an administrator (expects success).
    210207     */
    211208    public function test_ajax_comment_dim_actions_as_administrator() {
     
    216213
    217214    /**
    218      * Dim a comment as a subscriber (expects permission denied)
    219      *
    220      * @return void
     215     * Dims a comment as a subscriber (expects permission denied).
    221216     */
    222217    public function test_ajax_comment_dim_actions_as_subscriber() {
     
    226221
    227222    /**
    228      * Dim a comment with no id
    229      *
    230      * @return void
     223     * Dims a comment with no ID.
    231224     */
    232225    public function test_ajax_dim_comment_no_id() {
     
    236229
    237230    /**
    238      * Dim a comment with a bad nonce
    239      *
    240      * @return void
     231     * Dims a comment with a bad nonce.
    241232     */
    242233    public function test_ajax_dim_comment_bad_nonce() {
  • trunk/tests/phpunit/tests/ajax/EditComment.php

    r48217 r48220  
    1717
    1818    /**
    19      * A post with at least one comment
     19     * A post with at least one comment.
    2020     *
    2121     * @var mixed
     
    2424
    2525    /**
    26      * Set up the test fixture
     26     * Sets up the test fixture.
    2727     */
    2828    public function setUp() {
     
    3939
    4040    /**
    41      * Get comments as a privilged user (administrator)
    42      * Expects test to pass
    43      *
    44      * @return void
     41     * Gets comments as a privileged user (administrator).
     42     *
     43     * Expects test to pass.
    4544     */
    4645    public function test_as_admin() {
     
    133132
    134133    /**
     134     * Gets comments as a non-privileged user (subscriber).
     135     *
     136     * Expects test to fail.
     137     */
     138    public function test_as_subscriber() {
     139
     140        // Become a subscriber.
     141        $this->_setRole( 'subscriber' );
     142
     143        // Get a comment.
     144        $comments = get_comments(
     145            array(
     146                'post_id' => $this->_comment_post->ID,
     147            )
     148        );
     149        $comment  = array_pop( $comments );
     150
     151        // Set up a default request.
     152        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     153        $_POST['comment_ID']                  = $comment->comment_ID;
     154        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     155
     156        // Make the request.
     157        $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     158        $this->_handleAjax( 'edit-comment' );
     159    }
     160
     161    /**
     162     * Gets comments with a bad nonce.
     163     *
     164     * Expects test to fail.
     165     */
     166    public function test_bad_nonce() {
     167
     168        // Become an administrator.
     169        $this->_setRole( 'administrator' );
     170
     171        // Get a comment.
     172        $comments = get_comments(
     173            array(
     174                'post_id' => $this->_comment_post->ID,
     175            )
     176        );
     177        $comment  = array_pop( $comments );
     178
     179        // Set up a default request.
     180        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() );
     181        $_POST['comment_ID']                  = $comment->comment_ID;
     182        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     183
     184        // Make the request.
     185        $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     186        $this->_handleAjax( 'get-comments' );
     187    }
     188
     189    /**
     190     * Gets comments for an invalid post.
     191     *
     192     * This should return valid XML.
     193     */
     194    public function test_invalid_comment() {
     195
     196        // Become an administrator.
     197        $this->_setRole( 'administrator' );
     198
     199        // Set up a default request.
     200        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     201        $_POST['comment_ID']                  = 123456789;
     202        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     203
     204        // Make the request.
     205        $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     206        $this->_handleAjax( 'edit-comment' );
     207    }
     208
     209    /**
    135210     * @ticket 39732
    136211     */
    137212    public function test_wp_update_comment_data_is_wp_error() {
    138         // Become an administrator
    139         $this->_setRole( 'administrator' );
    140 
    141         // Get a comment
    142         $comments = get_comments(
    143             array(
    144                 'post_id' => $this->_comment_post->ID,
    145             )
    146         );
    147         $comment  = array_pop( $comments );
    148 
    149         // Set up a default request
    150         $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    151         $_POST['comment_ID']                  = $comment->comment_ID;
    152         $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    153 
    154         // Simulate filter check error
     213        // Become an administrator.
     214        $this->_setRole( 'administrator' );
     215
     216        // Get a comment.
     217        $comments = get_comments(
     218            array(
     219                'post_id' => $this->_comment_post->ID,
     220            )
     221        );
     222        $comment  = array_pop( $comments );
     223
     224        // Set up a default request.
     225        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     226        $_POST['comment_ID']                  = $comment->comment_ID;
     227        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     228
     229        // Simulate filter check error.
    155230        add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 );
    156231
    157         // Make the request
     232        // Make the request.
    158233        $this->setExpectedException( 'WPAjaxDieStopException', 'wp_update_comment_data filter fails for this comment.' );
    159234        $this->_handleAjax( 'edit-comment' );
     
    161236
    162237    /**
    163      * Block comments from being updated by returning WP_Error
     238     * Blocks comments from being updated by returning WP_Error.
    164239     */
    165240    public function _wp_update_comment_data_filter( $data, $comment, $commentarr ) {
    166241        return new WP_Error( 'comment_wrong', 'wp_update_comment_data filter fails for this comment.', 500 );
    167242    }
    168 
    169     /**
    170      * Get comments as a non-privileged user (subscriber)
    171      * Expects test to fail
    172      *
    173      * @return void
    174      */
    175     public function test_as_subscriber() {
    176 
    177         // Become a subscriber.
    178         $this->_setRole( 'subscriber' );
    179 
    180         // Get a comment.
    181         $comments = get_comments(
    182             array(
    183                 'post_id' => $this->_comment_post->ID,
    184             )
    185         );
    186         $comment  = array_pop( $comments );
    187 
    188         // Set up a default request.
    189         $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    190         $_POST['comment_ID']                  = $comment->comment_ID;
    191         $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    192 
    193         // Make the request.
    194         $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    195         $this->_handleAjax( 'edit-comment' );
    196     }
    197 
    198     /**
    199      * Get comments with a bad nonce
    200      * Expects test to fail
    201      *
    202      * @return void
    203      */
    204     public function test_bad_nonce() {
    205 
    206         // Become an administrator.
    207         $this->_setRole( 'administrator' );
    208 
    209         // Get a comment.
    210         $comments = get_comments(
    211             array(
    212                 'post_id' => $this->_comment_post->ID,
    213             )
    214         );
    215         $comment  = array_pop( $comments );
    216 
    217         // Set up a default request.
    218         $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( uniqid() );
    219         $_POST['comment_ID']                  = $comment->comment_ID;
    220         $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    221 
    222         // Make the request.
    223         $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    224         $this->_handleAjax( 'get-comments' );
    225     }
    226 
    227     /**
    228      * Get comments for an invalid post
    229      * This should return valid XML
    230      *
    231      * @return void
    232      */
    233     public function test_invalid_comment() {
    234 
    235         // Become an administrator.
    236         $this->_setRole( 'administrator' );
    237 
    238         // Set up a default request.
    239         $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
    240         $_POST['comment_ID']                  = 123456789;
    241         $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
    242 
    243         // Make the request.
    244         $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
    245         $this->_handleAjax( 'edit-comment' );
    246     }
    247243}
  • trunk/tests/phpunit/tests/ajax/GetComments.php

    r47198 r48220  
    1717
    1818    /**
    19      * A post with at least one comment
     19     * A post with at least one comment.
    2020     *
    2121     * @var mixed
     
    2424
    2525    /**
    26      * A post with no comments
     26     * A post with no comments.
    2727     *
    2828     * @var mixed
     
    3939
    4040    /**
    41      * Get comments as a privilged user (administrator)
    42      * Expects test to pass
     41     * Gets comments as a privileged user (administrator).
    4342     *
    44      * @return void
     43     * Expects test to pass.
    4544     */
    4645    public function test_as_admin() {
     
    7776
    7877    /**
    79      * Get comments as a non-privileged user (subscriber)
    80      * Expects test to fail
     78     * Gets comments as a non-privileged user (subscriber).
    8179     *
    82      * @return void
     80     * Expects test to fail.
    8381     */
    8482    public function test_as_subscriber() {
     
    9896
    9997    /**
    100      * Get comments with a bad nonce
    101      * Expects test to fail
     98     * Gets comments with a bad nonce.
    10299     *
    103      * @return void
     100     * Expects test to fail.
    104101     */
    105102    public function test_bad_nonce() {
     
    119116
    120117    /**
    121      * Get comments for an invalid post
    122      * Bad post IDs are set to 0, this should return valid XML
     118     * Gets comments for an invalid post.
    123119     *
    124      * @return void
     120     * Bad post IDs are set to 0, this should return valid XML.
    125121     */
    126122    public function test_invalid_post() {
     
    140136
    141137    /**
    142      * Get comments for an invalid post
    143      * Bad post IDs are set to 0, this should return valid XML
    144      *
    145      * @return void
     138     * Gets comments for a post with no comments.
    146139     */
    147140    public function test_post_with_no_comments() {
  • trunk/tests/phpunit/tests/ajax/ReplytoComment.php

    r48115 r48220  
    1717
    1818    /**
    19      * A post with at least one comment
     19     * A post with at least one comment.
    2020     *
    2121     * @var mixed
     
    2424
    2525    /**
    26      * Draft post
     26     * Draft post.
    2727     *
    2828     * @var mixed
     
    4444
    4545    /**
    46      * Reply as a privilged user (administrator)
    47      * Expects test to pass
    48      *
    49      * @return void
     46     * Tests reply as a privileged user (administrator).
     47     *
     48     * Expects test to pass.
    5049     */
    5150    public function test_as_admin() {
     
    9190
    9291    /**
    93      * Reply as a non-privileged user (subscriber)
    94      * Expects test to fail
    95      *
    96      * @return void
     92     * Tests reply as a non-privileged user (subscriber).
     93     *
     94     * Expects test to fail.
    9795     */
    9896    public function test_as_subscriber() {
     
    121119
    122120    /**
    123      * Reply using a bad nonce
    124      * Expects test to fail
    125      *
    126      * @return void
     121     * Tests reply using a bad nonce.
     122     *
     123     * Expects test to fail.
    127124     */
    128125    public function test_bad_nonce() {
     
    151148
    152149    /**
    153      * Reply to an invalid post
    154      * Expects test to fail
    155      *
    156      * @return void
     150     * Tests reply to an invalid post.
     151     *
     152     * Expects test to fail.
    157153     */
    158154    public function test_invalid_post() {
     
    172168
    173169    /**
    174      * Reply to a draft post
    175      * Expects test to fail
    176      *
    177      * @return void
     170     * Tests reply to a draft post.
     171     *
     172     * Expects test to fail.
    178173     */
    179174    public function test_with_draft_post() {
     
    193188
    194189    /**
    195      * Reply to a post with a simulated database failure
    196      * Expects test to fail
     190     * Tests reply to a post with a simulated database failure.
     191     *
     192     * Expects test to fail.
    197193     *
    198194     * @global $wpdb
    199      * @return void
    200195     */
    201196    public function test_blocked_comment() {
     
    226221
    227222    /**
    228      * Block comments from being saved
     223     * Blocks comments from being saved.
    229224     *
    230225     * @param string $sql
     
    240235
    241236    /**
    242      * Raises WP_Error after Posted a new pre comment
     237     * Tests blocking a comment from being saved on 'pre_comment_approved'.
    243238     *
    244239     * @ticket 39730
    245      * @return void
    246240     */
    247241    public function test_pre_comments_approved() {
     
    264258
    265259    /**
    266      *  Block comments from being saved 'pre_comment_approved', by returning WP_Error
     260     * Blocks comments from being saved on 'pre_comment_approved', by returning WP_Error.
    267261     */
    268262    function _pre_comment_approved_filter( $approved, $commentdata ) {
Note: See TracChangeset for help on using the changeset viewer.