From 9e16c0aed7bf796b0034d166264fe563e0518833 Mon Sep 17 00:00:00 2001 From: Foteini Giannaropoulou Date: Wed, 17 Sep 2025 12:19:42 +0300 Subject: [PATCH 1/4] Jetpack Sync: Add 'is_connected' property to synced users --- projects/packages/sync/src/modules/class-users.php | 3 +++ .../plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php | 2 ++ .../php/sync/server/class.jetpack-sync-test-replicastore.php | 2 ++ 3 files changed, 7 insertions(+) diff --git a/projects/packages/sync/src/modules/class-users.php b/projects/packages/sync/src/modules/class-users.php index 99d5603797449..6a979d03a3929 100644 --- a/projects/packages/sync/src/modules/class-users.php +++ b/projects/packages/sync/src/modules/class-users.php @@ -7,6 +7,7 @@ namespace Automattic\Jetpack\Sync\Modules; +use Automattic\Jetpack\Connection\Manager; use Automattic\Jetpack\Constants as Jetpack_Constants; use Automattic\Jetpack\Password_Checker; use Automattic\Jetpack\Sync\Defaults; @@ -253,6 +254,8 @@ public function expand_user( $user ) { $user->locale = get_user_locale( $user->ID ); } + $user->is_connected = ( new Manager( 'jetpack' ) )->is_user_connected( $user->ID ); + return $user; } diff --git a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php index 8883a57a90f09..307a0bcf2cf65 100644 --- a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php +++ b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php @@ -55,6 +55,7 @@ public function test_insert_user_is_synced() { // TODO: this is to address a testing bug, alas :/ unset( $retrieved_user->data->allowed_mime_types ); + unset( $retrieved_user->data->is_connected ); $this->assertEquals( $synced_user, $retrieved_user, 'Retrieved user must equal the synced user.' ); } @@ -578,6 +579,7 @@ public function test_returns_user_object_by_id() { // TODO: this is to address a testing bug, alas :/ unset( $retrieved_user->data->allowed_mime_types ); + unset( $retrieved_user->data->is_connected ); $this->assertEquals( $synced_user, $retrieved_user ); } diff --git a/projects/plugins/jetpack/tests/php/sync/server/class.jetpack-sync-test-replicastore.php b/projects/plugins/jetpack/tests/php/sync/server/class.jetpack-sync-test-replicastore.php index cd2a1932b6201..7c1c9f7d9c5f5 100644 --- a/projects/plugins/jetpack/tests/php/sync/server/class.jetpack-sync-test-replicastore.php +++ b/projects/plugins/jetpack/tests/php/sync/server/class.jetpack-sync-test-replicastore.php @@ -588,6 +588,8 @@ public function upsert_user( $user ) { $this->users_locale[ get_current_blog_id() ][ $user->ID ] = $user->data->locale; unset( $user->data->locale ); } + unset( $user->data->is_connected ); + $this->users[ get_current_blog_id() ][ $user->ID ] = $user; } From 09ae95611b27b684f441ccf3bc58e48379933b19 Mon Sep 17 00:00:00 2001 From: Foteini Giannaropoulou Date: Wed, 17 Sep 2025 12:21:27 +0300 Subject: [PATCH 2/4] changelog --- .../packages/sync/changelog/update-sync-users-is_connected | 4 ++++ .../plugins/jetpack/changelog/update-sync-users-is_connected | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 projects/packages/sync/changelog/update-sync-users-is_connected create mode 100644 projects/plugins/jetpack/changelog/update-sync-users-is_connected diff --git a/projects/packages/sync/changelog/update-sync-users-is_connected b/projects/packages/sync/changelog/update-sync-users-is_connected new file mode 100644 index 0000000000000..ef373821595d9 --- /dev/null +++ b/projects/packages/sync/changelog/update-sync-users-is_connected @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Jetpack Sync: Add 'is_connected' property to synced users diff --git a/projects/plugins/jetpack/changelog/update-sync-users-is_connected b/projects/plugins/jetpack/changelog/update-sync-users-is_connected new file mode 100644 index 0000000000000..f91b639f1e17b --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-sync-users-is_connected @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Update Sync related unit tests + + From fb3ac573fb689419ea1e9acacac5ef53524c1ba5 Mon Sep 17 00:00:00 2001 From: Foteini Giannaropoulou Date: Wed, 17 Sep 2025 12:33:21 +0300 Subject: [PATCH 3/4] Add unit tests --- .../php/sync/Jetpack_Sync_Users_Test.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php index 307a0bcf2cf65..392791c5e1f71 100644 --- a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php +++ b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php @@ -579,11 +579,34 @@ public function test_returns_user_object_by_id() { // TODO: this is to address a testing bug, alas :/ unset( $retrieved_user->data->allowed_mime_types ); + + $this->assertFalse( $retrieved_user->data->is_connected ); unset( $retrieved_user->data->is_connected ); $this->assertEquals( $synced_user, $retrieved_user ); } + public function test_returns_user_object_by_id_with_connected_user() { + Jetpack_Options::update_option( + 'user_tokens', + array( + $this->user_id => 'apple.a.' . $this->user_id, + ) + ); + + $user_sync_module = Modules::get_module( 'users' ); + // grab the codec - we need to simulate the stripping of types that comes with encoding/decoding + $codec = $this->sender->get_codec(); + + $retrieved_user = $codec->decode( + $codec->encode( + $user_sync_module->get_object_by_id( 'user', $this->user_id ) + ) + ); + + $this->assertTrue( $retrieved_user->data->is_connected ); + } + public function test_update_user_locale_changed_is_synced() { update_user_meta( $this->user_id, 'locale', 'en_GB' ); $this->sender->do_sync(); From fdb60c205731a8d46aca3934969bb951750d7177 Mon Sep 17 00:00:00 2001 From: Foteini Giannaropoulou Date: Wed, 17 Sep 2025 14:17:52 +0300 Subject: [PATCH 4/4] Update unit tests --- .../plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php index 392791c5e1f71..3c33cb7e98e8c 100644 --- a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php +++ b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_Users_Test.php @@ -451,6 +451,7 @@ public function test_syncs_users_added_to_multisite() { // TODO: this is to address a testing bug, alas :/ unset( $retrieved_user->data->allowed_mime_types ); + unset( $retrieved_user->data->is_connected ); $this->assertEquals( $synced_user, $retrieved_user ); }