Skip to content

Commit

Permalink
Update sign in render function to use site_url instead of rest_url.
Browse files Browse the repository at this point in the history
  • Loading branch information
benbowler committed Oct 23, 2024
1 parent ef86a42 commit 3786bdd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions includes/Modules/Sign_In_With_Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ protected function register_and_enqueue_style() {
public function render_signin_button() {
$settings = $this->get_settings()->get();

$redirect_url = rest_url( '/' . REST_Routes::REST_ROOT . '/modules/sign-in-with-google/auth/google' );
$redirect_url = site_url( '/auth/google' );

if ( substr( rest_url(), 0, 5 ) !== 'https' || ! $settings['clientID'] ) {
if ( substr( site_url(), 0, 5 ) !== 'https' || ! $settings['clientID'] ) {
return;
}

Expand Down
8 changes: 5 additions & 3 deletions tests/phpunit/integration/Modules/Sign_In_With_GoogleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public function test_render_signin_button() {
$this->assertNull( $this->module->render_signin_button() );

// Update site URL to https.
update_option( 'home', 'https://example.com/' );
$_SERVER['HTTPS'] = 'on'; // Required because WordPress's site_url function check is_ssl which uses this var.
update_option( 'siteurl', 'https://example.com/' );
update_option( 'home', 'https://example.com/' );

// Does not render if clientID is not set.
$this->module->get_settings()->set( array( 'clientID' => '' ) );
Expand Down Expand Up @@ -80,14 +81,15 @@ public function test_render_signin_button() {

// Check the rendered button contains the expected data.
$this->assertStringContainsString( 'data-client_id="1234567890.googleusercontent.com"', $output );
$this->assertStringContainsString( 'data-login_uri="https://example.com/index.php?rest_route=/google-site-kit/v1/modules/sign-in-with-google/auth/google"', $output );
$this->assertStringContainsString( 'data-login_uri="https://example.com/auth/google"', $output );

$this->assertStringContainsString( 'data-text="' . Sign_In_With_Google_Settings::TEXT_CONTINUE_WITH_GOOGLE . '"', $output );
$this->assertStringContainsString( 'data-theme="' . Sign_In_With_Google_Settings::THEME_LIGHT . '"', $output );
$this->assertStringContainsString( 'data-shape="' . Sign_In_With_Google_Settings::SHAPE_RECTANGULAR . '"', $output );

// Revert home and siteurl.
// Revert home and siteurl and https value.
update_option( 'home', $reset_site_url );
update_option( 'siteurl', $reset_site_url );
unset( $_SERVER['HTTPS'] );
}
}

0 comments on commit 3786bdd

Please sign in to comment.