+ $resp->assertDontSee('login-form');
+ $this->assertActivityExists(ActivityType::AUTH_LOGIN, null, 'github; (' . $this->users->admin()->id . ') ' . $this->users->admin()->name);
+ }
+
+ public function test_social_account_attach()
+ {
+ config([
+ 'GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc',
+ ]);
+ $editor = $this->users->editor();
+
+ $mockSocialite = $this->mock(Factory::class);
+ $mockSocialDriver = Mockery::mock(Provider::class);
+ $mockSocialUser = Mockery::mock(\Laravel\Socialite\Contracts\User::class);
+
+ $mockSocialUser->shouldReceive('getId')->twice()->andReturn('logintest123');
+ $mockSocialUser->shouldReceive('getAvatar')->andReturn(null);
+
+ $mockSocialite->shouldReceive('driver')->twice()->with('google')->andReturn($mockSocialDriver);
+ $mockSocialDriver->shouldReceive('redirect')->once()->andReturn(redirect('/login/service/google/callback'));
+ $mockSocialDriver->shouldReceive('user')->once()->andReturn($mockSocialUser);
+
+ // Test login routes
+ $resp = $this->actingAs($editor)->followingRedirects()->get('/login/service/google');
+ $resp->assertSee('Access & Security');
+
+ // Test social callback with matching social account
+ $this->assertDatabaseHas('social_accounts', [
+ 'user_id' => $editor->id,
+ 'driver' => 'google',
+ 'driver_id' => 'logintest123',
+ ]);
+ }
+
+ public function test_social_account_detach()
+ {
+ $editor = $this->users->editor();
+ config([
+ 'GITHUB_APP_ID' => 'abc123', 'GITHUB_APP_SECRET' => '123abc',
+ ]);
+
+ $socialAccount = SocialAccount::query()->forceCreate([
+ 'user_id' => $editor->id,
+ 'driver' => 'github',
+ 'driver_id' => 'logintest123',
+ ]);
+
+ $resp = $this->actingAs($editor)->get('/my-account/auth');
+ $this->withHtml($resp)->assertElementContains('form[action$="/login/service/github/detach"]', 'Disconnect Account');
+
+ $resp = $this->post('/login/service/github/detach');
+ $resp->assertRedirect('/my-account/auth#social-accounts');
+ $resp = $this->followRedirects($resp);
+ $resp->assertSee('Github account was successfully disconnected from your profile.');
+
+ $this->assertDatabaseMissing('social_accounts', ['id' => $socialAccount->id]);