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
3 changes: 3 additions & 0 deletions includes/Core/Authentication/Google_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ public function exchange_site_code( $site_code, $undelegated_code ) {
*
* @since 1.27.0
* @since 1.104.0 Added `php_version` to request.
* @since n.e.x.t Added `amp_mode` to request.
*
* @param Credentials $credentials Credentials instance.
* @return array|WP_Error Response of the wp_remote_post request.
Expand All @@ -534,6 +535,7 @@ public function get_features( Credentials $credentials ) {
$platform = self::get_platform();
$user_count = count_users();
$connectable_user_count = isset( $user_count['avail_roles']['administrator'] ) ? $user_count['avail_roles']['administrator'] : 0;
$amp_mode = $this->context->get_amp_mode();

$body = array(
'platform' => $platform . '/google-site-kit',
Expand All @@ -543,6 +545,7 @@ public function get_features( Credentials $credentials ) {
'user_count' => $user_count['total_users'],
'connectable_user_count' => $connectable_user_count,
'connected_user_count' => $this->count_connected_users(),
'amp_mode' => $amp_mode ? $amp_mode : '',
);

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/phpunit/integration/Core/Authentication/Google_ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,45 @@ public function test_get_features() {
'connected_modules' => 'site-verification search-console pagespeed-insights',
'php_version' => phpversion(),
'feature_metrics' => array(),
'amp_mode' => '', // No AMP mode by default.
),
$this->request_args['body'],
'Get features request body should contain site credentials and platform information.'
);
$this->assertEqualSetsWithIndex( $expected_success_response, $features, 'Get features should return expected feature data.' );
}

/**
* @dataProvider amp_mode_provider
*/
public function test_get_features_with_amp_mode( $amp_mode, $context_method ) {
// Remove the filter being added by Modules::register() or any other class during bootstrap.
remove_all_filters( 'googlesitekit_feature_metrics' );

list ( $credentials, $site_id, $site_secret ) = $this->get_credentials();

$context = call_user_func( array( $this, $context_method ) );
$google_proxy = new Google_Proxy( $context );

$expected_url = $google_proxy->url( Google_Proxy::FEATURES_URI );
$expected_success_response = array(
'test.featureName' => array( 'enabled' => true ),
);

$this->mock_http_request( $expected_url, $expected_success_response );
$google_proxy->get_features( $credentials, new OAuth_Client( $context, null, null, $credentials, $google_proxy ) );

// Ensure amp_mode is set to the expected value.
$this->assertEquals( $amp_mode, $this->request_args['body']['amp_mode'], "Get features request should include '$amp_mode' amp_mode." );
}

public function amp_mode_provider() {
return array(
'primary AMP mode' => array( 'primary', 'get_amp_primary_context' ),
'secondary AMP mode' => array( 'secondary', 'get_amp_secondary_context' ),
);
}

public function test_count_connected_users() {
$context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE );
$meta_key = ( new User_Options( $context ) )->get_meta_key( OAuth_Client::OPTION_ACCESS_TOKEN );
Expand Down