Make WordPress Core

Changeset 48997


Ignore:
Timestamp:
09/18/2020 01:48:27 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Tests: Switch Ajax tests to use the expectException() method directly, instead of the WP_UnitTestCase_Base::setExpectedException() wrapper.

This brings some consistency with other tests.

Follow-up to [48996].

See #51344.

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

Legend:

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

    r48937 r48997  
    2626
    2727                // Make the request.
    28                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     28                $this->expectException( 'WPAjaxDieStopException' );
     29                $this->expectExceptionMessage( '-1' );
    2930                $this->_handleAjax( 'wp-compression-test' );
    3031        }
     
    119120
    120121                // Make the request.
    121                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     122                $this->expectException( 'WPAjaxDieStopException' );
     123                $this->expectExceptionMessage( '-1' );
    122124                $this->_handleAjax( 'wp-compression-test' );
    123125        }
  • trunk/tests/phpunit/tests/ajax/CustomizeMenus.php

    r48937 r48997  
    5454
    5555                if ( 'administrator' !== $role ) {
    56                         // If we're not an admin, we should get a wp_die(-1).
    57                         $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     56                        // If we're not an admin, we should get a wp_die( -1 ).
     57                        $this->expectException( 'WPAjaxDieStopException' );
     58                        $this->expectExceptionMessage( '-1' );
    5859                }
    5960
     
    443444
    444445                if ( 'administrator' !== $role ) {
    445                         // If we're not an admin, we should get a wp_die(-1).
    446                         $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     446                        // If we're not an admin, we should get a wp_die( -1 ).
     447                        $this->expectException( 'WPAjaxDieStopException' );
     448                        $this->expectExceptionMessage( '-1' );
    447449                }
    448450
  • trunk/tests/phpunit/tests/ajax/DeleteComment.php

    r48937 r48997  
    138138
    139139                // Make the request.
    140                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     140                $this->expectException( 'WPAjaxDieStopException' );
     141                $this->expectExceptionMessage( '-1' );
    141142                $this->_handleAjax( 'delete-comment' );
    142143        }
     
    169170
    170171                // Make the request.
    171                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     172                $this->expectException( 'WPAjaxDieStopException' );
     173                $this->expectExceptionMessage( '-1' );
    172174                $this->_handleAjax( 'delete-comment' );
    173175        }
  • trunk/tests/phpunit/tests/ajax/DeletePlugin.php

    r48996 r48997  
    1313
    1414        public function test_missing_nonce() {
    15                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     15                $this->expectException( 'WPAjaxDieStopException' );
     16                $this->expectExceptionMessage( '-1' );
    1617                $this->_handleAjax( 'delete-plugin' );
    1718        }
  • trunk/tests/phpunit/tests/ajax/DimComment.php

    r48937 r48997  
    131131
    132132                // Make the request.
    133                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     133                $this->expectException( 'WPAjaxDieStopException' );
     134                $this->expectExceptionMessage( '-1' );
    134135                $this->_handleAjax( 'dim-comment' );
    135136        }
     
    159160
    160161                // Make the request.
    161                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     162                $this->expectException( 'WPAjaxDieStopException' );
     163                $this->expectExceptionMessage( '-1' );
    162164                $this->_handleAjax( 'dim-comment' );
    163165        }
  • trunk/tests/phpunit/tests/ajax/EditComment.php

    r48937 r48997  
    150150
    151151                // Make the request.
    152                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     152                $this->expectException( 'WPAjaxDieStopException' );
     153                $this->expectExceptionMessage( '-1' );
    153154                $this->_handleAjax( 'edit-comment' );
    154155        }
     
    178179
    179180                // Make the request.
    180                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     181                $this->expectException( 'WPAjaxDieStopException' );
     182                $this->expectExceptionMessage( '-1' );
    181183                $this->_handleAjax( 'get-comments' );
    182184        }
     
    198200
    199201                // Make the request.
    200                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     202                $this->expectException( 'WPAjaxDieStopException' );
     203                $this->expectExceptionMessage( '-1' );
    201204                $this->_handleAjax( 'edit-comment' );
    202205        }
     
    226229
    227230                // Make the request.
    228                 $this->setExpectedException( 'WPAjaxDieStopException', 'wp_update_comment_data filter fails for this comment.' );
     231                $this->expectException( 'WPAjaxDieStopException' );
     232                $this->expectExceptionMessage( 'wp_update_comment_data filter fails for this comment.' );
    229233                $this->_handleAjax( 'edit-comment' );
    230234        }
  • trunk/tests/phpunit/tests/ajax/GetComments.php

    r48937 r48997  
    9191
    9292                // Make the request.
    93                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     93                $this->expectException( 'WPAjaxDieStopException' );
     94                $this->expectExceptionMessage( '-1' );
    9495                $this->_handleAjax( 'get-comments' );
    9596        }
     
    111112
    112113                // Make the request.
    113                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     114                $this->expectException( 'WPAjaxDieStopException' );
     115                $this->expectExceptionMessage( '-1' );
    114116                $this->_handleAjax( 'get-comments' );
    115117        }
     
    131133
    132134                // Make the request.
    133                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     135                $this->expectException( 'WPAjaxDieStopException' );
     136                $this->expectExceptionMessage( '-1' );
    134137                $this->_handleAjax( 'get-comments' );
    135138        }
     
    149152
    150153                // Make the request.
    151                 $this->setExpectedException( 'WPAjaxDieStopException', '1' );
     154                $this->expectException( 'WPAjaxDieStopException' );
     155                $this->expectExceptionMessage( '1' );
    152156                $this->_handleAjax( 'get-comments' );
    153157        }
  • trunk/tests/phpunit/tests/ajax/PrivacyErasePersonalData.php

    r48100 r48997  
    332332         */
    333333        public function test_failure_with_invalid_nonce() {
    334                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     334                $this->expectException( 'WPAjaxDieStopException' );
     335                $this->expectExceptionMessage( '-1' );
    335336
    336337                $this->_make_ajax_call(
  • trunk/tests/phpunit/tests/ajax/PrivacyExportPersonalData.php

    r47122 r48997  
    293293         */
    294294        public function test_failure_with_invalid_nonce() {
    295                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     295                $this->expectException( 'WPAjaxDieStopException' );
     296                $this->expectExceptionMessage( '-1' );
    296297
    297298                $this->_make_ajax_call(
  • trunk/tests/phpunit/tests/ajax/ReplytoComment.php

    r48937 r48997  
    114114
    115115                // Make the request.
    116                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     116                $this->expectException( 'WPAjaxDieStopException' );
     117                $this->expectExceptionMessage( '-1' );
    117118                $this->_handleAjax( 'replyto-comment' );
    118119        }
     
    143144
    144145                // Make the request.
    145                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     146                $this->expectException( 'WPAjaxDieStopException' );
     147                $this->expectExceptionMessage( '-1' );
    146148                $this->_handleAjax( 'replyto-comment' );
    147149        }
     
    163165
    164166                // Make the request.
    165                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     167                $this->expectException( 'WPAjaxDieStopException' );
     168                $this->expectExceptionMessage( '-1' );
    166169                $this->_handleAjax( 'replyto-comment' );
    167170        }
     
    183186
    184187                // Make the request.
    185                 $this->setExpectedException( 'WPAjaxDieStopException', 'Error: You can’t reply to a comment on a draft post.' );
     188                $this->expectException( 'WPAjaxDieStopException' );
     189                $this->expectExceptionMessage( 'Error: You can’t reply to a comment on a draft post.' );
    186190                $this->_handleAjax( 'replyto-comment' );
    187191        }
     
    253257
    254258                // Make the request.
    255                 $this->setExpectedException( 'WPAjaxDieStopException', 'pre_comment_approved filter fails for new comment' );
     259                $this->expectException( 'WPAjaxDieStopException' );
     260                $this->expectExceptionMessage( 'pre_comment_approved filter fails for new comment.' );
    256261                $this->_handleAjax( 'replyto-comment' );
    257262        }
     
    261266         */
    262267        function _pre_comment_approved_filter( $approved, $commentdata ) {
    263                 return new WP_Error( 'comment_wrong', 'pre_comment_approved filter fails for new comment', 403 );
     268                return new WP_Error( 'comment_wrong', 'pre_comment_approved filter fails for new comment.', 403 );
    264269        }
    265270}
  • trunk/tests/phpunit/tests/ajax/TagSearch.php

    r48937 r48997  
    7575                // Make the request.
    7676                // No output, so we get a stop exception.
    77                 $this->setExpectedException( 'WPAjaxDieStopException', '' );
     77                $this->expectException( 'WPAjaxDieStopException' );
     78                $this->expectExceptionMessage( '' );
    7879                $this->_handleAjax( 'ajax-tag-search' );
    7980        }
     
    115116
    116117                // Make the request.
    117                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     118                $this->expectException( 'WPAjaxDieStopException' );
     119                $this->expectExceptionMessage( '-1' );
    118120                $this->_handleAjax( 'ajax-tag-search' );
    119121        }
     
    132134
    133135                // Make the request.
    134                 $this->setExpectedException( 'WPAjaxDieStopException', '0' );
     136                $this->expectException( 'WPAjaxDieStopException' );
     137                $this->expectExceptionMessage( '0' );
    135138                $this->_handleAjax( 'ajax-tag-search' );
    136139        }
     
    149152
    150153                // Make the request.
    151                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     154                $this->expectException( 'WPAjaxDieStopException' );
     155                $this->expectExceptionMessage( '-1' );
    152156                $this->_handleAjax( 'ajax-tag-search' );
    153157        }
  • trunk/tests/phpunit/tests/ajax/UpdatePlugin.php

    r48996 r48997  
    1313
    1414        public function test_missing_nonce() {
    15                 $this->setExpectedException( 'WPAjaxDieStopException', '-1' );
     15                $this->expectException( 'WPAjaxDieStopException' );
     16                $this->expectExceptionMessage( '-1' );
    1617                $this->_handleAjax( 'update-plugin' );
    1718        }
Note: See TracChangeset for help on using the changeset viewer.