Skip to content

Commit 46b4df4

Browse files
westonruterb1ink0
andcommitted
Fix Ajax tests
Co-authored-by: Aditya Dhade <[email protected]>
1 parent ebb2277 commit 46b4df4

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

plugins/performance-lab/tests/includes/site-health/audit-enqueued-assets/test-audit-enqueued-assets-helper.php

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,15 @@ public function test_perflab_aea_enqueued_blocking_assets_test_but_one_style_is_
284284
*/
285285
public function test_perflab_aea_enqueued_ajax_blocking_assets_test_unauthenticated_without_nonce(): void {
286286
$this->add_filter_to_mock_front_page_loopback_request();
287-
$this->expectException( WPAjaxDieStopException::class );
288-
$this->_handleAjax( 'health-check-enqueued-blocking-assets-test' );
289-
$response = json_decode( $this->_last_response, true );
290-
$this->assertArrayHasKey( 'success', $response );
291-
$this->assertFalse( $response['success'] );
287+
$exception = null;
288+
try {
289+
$this->_handleAjax( 'health-check-enqueued-blocking-assets-test' );
290+
} catch ( Exception $e ) {
291+
$exception = $e;
292+
}
293+
$this->assertInstanceOf( WPAjaxDieStopException::class, $exception );
294+
$this->assertEquals( '-1', $exception->getMessage() );
295+
$this->assertSame( '', $this->_last_response );
292296
}
293297

294298
/**
@@ -299,8 +303,14 @@ public function test_perflab_aea_enqueued_ajax_blocking_assets_test_unauthentica
299303
public function test_perflab_aea_enqueued_ajax_blocking_assets_test_unauthenticated_with_nonce(): void {
300304
$this->add_filter_to_mock_front_page_loopback_request();
301305
$_GET['_wpnonce'] = wp_create_nonce( 'health-check-site-status' );
302-
$this->expectException( WPAjaxDieContinueException::class );
303-
$this->_handleAjax( 'health-check-enqueued-blocking-assets-test' );
306+
$exception = null;
307+
try {
308+
$this->_handleAjax( 'health-check-enqueued-blocking-assets-test' );
309+
} catch ( Exception $e ) {
310+
$exception = $e;
311+
}
312+
$this->assertInstanceOf( WPAjaxDieContinueException::class, $exception );
313+
$this->assertEquals( '', $exception->getMessage() );
304314
$response = json_decode( $this->_last_response, true );
305315
$this->assertFalse( $response['success'] );
306316
}
@@ -314,8 +324,14 @@ public function test_perflab_aea_enqueued_ajax_blocking_assets_test_unauthorized
314324
$this->add_filter_to_mock_front_page_loopback_request();
315325
wp_set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );
316326
$_GET['_wpnonce'] = wp_create_nonce( 'health-check-site-status' );
317-
$this->expectException( WPAjaxDieContinueException::class );
318-
$this->_handleAjax( 'health-check-enqueued-blocking-assets-test' );
327+
$exception = null;
328+
try {
329+
$this->_handleAjax( 'health-check-enqueued-blocking-assets-test' );
330+
} catch ( Exception $e ) {
331+
$exception = $e;
332+
}
333+
$this->assertInstanceOf( WPAjaxDieContinueException::class, $exception );
334+
$this->assertEquals( '', $exception->getMessage() );
319335
$response = json_decode( $this->_last_response, true );
320336
$this->assertFalse( $response['success'] );
321337
}
@@ -329,10 +345,21 @@ public function test_perflab_aea_enqueued_ajax_blocking_assets_test_authorized()
329345
$this->add_filter_to_mock_front_page_loopback_request();
330346
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
331347
$_GET['_wpnonce'] = wp_create_nonce( 'health-check-site-status' );
332-
$this->expectException( WPAjaxDieContinueException::class );
333-
$this->_handleAjax( 'health-check-enqueued-blocking-assets-test' );
348+
$exception = null;
349+
try {
350+
$this->_handleAjax( 'health-check-enqueued-blocking-assets-test' );
351+
} catch ( Exception $e ) {
352+
$exception = $e;
353+
}
354+
$this->assertInstanceOf( WPAjaxDieContinueException::class, $exception );
355+
$this->assertEquals( '', $exception->getMessage() );
334356
$response = json_decode( $this->_last_response, true );
335357
$this->assertTrue( $response['success'] );
358+
$this->assertArrayHasKey( 'data', $response );
359+
$this->assertSameSets(
360+
array( 'label', 'status', 'badge', 'description', 'actions', 'test' ),
361+
array_keys( $response['data'] )
362+
);
336363
}
337364

338365
/**

0 commit comments

Comments
 (0)