@@ -518,4 +518,77 @@ public function test_maybe_get_stamp_invalid_author() {
518518 // Clean up.
519519 \wp_delete_post ( $ post_id , true );
520520 }
521+
522+ /**
523+ * Test get_activitypub_object method for home page in Actor mode.
524+ *
525+ * @covers ::get_activitypub_object
526+ */
527+ public function test_home_page_actor_mode () {
528+ \update_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_ACTOR_MODE );
529+
530+ $ actor_queries = array ();
531+
532+ // Track database queries using the 'query' filter.
533+ $ query_filter = function ( $ query ) use ( &$ actor_queries ) {
534+ if ( strpos ( $ query , 'ap_actor ' ) !== false ) {
535+ $ actor_queries [] = $ query ;
536+ }
537+ return $ query ;
538+ };
539+
540+ add_filter ( 'query ' , $ query_filter );
541+
542+ Query::get_instance ()->__destruct ();
543+ $ this ->go_to ( home_url ( '/ ' ) );
544+ $ object = Query::get_instance ()->get_activitypub_object ();
545+
546+ remove_filter ( 'query ' , $ query_filter );
547+
548+ $ message = 'Should not query Remote_Actors table for home page. ' ;
549+ if ( ! empty ( $ actor_queries ) ) {
550+ $ message .= ' Found queries: ' . wp_json_encode ( $ actor_queries );
551+ }
552+
553+ $ this ->assertNull ( $ object , 'Home page should return null, because the Blog user is disabled. ' );
554+ $ this ->assertEmpty ( $ actor_queries , $ message );
555+
556+ \delete_option ( 'activitypub_actor_mode ' );
557+ }
558+
559+ /**
560+ * Test get_activitypub_object method for home page in Actor and Blog mode.
561+ *
562+ * @covers ::get_activitypub_object
563+ */
564+ public function test_home_page_actor_and_blog_mode () {
565+ \update_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_ACTOR_AND_BLOG_MODE );
566+ $ actor_queries = array ();
567+
568+ // Track database queries using the 'query' filter.
569+ $ query_filter = function ( $ query ) use ( &$ actor_queries ) {
570+ if ( strpos ( $ query , 'ap_actor ' ) !== false ) {
571+ $ actor_queries [] = $ query ;
572+ }
573+ return $ query ;
574+ };
575+
576+ \add_filter ( 'query ' , $ query_filter );
577+
578+ Query::get_instance ()->__destruct ();
579+ $ this ->go_to ( home_url ( '/ ' ) );
580+ $ object = Query::get_instance ()->get_activitypub_object ();
581+
582+ \remove_filter ( 'query ' , $ query_filter );
583+
584+ $ message = 'Should not query Remote_Actors table for home page. ' ;
585+ if ( ! empty ( $ actor_queries ) ) {
586+ $ message .= ' Found queries: ' . wp_json_encode ( $ actor_queries );
587+ }
588+
589+ $ this ->assertNotNull ( $ object , 'Home page should return an object ' );
590+ $ this ->assertEmpty ( $ actor_queries , $ message );
591+
592+ \delete_option ( 'activitypub_actor_mode ' );
593+ }
521594}
0 commit comments