Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Jetpack Sync: Add 'is_connected' property to synced users
3 changes: 3 additions & 0 deletions projects/packages/sync/src/modules/class-users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Update Sync related unit tests


Original file line number Diff line number Diff line change
Expand Up @@ -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.' );
}
Expand Down Expand Up @@ -450,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 );
}
Expand Down Expand Up @@ -579,9 +581,33 @@ 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading