From 178b5af83a3a61e04b376b052cc6f1d8d9782c3d Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 10 Nov 2018 14:52:43 +0000 Subject: [PATCH] Added google select_account test Also cleaned the function naming a little to be more descriptive of the work they do. --- app/Auth/Access/SocialAuthService.php | 18 ++++++++++-------- phpunit.xml | 1 + tests/Auth/SocialAuthTest.php | 8 ++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/Auth/Access/SocialAuthService.php b/app/Auth/Access/SocialAuthService.php index 66f567c98..0d46b9f88 100644 --- a/app/Auth/Access/SocialAuthService.php +++ b/app/Auth/Access/SocialAuthService.php @@ -40,7 +40,7 @@ class SocialAuthService public function startLogIn($socialDriver) { $driver = $this->validateDriver($socialDriver); - return $this->redirectToSocialProvider($driver)->redirect(); + return $this->getSocialDriver($driver)->redirect(); } /** @@ -52,7 +52,7 @@ class SocialAuthService public function startRegister($socialDriver) { $driver = $this->validateDriver($socialDriver); - return $this->redirectToSocialProvider($driver)->redirect(); + return $this->getSocialDriver($driver)->redirect(); } /** @@ -250,15 +250,17 @@ class SocialAuthService /** * Provide redirect options per service for the Laravel Socialite driver - * @param $driver + * @param $driverName + * @return \Laravel\Socialite\Contracts\Provider */ - public function redirectToSocialProvider($driver) + public function getSocialDriver(string $driverName) { - if ($driver == 'google' && config('services.google.select_account')) - { - return $this->socialite->driver($driver)->with(['prompt' => 'select_account']); + $driver = $this->socialite->driver($driverName); + + if ($driverName === 'google' && config('services.google.select_account')) { + $driver->with(['prompt' => 'select_account']); } - return $this->socialite->driver($driver); + return $driver; } } diff --git a/phpunit.xml b/phpunit.xml index efed0070e..3d18d9bbf 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -41,6 +41,7 @@ + diff --git a/tests/Auth/SocialAuthTest.php b/tests/Auth/SocialAuthTest.php index 572c32f46..b8ca81174 100644 --- a/tests/Auth/SocialAuthTest.php +++ b/tests/Auth/SocialAuthTest.php @@ -148,4 +148,12 @@ class SocialAuthTest extends TestCase $this->assertDatabaseHas('social_accounts', ['user_id' => $user->id]); } + public function test_google_select_account_option_changes_redirect_url() + { + config()->set('services.google.select_account', 'true'); + + $resp = $this->get('/login/service/google'); + $this->assertContains('prompt=select_account', $resp->headers->get('Location')); + } + }