@@ -163,6 +163,8 @@ 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
167+ * @covers ::od_maybe_render_rest_api_health_check_admin_notice
166168 *
167169 * @dataProvider data_provider_test_rest_api_availability
168170 *
@@ -172,9 +174,23 @@ public function test_rest_api_availability( $mocked_response, string $expected_o
172174 $ this ->filter_rest_api_response ( $ mocked_response );
173175
174176 $ 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 );
177+ $ notice = get_echo ( 'od_render_rest_api_health_check_admin_notice_in_plugin_row ' , array ( 'optimization-detective/load.php ' ) );
178+ if ( $ expected_unavailable ) {
179+ $ this ->assertStringContainsString ( '<code> ' , $ notice );
180+ if ( is_array ( $ mocked_response ) ) {
181+ if ( isset ( $ mocked_response ['headers ' ]['content-type ' ] ) && str_contains ( join ( '' , (array ) $ mocked_response ['headers ' ]['content-type ' ] ), 'html ' ) ) {
182+ $ this ->assertStringContainsString ( '</iframe> ' , $ notice );
183+ $ this ->assertStringNotContainsString ( '</pre> ' , $ notice );
184+ } else {
185+ $ this ->assertStringContainsString ( '</pre> ' , $ notice );
186+ $ this ->assertStringNotContainsString ( '</iframe> ' , $ notice );
187+ }
188+ } else {
189+ $ this ->assertStringNotContainsString ( '</iframe> ' , $ notice );
190+ $ this ->assertStringNotContainsString ( '</pre> ' , $ notice );
191+ }
192+ } else {
193+ $ this ->assertSame ( '' , $ notice );
178194 }
179195 $ this ->assertArrayHasKey ( 'label ' , $ result );
180196 $ this ->assertArrayHasKey ( 'status ' , $ result );
@@ -417,7 +433,7 @@ static function ( $pre, array $args, string $url ) use ( $mocked_response, $obse
417433 }
418434
419435 /**
420- * Build a mock response.
436+ * Build a mock JSON response.
421437 *
422438 * @param int $status_code HTTP status code.
423439 * @param string $message HTTP status message.
@@ -431,6 +447,9 @@ protected function build_mock_response( int $status_code, string $message, array
431447 'message ' => $ message ,
432448 ),
433449 'body ' => wp_json_encode ( $ body ),
450+ 'headers ' => array (
451+ 'content-type ' => 'application/json ' ,
452+ ),
434453 );
435454 }
436455}
0 commit comments