@@ -163,6 +163,7 @@ public function data_provider_test_rest_api_availability(): array {
163163 * @covers ::od_compose_site_health_result
164164 * @covers ::od_get_rest_api_health_check_response
165165 * @covers ::od_is_rest_api_unavailable
166+ * @covers ::od_render_rest_api_health_check_admin_notice_in_plugin_row
166167 *
167168 * @dataProvider data_provider_test_rest_api_availability
168169 *
@@ -172,9 +173,23 @@ public function test_rest_api_availability( $mocked_response, string $expected_o
172173 $ this ->filter_rest_api_response ( $ mocked_response );
173174
174175 $ result = od_test_rest_api_availability ();
175- if ( 'nginx_forbidden ' === $ this ->dataName () ) {
176- $ notice = get_echo ( 'od_render_rest_api_health_check_admin_notice_in_plugin_row ' , array ( 'optimization-detective/load.php ' ) );
177- $ this ->assertStringContainsString ( '</iframe> ' , $ notice );
176+ $ notice = get_echo ( 'od_render_rest_api_health_check_admin_notice_in_plugin_row ' , array ( 'optimization-detective/load.php ' ) );
177+ if ( $ expected_unavailable ) {
178+ $ this ->assertStringContainsString ( '<code> ' , $ notice );
179+ if ( is_array ( $ mocked_response ) ) {
180+ if ( isset ( $ mocked_response ['headers ' ]['content-type ' ] ) && str_contains ( join ( '' , (array ) $ mocked_response ['headers ' ]['content-type ' ] ), 'html ' ) ) {
181+ $ this ->assertStringContainsString ( '</iframe> ' , $ notice );
182+ $ this ->assertStringNotContainsString ( '</pre> ' , $ notice );
183+ } else {
184+ $ this ->assertStringContainsString ( '</pre> ' , $ notice );
185+ $ this ->assertStringNotContainsString ( '</iframe> ' , $ notice );
186+ }
187+ } else {
188+ $ this ->assertStringNotContainsString ( '</iframe> ' , $ notice );
189+ $ this ->assertStringNotContainsString ( '</pre> ' , $ notice );
190+ }
191+ } else {
192+ $ this ->assertSame ( '' , $ notice );
178193 }
179194 $ this ->assertArrayHasKey ( 'label ' , $ result );
180195 $ this ->assertArrayHasKey ( 'status ' , $ result );
@@ -417,7 +432,7 @@ static function ( $pre, array $args, string $url ) use ( $mocked_response, $obse
417432 }
418433
419434 /**
420- * Build a mock response.
435+ * Build a mock JSON response.
421436 *
422437 * @param int $status_code HTTP status code.
423438 * @param string $message HTTP status message.
@@ -431,6 +446,9 @@ protected function build_mock_response( int $status_code, string $message, array
431446 'message ' => $ message ,
432447 ),
433448 'body ' => wp_json_encode ( $ body ),
449+ 'headers ' => array (
450+ 'content-type ' => 'application/json ' ,
451+ ),
434452 );
435453 }
436454}
0 commit comments