@@ -178,13 +178,20 @@ public function data_provider_test_od_maybe_add_template_output_buffer_filter():
178
178
'expected_has_filter ' => true ,
179
179
),
180
180
'search_enabled_by_filter_using_flags ' => array (
181
- 'set_up ' => static function (): string {
181
+ 'set_up ' => function (): string {
182
182
// This is needed because otherwise no_cache_purge_post_id will be true.
183
183
self ::factory ()->post ->create ( array ( 'post_title ' => 'foo ' ) );
184
184
185
185
add_filter (
186
186
'od_can_optimize_response ' ,
187
- static function ( $ can_optimize , array $ disabled_flags ): bool {
187
+ function ( $ can_optimize , array $ disabled_flags ): bool {
188
+ $ expected_keys = array ( 'is_search ' , 'is_embed ' , 'is_preview ' , 'is_customize_preview ' , 'not_get_request ' , 'no_cache_purge_post_id ' );
189
+ $ this ->assertCount ( count ( $ expected_keys ), $ disabled_flags );
190
+ foreach ( $ expected_keys as $ key ) {
191
+ $ this ->assertArrayHasKey ( $ key , $ disabled_flags );
192
+ $ this ->assertIsBool ( $ disabled_flags [ $ key ] );
193
+ }
194
+
188
195
if ( ! $ can_optimize && $ disabled_flags ['is_search ' ] ) {
189
196
unset( $ disabled_flags ['is_search ' ] );
190
197
$ can_optimize = count ( array_filter ( $ disabled_flags ) ) === 0 ;
@@ -382,6 +389,27 @@ public function test_od_can_optimize_response( Closure $set_up, bool $expected )
382
389
$ url = $ set_up ();
383
390
$ this ->go_to ( $ url );
384
391
$ this ->assertSame ( $ expected , od_can_optimize_response () );
392
+ $ disabled_reasons = od_get_disabled_reasons ();
393
+ $ possible_keys = array (
394
+ 'is_search ' ,
395
+ 'is_embed ' ,
396
+ 'is_preview ' ,
397
+ 'is_customize_preview ' ,
398
+ 'not_get_request ' ,
399
+ 'no_cache_purge_post_id ' ,
400
+ 'filter_disabled ' ,
401
+ 'rest_api_unavailable ' ,
402
+ 'query_param_disabled ' ,
403
+ );
404
+ foreach ( $ disabled_reasons as $ key => $ reason ) {
405
+ $ this ->assertContains ( $ key , $ possible_keys );
406
+ $ this ->assertIsString ( $ reason );
407
+ }
408
+ if ( $ expected ) {
409
+ $ this ->assertCount ( 0 , $ disabled_reasons );
410
+ } else {
411
+ $ this ->assertNotCount ( 0 , $ disabled_reasons );
412
+ }
385
413
}
386
414
387
415
/**
0 commit comments