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. git-svn-id: https://develop.svn.wordpress.org/trunk@48997 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d46af0956d
commit
5164bba5e2
@ -25,7 +25,8 @@ class Tests_Ajax_CompressionTest extends WP_Ajax_UnitTestCase {
|
|||||||
$_GET['test'] = 1;
|
$_GET['test'] = 1;
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'wp-compression-test' );
|
$this->_handleAjax( 'wp-compression-test' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +119,8 @@ class Tests_Ajax_CompressionTest extends WP_Ajax_UnitTestCase {
|
|||||||
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'unknown';
|
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'unknown';
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'wp-compression-test' );
|
$this->_handleAjax( 'wp-compression-test' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +53,9 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase {
|
|||||||
function test_ajax_load_available_items_cap_check( $role, $expected_results ) {
|
function test_ajax_load_available_items_cap_check( $role, $expected_results ) {
|
||||||
|
|
||||||
if ( 'administrator' !== $role ) {
|
if ( 'administrator' !== $role ) {
|
||||||
// If we're not an admin, we should get a wp_die(-1).
|
// If we're not an admin, we should get a wp_die( -1 ).
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) );
|
wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) );
|
||||||
@ -442,8 +443,9 @@ class Tests_Ajax_CustomizeMenus extends WP_Ajax_UnitTestCase {
|
|||||||
function test_ajax_search_available_items_caps_check( $role, $expected_results ) {
|
function test_ajax_search_available_items_caps_check( $role, $expected_results ) {
|
||||||
|
|
||||||
if ( 'administrator' !== $role ) {
|
if ( 'administrator' !== $role ) {
|
||||||
// If we're not an admin, we should get a wp_die(-1).
|
// If we're not an admin, we should get a wp_die( -1 ).
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) );
|
wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) );
|
||||||
|
@ -137,7 +137,8 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['_url'] = admin_url( 'edit-comments.php' );
|
$_POST['_url'] = admin_url( 'edit-comments.php' );
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'delete-comment' );
|
$this->_handleAjax( 'delete-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +169,8 @@ class Tests_Ajax_DeleteComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['_url'] = admin_url( 'edit-comments.php' );
|
$_POST['_url'] = admin_url( 'edit-comments.php' );
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'delete-comment' );
|
$this->_handleAjax( 'delete-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
|
|||||||
class Tests_Ajax_Delete_Plugin extends WP_Ajax_UnitTestCase {
|
class Tests_Ajax_Delete_Plugin extends WP_Ajax_UnitTestCase {
|
||||||
|
|
||||||
public function test_missing_nonce() {
|
public function test_missing_nonce() {
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'delete-plugin' );
|
$this->_handleAjax( 'delete-plugin' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,8 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['_url'] = admin_url( 'edit-comments.php' );
|
$_POST['_url'] = admin_url( 'edit-comments.php' );
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'dim-comment' );
|
$this->_handleAjax( 'dim-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +159,8 @@ class Tests_Ajax_DimComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['_url'] = admin_url( 'edit-comments.php' );
|
$_POST['_url'] = admin_url( 'edit-comments.php' );
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'dim-comment' );
|
$this->_handleAjax( 'dim-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,8 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
|
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'edit-comment' );
|
$this->_handleAjax( 'edit-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +178,8 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
|
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'get-comments' );
|
$this->_handleAjax( 'get-comments' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +199,8 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
|
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'edit-comment' );
|
$this->_handleAjax( 'edit-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +228,8 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
|
|||||||
add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 );
|
add_filter( 'wp_update_comment_data', array( $this, '_wp_update_comment_data_filter' ), 10, 3 );
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', 'wp_update_comment_data filter fails for this comment.' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( 'wp_update_comment_data filter fails for this comment.' );
|
||||||
$this->_handleAjax( 'edit-comment' );
|
$this->_handleAjax( 'edit-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,8 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['p'] = self::$comment_post->ID;
|
$_POST['p'] = self::$comment_post->ID;
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'get-comments' );
|
$this->_handleAjax( 'get-comments' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,8 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['p'] = self::$comment_post->ID;
|
$_POST['p'] = self::$comment_post->ID;
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'get-comments' );
|
$this->_handleAjax( 'get-comments' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +132,8 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['p'] = 'b0rk';
|
$_POST['p'] = 'b0rk';
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'get-comments' );
|
$this->_handleAjax( 'get-comments' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +151,8 @@ class Tests_Ajax_GetComments extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['p'] = self::$no_comment_post->ID;
|
$_POST['p'] = self::$no_comment_post->ID;
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '1' );
|
||||||
$this->_handleAjax( 'get-comments' );
|
$this->_handleAjax( 'get-comments' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,8 @@ class Tests_Ajax_PrivacyErasePersonalData extends WP_Ajax_UnitTestCase {
|
|||||||
* @since 5.2.0
|
* @since 5.2.0
|
||||||
*/
|
*/
|
||||||
public function test_failure_with_invalid_nonce() {
|
public function test_failure_with_invalid_nonce() {
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
|
|
||||||
$this->_make_ajax_call(
|
$this->_make_ajax_call(
|
||||||
array(
|
array(
|
||||||
|
@ -292,7 +292,8 @@ class Tests_Ajax_PrivacyExportPersonalData extends WP_Ajax_UnitTestCase {
|
|||||||
* @since 5.2.0
|
* @since 5.2.0
|
||||||
*/
|
*/
|
||||||
public function test_failure_with_invalid_nonce() {
|
public function test_failure_with_invalid_nonce() {
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
|
|
||||||
$this->_make_ajax_call(
|
$this->_make_ajax_call(
|
||||||
array(
|
array(
|
||||||
|
@ -113,7 +113,8 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['comment_post_ID'] = self::$comment_post->ID;
|
$_POST['comment_post_ID'] = self::$comment_post->ID;
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'replyto-comment' );
|
$this->_handleAjax( 'replyto-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +143,8 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['comment_post_ID'] = self::$comment_post->ID;
|
$_POST['comment_post_ID'] = self::$comment_post->ID;
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'replyto-comment' );
|
$this->_handleAjax( 'replyto-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +164,8 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['comment_post_ID'] = 123456789;
|
$_POST['comment_post_ID'] = 123456789;
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'replyto-comment' );
|
$this->_handleAjax( 'replyto-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +185,8 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
|
|||||||
$_POST['comment_post_ID'] = self::$draft_post->ID;
|
$_POST['comment_post_ID'] = self::$draft_post->ID;
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', 'Error: You can’t reply to a comment on a draft post.' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( 'Error: You can’t reply to a comment on a draft post.' );
|
||||||
$this->_handleAjax( 'replyto-comment' );
|
$this->_handleAjax( 'replyto-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +256,8 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
|
|||||||
add_filter( 'pre_comment_approved', array( $this, '_pre_comment_approved_filter' ), 10, 2 );
|
add_filter( 'pre_comment_approved', array( $this, '_pre_comment_approved_filter' ), 10, 2 );
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', 'pre_comment_approved filter fails for new comment' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( 'pre_comment_approved filter fails for new comment.' );
|
||||||
$this->_handleAjax( 'replyto-comment' );
|
$this->_handleAjax( 'replyto-comment' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,6 +265,6 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
|
|||||||
* Blocks comments from being saved on 'pre_comment_approved', by returning WP_Error.
|
* Blocks comments from being saved on 'pre_comment_approved', by returning WP_Error.
|
||||||
*/
|
*/
|
||||||
function _pre_comment_approved_filter( $approved, $commentdata ) {
|
function _pre_comment_approved_filter( $approved, $commentdata ) {
|
||||||
return new WP_Error( 'comment_wrong', 'pre_comment_approved filter fails for new comment', 403 );
|
return new WP_Error( 'comment_wrong', 'pre_comment_approved filter fails for new comment.', 403 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,8 @@ class Tests_Ajax_TagSearch extends WP_Ajax_UnitTestCase {
|
|||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
// No output, so we get a stop exception.
|
// No output, so we get a stop exception.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '' );
|
||||||
$this->_handleAjax( 'ajax-tag-search' );
|
$this->_handleAjax( 'ajax-tag-search' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +115,8 @@ class Tests_Ajax_TagSearch extends WP_Ajax_UnitTestCase {
|
|||||||
$_GET['q'] = 'chat';
|
$_GET['q'] = 'chat';
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'ajax-tag-search' );
|
$this->_handleAjax( 'ajax-tag-search' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +133,8 @@ class Tests_Ajax_TagSearch extends WP_Ajax_UnitTestCase {
|
|||||||
$_GET['q'] = 'chat';
|
$_GET['q'] = 'chat';
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '0' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '0' );
|
||||||
$this->_handleAjax( 'ajax-tag-search' );
|
$this->_handleAjax( 'ajax-tag-search' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +151,8 @@ class Tests_Ajax_TagSearch extends WP_Ajax_UnitTestCase {
|
|||||||
$_GET['q'] = 'chat';
|
$_GET['q'] = 'chat';
|
||||||
|
|
||||||
// Make the request.
|
// Make the request.
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'ajax-tag-search' );
|
$this->_handleAjax( 'ajax-tag-search' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
|
|||||||
class Tests_Ajax_Update_Plugin extends WP_Ajax_UnitTestCase {
|
class Tests_Ajax_Update_Plugin extends WP_Ajax_UnitTestCase {
|
||||||
|
|
||||||
public function test_missing_nonce() {
|
public function test_missing_nonce() {
|
||||||
$this->setExpectedException( 'WPAjaxDieStopException', '-1' );
|
$this->expectException( 'WPAjaxDieStopException' );
|
||||||
|
$this->expectExceptionMessage( '-1' );
|
||||||
$this->_handleAjax( 'update-plugin' );
|
$this->_handleAjax( 'update-plugin' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user