diff --git a/.github/changelog/1516-from-description b/.github/changelog/1516-from-description new file mode 100644 index 000000000..1614e8240 --- /dev/null +++ b/.github/changelog/1516-from-description @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Use the `$from` account for the object in Move activity for internal Moves diff --git a/includes/class-move.php b/includes/class-move.php index 03bdad7aa..4319717e8 100644 --- a/includes/class-move.php +++ b/includes/class-move.php @@ -130,7 +130,7 @@ public static function internally( $from, $to ) { $activity->set_type( 'Move' ); $activity->set_actor( $actor ); $activity->set_origin( $actor ); - $activity->set_object( $to ); + $activity->set_object( $actor ); $activity->set_target( $to ); return add_to_outbox( $activity, null, $user->get__id(), ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC ); diff --git a/tests/includes/class-test-move.php b/tests/includes/class-test-move.php index fae6d679a..75b3acbfe 100644 --- a/tests/includes/class-test-move.php +++ b/tests/includes/class-test-move.php @@ -160,4 +160,38 @@ public function test_internally_with_valid_input() { $also_known_as = Actors::get_by_id( self::$user_id )->get_also_known_as(); $this->assertContains( $from, $also_known_as ); } + + /** + * Test that the Move Activity created by internally() has the correct properties. + * + * @covers ::internally + */ + public function test_internally_activity_object_properties() { + $from = get_author_posts_url( self::$user_id ); + $to = Actors::get_by_id( self::$user_id )->get_id(); + + // Call the method and get the outbox item ID. + $outbox_id = \Activitypub\Move::internally( $from, $to ); + + // Verify we got a valid outbox ID. + $this->assertIsInt( $outbox_id ); + + // Get the outbox item from the database. + $outbox_item = get_post( $outbox_id ); + + // Verify the outbox item exists. + $this->assertNotNull( $outbox_item ); + + // Get the activity JSON from the outbox item. + $activity = json_decode( $outbox_item->post_content ); + + // Verify the activity type is Move. + $this->assertEquals( 'Move', $activity->type ); + + // Verify the activity object is set to the actor, not the target. + $this->assertEquals( $from, $activity->object ); + $this->assertEquals( $from, $activity->actor ); + $this->assertEquals( $from, $activity->origin ); + $this->assertEquals( $to, $activity->target ); + } }