Skip to content

Commit 8935320

Browse files
authored
Merge pull request #11774 from google/enhancement/#11643-extend-features-request-amp-mode
Enhancement/#11643 - Add amp mode to Google Proxy features request
2 parents 3972ebf + 3a7a560 commit 8935320

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

includes/Core/Authentication/Google_Proxy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ public function exchange_site_code( $site_code, $undelegated_code ) {
524524
*
525525
* @since 1.27.0
526526
* @since 1.104.0 Added `php_version` to request.
527+
* @since n.e.x.t Added `amp_mode` to request.
527528
*
528529
* @param Credentials $credentials Credentials instance.
529530
* @return array|WP_Error Response of the wp_remote_post request.
@@ -534,6 +535,7 @@ public function get_features( Credentials $credentials ) {
534535
$platform = self::get_platform();
535536
$user_count = count_users();
536537
$connectable_user_count = isset( $user_count['avail_roles']['administrator'] ) ? $user_count['avail_roles']['administrator'] : 0;
538+
$amp_mode = $this->context->get_amp_mode();
537539

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

548551
/**

tests/phpunit/integration/Core/Authentication/Google_ProxyTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,45 @@ public function test_get_features() {
431431
'connected_modules' => 'site-verification search-console pagespeed-insights',
432432
'php_version' => phpversion(),
433433
'feature_metrics' => array(),
434+
'amp_mode' => '', // No AMP mode by default.
434435
),
435436
$this->request_args['body'],
436437
'Get features request body should contain site credentials and platform information.'
437438
);
438439
$this->assertEqualSetsWithIndex( $expected_success_response, $features, 'Get features should return expected feature data.' );
439440
}
440441

442+
/**
443+
* @dataProvider amp_mode_provider
444+
*/
445+
public function test_get_features_with_amp_mode( $amp_mode, $context_method ) {
446+
// Remove the filter being added by Modules::register() or any other class during bootstrap.
447+
remove_all_filters( 'googlesitekit_feature_metrics' );
448+
449+
list ( $credentials, $site_id, $site_secret ) = $this->get_credentials();
450+
451+
$context = call_user_func( array( $this, $context_method ) );
452+
$google_proxy = new Google_Proxy( $context );
453+
454+
$expected_url = $google_proxy->url( Google_Proxy::FEATURES_URI );
455+
$expected_success_response = array(
456+
'test.featureName' => array( 'enabled' => true ),
457+
);
458+
459+
$this->mock_http_request( $expected_url, $expected_success_response );
460+
$google_proxy->get_features( $credentials, new OAuth_Client( $context, null, null, $credentials, $google_proxy ) );
461+
462+
// Ensure amp_mode is set to the expected value.
463+
$this->assertEquals( $amp_mode, $this->request_args['body']['amp_mode'], "Get features request should include '$amp_mode' amp_mode." );
464+
}
465+
466+
public function amp_mode_provider() {
467+
return array(
468+
'primary AMP mode' => array( 'primary', 'get_amp_primary_context' ),
469+
'secondary AMP mode' => array( 'secondary', 'get_amp_secondary_context' ),
470+
);
471+
}
472+
441473
public function test_count_connected_users() {
442474
$context = new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE );
443475
$meta_key = ( new User_Options( $context ) )->get_meta_key( OAuth_Client::OPTION_ACCESS_TOKEN );

0 commit comments

Comments
 (0)