-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract setting user access token to a new trait.
- Loading branch information
Showing
2 changed files
with
37 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* UserAuthenticationTrait | ||
* | ||
* @package Google\Site_Kit\Tests | ||
* @copyright 2023 Google LLC | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 | ||
* @link https://sitekit.withgoogle.com | ||
*/ | ||
|
||
namespace Google\Site_Kit\Tests; | ||
|
||
use Google\Site_Kit\Context; | ||
use Google\Site_Kit\Core\Authentication\Token; | ||
use Google\Site_Kit\Core\Storage\User_Options; | ||
|
||
trait UserAuthenticationTrait { | ||
|
||
/** | ||
* Sets the access token for the specified user. | ||
* | ||
* @param int $user_id The user ID to set the access token for. | ||
* @param string $access_token The access token to use. | ||
*/ | ||
protected function set_user_access_token( $user_id, $access_token ) { | ||
$user_options = new User_Options( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ), $user_id ); | ||
$token = new Token( $user_options ); | ||
$token->set( | ||
array( | ||
'access_token' => $access_token, | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters