diff --git a/includes/Core/Authentication/Google_Proxy.php b/includes/Core/Authentication/Google_Proxy.php index ee4de5c3947..17bc9dfd064 100644 --- a/includes/Core/Authentication/Google_Proxy.php +++ b/includes/Core/Authentication/Google_Proxy.php @@ -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. @@ -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', @@ -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 : '', ); /** diff --git a/tests/phpunit/integration/Core/Authentication/Google_ProxyTest.php b/tests/phpunit/integration/Core/Authentication/Google_ProxyTest.php index b4c80ff15b2..e10963924d9 100644 --- a/tests/phpunit/integration/Core/Authentication/Google_ProxyTest.php +++ b/tests/phpunit/integration/Core/Authentication/Google_ProxyTest.php @@ -431,6 +431,7 @@ 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.' @@ -438,6 +439,37 @@ public function test_get_features() { $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 );