@@ -220,4 +220,60 @@ function () {
220220 );
221221 $ feature ->after_update_feature ( 'instant-results ' , [], [ 'active ' => false ] );
222222 }
223+
224+ /**
225+ * Ensure invalid taxonomy values returned from ep_facet_include_taxonomies
226+ * are skipped and logged via _doing_it_wrong().
227+ *
228+ * @group instant-results
229+ * @since 5.3.3
230+ */
231+ public function test_invalid_taxonomy_from_facet_filter_triggers_doing_it_wrong_and_is_skipped () {
232+ $ this ->setExpectedIncorrectUsage (
233+ \ElasticPress \Feature \InstantResults \InstantResults::class . '::get_facets '
234+ );
235+
236+ add_filter ( 'doing_it_wrong_trigger_error ' , '__return_false ' );
237+
238+ $ calls = [];
239+
240+ $ listener = function ( $ function_name , $ message , $ version ) use ( &$ calls ) {
241+ $ calls [] = [
242+ 'function ' => $ function_name ,
243+ 'message ' => $ message ,
244+ 'version ' => $ version ,
245+ ];
246+ };
247+
248+ add_action ( 'doing_it_wrong_run ' , $ listener , 10 , 3 );
249+
250+ $ taxonomy_filter = function ( $ taxonomies ) {
251+ $ taxonomies ['not-a-real-taxonomy ' ] = 'not-a-real-taxonomy ' ;
252+ return $ taxonomies ;
253+ };
254+
255+ add_filter ( 'ep_facet_include_taxonomies ' , $ taxonomy_filter , 1 , 1 );
256+
257+ $ feature = \ElasticPress \Features::factory ()->get_registered_feature ( 'instant-results ' );
258+ $ facets = $ feature ->get_facets ();
259+
260+ $ this ->assertArrayNotHasKey ( 'tax-not-a-real-taxonomy ' , $ facets );
261+
262+ $ this ->assertNotEmpty ( $ calls );
263+ $ this ->assertSame ( 'ElasticPress 5.3.3 ' , $ calls [0 ]['version ' ] );
264+ $ this ->assertSame (
265+ \ElasticPress \Feature \InstantResults \InstantResults::class . '::get_facets ' ,
266+ $ calls [0 ]['function ' ]
267+ );
268+
269+ $ message = html_entity_decode ( $ calls [0 ]['message ' ] );
270+
271+ $ this ->assertStringContainsString ( 'not-a-real-taxonomy ' , $ message );
272+ $ this ->assertStringContainsString ( 'Invalid taxonomy ' , $ message );
273+ $ this ->assertStringContainsString ( 'returned via ep_facet_include_taxonomies ' , $ message );
274+
275+ remove_filter ( 'doing_it_wrong_trigger_error ' , '__return_false ' );
276+ remove_action ( 'doing_it_wrong_run ' , $ listener , 10 );
277+ remove_filter ( 'ep_facet_include_taxonomies ' , $ taxonomy_filter , 1 );
278+ }
223279}
0 commit comments