@@ -140,14 +140,14 @@ public function test_get_items_pagination() {
140140 $ this ->assertStringContainsString ( 'page=1 ' , $ data ['prev ' ] );
141141 $ this ->assertStringContainsString ( 'page=3 ' , $ data ['next ' ] );
142142
143- // Empty collection.
143+ // Empty collection - with the new behavior, even empty collections have pagination links .
144144 $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/1/outbox ' );
145145 $ request ->set_param ( 'per_page ' , 3 );
146146 $ response = \rest_get_server ()->dispatch ( $ request );
147147 $ data = $ response ->get_data ();
148148
149- $ this ->assertArrayNotHasKey ( 'first ' , $ data );
150- $ this ->assertArrayNotHasKey ( 'last ' , $ data );
149+ $ this ->assertArrayHasKey ( 'first ' , $ data );
150+ $ this ->assertArrayHasKey ( 'last ' , $ data );
151151 }
152152
153153 /**
@@ -164,9 +164,11 @@ public function test_get_items_response_structure() {
164164 $ this ->assertArrayHasKey ( 'id ' , $ data );
165165 $ this ->assertArrayHasKey ( 'type ' , $ data );
166166 $ this ->assertArrayHasKey ( 'totalItems ' , $ data );
167- $ this ->assertArrayHasKey ( 'orderedItems ' , $ data );
167+ // Collection (without page param) should not have orderedItems, only links to pages.
168+ $ this ->assertArrayNotHasKey ( 'orderedItems ' , $ data );
169+ $ this ->assertArrayHasKey ( 'first ' , $ data );
170+ $ this ->assertArrayHasKey ( 'last ' , $ data );
168171 $ this ->assertEquals ( 'OrderedCollection ' , $ data ['type ' ] );
169- $ this ->assertIsArray ( $ data ['orderedItems ' ] );
170172
171173 $ headers = $ response ->get_headers ();
172174 $ this ->assertEquals ( 'application/activity+json; charset= ' . \get_option ( 'blog_charset ' ), $ headers ['Content-Type ' ] );
@@ -345,24 +347,34 @@ public function test_get_items_activity_type( $type, $activity, $allowed ) {
345347
346348 // Test as logged-out user.
347349 \wp_set_current_user ( 0 );
348- $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . $ user_id . '/outbox ' );
349- $ response = \rest_get_server ()->dispatch ( $ request );
350- $ data = $ response ->get_data ();
351-
352- $ this ->assertEquals ( 200 , $ response ->get_status () );
353- $ activity_types = \wp_list_pluck ( $ data ['orderedItems ' ], 'type ' );
350+ $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . $ user_id . '/outbox ' );
354351
355352 if ( $ allowed ) {
353+ // For allowed activities, request a page to verify they appear in orderedItems.
354+ $ request ->set_param ( 'page ' , 1 ); // Need to request a page to get orderedItems.
355+ $ request ->set_param ( 'per_page ' , 10 ); // Need per_page for pagination calculation.
356+ $ response = \rest_get_server ()->dispatch ( $ request );
357+ $ data = $ response ->get_data ();
358+
359+ $ this ->assertEquals ( 200 , $ response ->get_status () );
360+ $ activity_types = \wp_list_pluck ( $ data ['orderedItems ' ], 'type ' );
356361 $ this ->assertContains ( $ type , $ activity_types , sprintf ( 'Activity type "%s" should be visible to logged-out users. ' , $ type ) );
357362 } else {
358- $ this ->assertNotContains ( $ type , $ activity_types , sprintf ( 'Activity type "%s" should not be visible to logged-out users. ' , $ type ) );
363+ // For disallowed activities, check the collection without pagination to verify totalItems is 0.
364+ $ response = \rest_get_server ()->dispatch ( $ request );
365+ $ data = $ response ->get_data ();
366+
367+ $ this ->assertEquals ( 200 , $ response ->get_status () );
368+ $ this ->assertEquals ( 0 , $ data ['totalItems ' ], sprintf ( 'Activity type "%s" should not be visible to logged-out users (totalItems should be 0). ' , $ type ) );
359369 }
360370
361371 // Test as logged-in user with activitypub capability.
362372 \wp_set_current_user ( $ user_id );
363373 $ this ->assertTrue ( \current_user_can ( 'activitypub ' ) );
364374
365- $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . $ user_id . '/outbox ' );
375+ $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . $ user_id . '/outbox ' );
376+ $ request ->set_param ( 'page ' , 1 ); // Need to request a page to get orderedItems.
377+ $ request ->set_param ( 'per_page ' , 10 ); // Need per_page for pagination calculation.
366378 $ response = \rest_get_server ()->dispatch ( $ request );
367379 $ data = $ response ->get_data ();
368380
@@ -456,26 +468,47 @@ public function test_get_items_content_visibility( $visibility, $public_visible,
456468
457469 // Test as logged-out user.
458470 \wp_set_current_user ( 0 );
459- $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . $ user_id . '/outbox ' );
460- $ response = \rest_get_server ()->dispatch ( $ request );
461- $ data = $ response ->get_data ();
462-
463- $ this ->assertEquals ( 200 , $ response ->get_status () );
464- $ this ->assertSame (
465- (int ) $ public_visible ,
466- (int ) \count ( $ data ['orderedItems ' ] ),
467- sprintf (
468- 'Content with visibility "%s" should%s be visible to logged-out users. ' ,
469- $ visibility ?? 'none ' ,
470- $ public_visible ? '' : ' not '
471- )
472- );
471+ $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . $ user_id . '/outbox ' );
472+
473+ if ( $ public_visible ) {
474+ // For publicly visible content, request a page to verify it appears in orderedItems.
475+ $ request ->set_param ( 'page ' , 1 ); // Need to request a page to get orderedItems.
476+ $ request ->set_param ( 'per_page ' , 10 ); // Need per_page for pagination calculation.
477+ $ response = \rest_get_server ()->dispatch ( $ request );
478+ $ data = $ response ->get_data ();
479+
480+ $ this ->assertEquals ( 200 , $ response ->get_status () );
481+ $ this ->assertSame (
482+ 1 ,
483+ (int ) \count ( $ data ['orderedItems ' ] ),
484+ sprintf (
485+ 'Content with visibility "%s" should be visible to logged-out users. ' ,
486+ $ visibility ?? 'none '
487+ )
488+ );
489+ } else {
490+ // For non-public content, check the collection without pagination to verify totalItems is 0.
491+ $ response = \rest_get_server ()->dispatch ( $ request );
492+ $ data = $ response ->get_data ();
493+
494+ $ this ->assertEquals ( 200 , $ response ->get_status () );
495+ $ this ->assertEquals (
496+ 0 ,
497+ $ data ['totalItems ' ],
498+ sprintf (
499+ 'Content with visibility "%s" should not be visible to logged-out users (totalItems should be 0). ' ,
500+ $ visibility ?? 'none '
501+ )
502+ );
503+ }
473504
474505 // Test as logged-in user with activitypub capability.
475506 \wp_set_current_user ( $ user_id );
476507 $ this ->assertTrue ( \current_user_can ( 'activitypub ' ) );
477508
478- $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . $ user_id . '/outbox ' );
509+ $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . $ user_id . '/outbox ' );
510+ $ request ->set_param ( 'page ' , 1 ); // Need to request a page to get orderedItems.
511+ $ request ->set_param ( 'per_page ' , 10 ); // Need per_page for pagination calculation.
479512 $ response = \rest_get_server ()->dispatch ( $ request );
480513 $ data = $ response ->get_data ();
481514
@@ -531,15 +564,17 @@ public function test_get_items_actor_type_filtering() {
531564 );
532565
533566 // Test user outbox only returns user actor type.
534- $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . self ::$ user_id . '/outbox ' );
567+ $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . self ::$ user_id . '/outbox ' );
568+ $ request ->set_param ( 'page ' , 1 ); // Need to request a page to get orderedItems.
535569 $ response = \rest_get_server ()->dispatch ( $ request );
536570 $ data = $ response ->get_data ();
537571
538572 $ this ->assertEquals ( 200 , $ response ->get_status () );
539573 $ this ->assertCount ( 10 , $ data ['orderedItems ' ] );
540574
541575 // Test blog outbox only returns blog actor type.
542- $ request = new \WP_REST_Request ( 'GET ' , sprintf ( '/%s/actors/0/outbox ' , ACTIVITYPUB_REST_NAMESPACE ) );
576+ $ request = new \WP_REST_Request ( 'GET ' , sprintf ( '/%s/actors/0/outbox ' , ACTIVITYPUB_REST_NAMESPACE ) );
577+ $ request ->set_param ( 'page ' , 1 ); // Need to request a page to get orderedItems.
543578 $ response = \rest_get_server ()->dispatch ( $ request );
544579 $ data = $ response ->get_data ();
545580
@@ -583,7 +618,8 @@ public function test_get_items_meta_query_for_non_privileged_users() {
583618
584619 // Test as non-privileged user.
585620 wp_set_current_user ( $ viewer_id );
586- $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . self ::$ user_id . '/outbox ' );
621+ $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . self ::$ user_id . '/outbox ' );
622+ $ request ->set_param ( 'page ' , 1 ); // Need to request a page to get orderedItems.
587623 $ response = \rest_get_server ()->dispatch ( $ request );
588624 $ data = $ response ->get_data ();
589625
@@ -593,7 +629,9 @@ public function test_get_items_meta_query_for_non_privileged_users() {
593629 // Test as privileged user.
594630 $ admin_id = self ::factory ()->user ->create ( array ( 'role ' => 'administrator ' ) );
595631 wp_set_current_user ( $ admin_id );
596- $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . self ::$ user_id . '/outbox ' );
632+ $ request = new \WP_REST_Request ( 'GET ' , '/ ' . ACTIVITYPUB_REST_NAMESPACE . '/actors/ ' . self ::$ user_id . '/outbox ' );
633+ $ request ->set_param ( 'page ' , 1 ); // Need to request a page to get orderedItems.
634+ $ request ->set_param ( 'per_page ' , 20 ); // Need per_page for pagination calculation.
597635 $ response = \rest_get_server ()->dispatch ( $ request );
598636 $ data = $ response ->get_data ();
599637
0 commit comments