Skip to content

Commit 3d01dcf

Browse files
aristathclaude
andcommitted
Fix AJAX tests to catch WPAjaxDieContinueException
The tests were catching WPAjaxDieStopException but wp_send_json_error() actually throws WPAjaxDieContinueException. Fixed in: - test-class-ajax-security-base.php (2 occurrences) - test-class-ajax-security-aioseo.php (1 occurrence) - test-class-ajax-security-yoast.php (1 occurrence) This fixes the 4 test errors: - Ajax_Security_Base_Test::test_verify_nonce_or_fail_invalid - Ajax_Security_Base_Test::test_verify_capability_or_fail_non_admin - Ajax_Security_AIOSEO_Test::test_verify_aioseo_active_or_fail_not_active - Ajax_Security_Yoast_Test::test_verify_yoast_active_or_fail_not_active 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 80ad98d commit 3d01dcf

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

tests/phpunit/traits/test-class-ajax-security-aioseo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function test_verify_aioseo_active_or_fail_not_active() {
7272
// WP_Ajax_UnitTestCase allows us to test AJAX methods that call wp_send_json_error().
7373
try {
7474
$this->mock_class->public_verify_aioseo_active_or_fail();
75-
$this->fail( 'Expected WPAjaxDieStopException was not thrown' );
76-
} catch ( \WPAjaxDieStopException $e ) {
75+
$this->fail( 'Expected WPAjaxDieContinueException was not thrown' );
76+
} catch ( \WPAjaxDieContinueException $e ) {
7777
// Get the response.
7878
$response = json_decode( $this->_last_response, true );
7979
$this->assertFalse( $response['success'] );

tests/phpunit/traits/test-class-ajax-security-base.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public function test_verify_nonce_or_fail_invalid() {
105105
// WP_Ajax_UnitTestCase allows us to test AJAX methods that call wp_send_json_error().
106106
try {
107107
$this->mock_class->public_verify_nonce_or_fail();
108-
$this->fail( 'Expected WPAjaxDieStopException was not thrown' );
109-
} catch ( \WPAjaxDieStopException $e ) {
108+
$this->fail( 'Expected WPAjaxDieContinueException was not thrown' );
109+
} catch ( \WPAjaxDieContinueException $e ) {
110110
// Get the response.
111111
$response = json_decode( $this->_last_response, true );
112112
$this->assertFalse( $response['success'] );
@@ -151,8 +151,8 @@ public function test_verify_capability_or_fail_non_admin() {
151151
// WP_Ajax_UnitTestCase allows us to test AJAX methods that call wp_send_json_error().
152152
try {
153153
$this->mock_class->public_verify_capability_or_fail();
154-
$this->fail( 'Expected WPAjaxDieStopException was not thrown' );
155-
} catch ( \WPAjaxDieStopException $e ) {
154+
$this->fail( 'Expected WPAjaxDieContinueException was not thrown' );
155+
} catch ( \WPAjaxDieContinueException $e ) {
156156
// Get the response.
157157
$response = json_decode( $this->_last_response, true );
158158
$this->assertFalse( $response['success'] );

tests/phpunit/traits/test-class-ajax-security-yoast.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function test_verify_yoast_active_or_fail_not_active() {
7272
// WP_Ajax_UnitTestCase allows us to test AJAX methods that call wp_send_json_error().
7373
try {
7474
$this->mock_class->public_verify_yoast_active_or_fail();
75-
$this->fail( 'Expected WPAjaxDieStopException was not thrown' );
76-
} catch ( \WPAjaxDieStopException $e ) {
75+
$this->fail( 'Expected WPAjaxDieContinueException was not thrown' );
76+
} catch ( \WPAjaxDieContinueException $e ) {
7777
// Get the response.
7878
$response = json_decode( $this->_last_response, true );
7979
$this->assertFalse( $response['success'] );

0 commit comments

Comments
 (0)