+ $resp = $this->followingRedirects()->get('/login/service/github/callback');
+ $resp->assertDontSee("login-form");
+ }
+
+ public function test_social_autoregister()
+ {
+ config([
+ 'services.google.client_id' => 'abc123', 'services.google.client_secret' => '123abc',
+ 'APP_URL' => 'http://localhost'
+ ]);
+
+ $user = factory(User::class)->make();
+ $mockSocialite = Mockery::mock(Factory::class);
+ $this->app[Factory::class] = $mockSocialite;
+ $mockSocialDriver = Mockery::mock(Provider::class);
+ $mockSocialUser = Mockery::mock(\Laravel\Socialite\Contracts\User::class);
+
+ $mockSocialUser->shouldReceive('getId')->times(4)->andReturn(1);
+ $mockSocialUser->shouldReceive('getEmail')->times(2)->andReturn($user->email);
+ $mockSocialUser->shouldReceive('getName')->once()->andReturn($user->name);
+ $mockSocialUser->shouldReceive('getAvatar')->once()->andReturn('avatar_placeholder');
+
+ $mockSocialDriver->shouldReceive('user')->times(2)->andReturn($mockSocialUser);
+ $mockSocialite->shouldReceive('driver')->times(4)->with('google')->andReturn($mockSocialDriver);
+ $mockSocialDriver->shouldReceive('redirect')->twice()->andReturn(redirect('/'));
+
+ $googleAccountNotUsedMessage = trans('errors.social_account_not_used', ['socialAccount' => 'Google']);
+
+ $this->get('/login/service/google');
+ $resp = $this->followingRedirects()->get('/login/service/google/callback');
+ $resp->assertSee($googleAccountNotUsedMessage);
+
+ config(['services.google.auto_register' => true]);
+
+ $this->get('/login/service/google');
+ $resp = $this->followingRedirects()->get('/login/service/google/callback');
+ $resp->assertDontSee($googleAccountNotUsedMessage);
+
+ $this->assertDatabaseHas('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => false]);
+ $user = $user->whereEmail($user->email)->first();
+ $this->assertDatabaseHas('social_accounts', ['user_id' => $user->id]);
+ }
+
+ public function test_social_auto_email_confirm()
+ {
+ config([
+ 'services.google.client_id' => 'abc123', 'services.google.client_secret' => '123abc',
+ 'APP_URL' => 'http://localhost', 'services.google.auto_register' => true, 'services.google.auto_confirm' => true
+ ]);
+
+ $user = factory(User::class)->make();
+ $mockSocialite = Mockery::mock(Factory::class);
+ $this->app[Factory::class] = $mockSocialite;
+ $mockSocialDriver = Mockery::mock(Provider::class);
+ $mockSocialUser = Mockery::mock(\Laravel\Socialite\Contracts\User::class);
+
+ $mockSocialUser->shouldReceive('getId')->times(3)->andReturn(1);
+ $mockSocialUser->shouldReceive('getEmail')->times(2)->andReturn($user->email);
+ $mockSocialUser->shouldReceive('getName')->once()->andReturn($user->name);
+ $mockSocialUser->shouldReceive('getAvatar')->once()->andReturn('avatar_placeholder');
+
+ $mockSocialDriver->shouldReceive('user')->times(1)->andReturn($mockSocialUser);
+ $mockSocialite->shouldReceive('driver')->times(2)->with('google')->andReturn($mockSocialDriver);
+ $mockSocialDriver->shouldReceive('redirect')->once()->andReturn(redirect('/'));
+
+ $this->get('/login/service/google');
+ $this->get('/login/service/google/callback');
+
+ $this->assertDatabaseHas('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => true]);
+ $user = $user->whereEmail($user->email)->first();
+ $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->assertStringContainsString('prompt=select_account', $resp->headers->get('Location'));
+ }
+
+ public function test_social_registration_with_no_name_uses_email_as_name()
+ {
+
+ $this->setSettings(['registration-enabled' => 'true']);
+ config(['GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);
+
+ $mockSocialite = Mockery::mock(Factory::class);
+ $this->app[Factory::class] = $mockSocialite;
+ $mockSocialDriver = Mockery::mock(Provider::class);
+ $mockSocialUser = Mockery::mock(\Laravel\Socialite\Contracts\User::class);
+
+ $mockSocialite->shouldReceive('driver')->twice()->with('github')->andReturn($mockSocialDriver);
+ $mockSocialDriver->shouldReceive('redirect')->once()->andReturn(redirect('/'));
+ $mockSocialDriver->shouldReceive('user')->once()->andReturn($mockSocialUser);
+
+ $mockSocialUser->shouldReceive('getId')->twice()->andReturn(1);
+ $mockSocialUser->shouldReceive('getEmail')->twice()->andReturn($user->email);
+ $mockSocialUser->shouldReceive('getName')->once()->andReturn('');
+ $mockSocialUser->shouldReceive('getAvatar')->once()->andReturn('avatar_placeholder');
+
+ $this->get('/register/service/github');
+ $this->get('/login/service/github/callback');
+ $this->assertDatabaseHas('users', ['name' => 'nonameuser', 'email' => $user->email]);
+ $user = $user->whereEmail($user->email)->first();
+ $this->assertDatabaseHas('social_accounts', ['user_id' => $user->id]);