@@ -18,7 +18,7 @@ public function test_social_registration()
1818 $ user = User::factory ()->make ();
1919
2020 $ this ->setSettings (['registration-enabled ' => 'true ' ]);
21- config (['GOOGLE_APP_ID ' => 'abc123 ' , 'GOOGLE_APP_SECRET ' => '123abc ' , ' APP_URL ' => ' http://localhost ' ]);
21+ config (['GOOGLE_APP_ID ' => 'abc123 ' , 'GOOGLE_APP_SECRET ' => '123abc ' ]);
2222
2323 $ mockSocialite = $ this ->mock (Factory::class);
2424 $ mockSocialDriver = Mockery::mock (Provider::class);
@@ -45,7 +45,6 @@ public function test_social_login()
4545 config ([
4646 'GOOGLE_APP_ID ' => 'abc123 ' , 'GOOGLE_APP_SECRET ' => '123abc ' ,
4747 'GITHUB_APP_ID ' => 'abc123 ' , 'GITHUB_APP_SECRET ' => '123abc ' ,
48- 'APP_URL ' => 'http://localhost ' ,
4948 ]);
5049
5150 $ mockSocialite = $ this ->mock (Factory::class);
@@ -86,12 +85,41 @@ public function test_social_login()
8685 $ this ->assertActivityExists (ActivityType::AUTH_LOGIN , null , 'github; ( ' . $ this ->users ->admin ()->id . ') ' . $ this ->users ->admin ()->name );
8786 }
8887
88+ public function test_social_account_attach ()
89+ {
90+ config ([
91+ 'GOOGLE_APP_ID ' => 'abc123 ' , 'GOOGLE_APP_SECRET ' => '123abc ' ,
92+ ]);
93+ $ editor = $ this ->users ->editor ();
94+
95+ $ mockSocialite = $ this ->mock (Factory::class);
96+ $ mockSocialDriver = Mockery::mock (Provider::class);
97+ $ mockSocialUser = Mockery::mock (\Laravel \Socialite \Contracts \User::class);
98+
99+ $ mockSocialUser ->shouldReceive ('getId ' )->twice ()->andReturn ('logintest123 ' );
100+ $ mockSocialUser ->shouldReceive ('getAvatar ' )->andReturn (null );
101+
102+ $ mockSocialite ->shouldReceive ('driver ' )->twice ()->with ('google ' )->andReturn ($ mockSocialDriver );
103+ $ mockSocialDriver ->shouldReceive ('redirect ' )->once ()->andReturn (redirect ('/login/service/google/callback ' ));
104+ $ mockSocialDriver ->shouldReceive ('user ' )->once ()->andReturn ($ mockSocialUser );
105+
106+ // Test login routes
107+ $ resp = $ this ->actingAs ($ editor )->followingRedirects ()->get ('/login/service/google ' );
108+ $ resp ->assertSee ('Access & Security ' );
109+
110+ // Test social callback with matching social account
111+ $ this ->assertDatabaseHas ('social_accounts ' , [
112+ 'user_id ' => $ editor ->id ,
113+ 'driver ' => 'google ' ,
114+ 'driver_id ' => 'logintest123 ' ,
115+ ]);
116+ }
117+
89118 public function test_social_account_detach ()
90119 {
91120 $ editor = $ this ->users ->editor ();
92121 config ([
93122 'GITHUB_APP_ID ' => 'abc123 ' , 'GITHUB_APP_SECRET ' => '123abc ' ,
94- 'APP_URL ' => 'http://localhost ' ,
95123 ]);
96124
97125 $ socialAccount = SocialAccount::query ()->forceCreate ([
@@ -100,11 +128,11 @@ public function test_social_account_detach()
100128 'driver_id ' => 'logintest123 ' ,
101129 ]);
102130
103- $ resp = $ this ->actingAs ($ editor )->get ($ editor -> getEditUrl () );
131+ $ resp = $ this ->actingAs ($ editor )->get (' /my-account/auth ' );
104132 $ this ->withHtml ($ resp )->assertElementContains ('form[action$="/login/service/github/detach"] ' , 'Disconnect Account ' );
105133
106134 $ resp = $ this ->post ('/login/service/github/detach ' );
107- $ resp ->assertRedirect ($ editor -> getEditUrl () );
135+ $ resp ->assertRedirect (' /my-account/auth#social-accounts ' );
108136 $ resp = $ this ->followRedirects ($ resp );
109137 $ resp ->assertSee ('Github account was successfully disconnected from your profile. ' );
110138
@@ -115,7 +143,6 @@ public function test_social_autoregister()
115143 {
116144 config ([
117145 'services.google.client_id ' => 'abc123 ' , 'services.google.client_secret ' => '123abc ' ,
118- 'APP_URL ' => 'http://localhost ' ,
119146 ]);
120147
121148 $ user = User::factory ()->make ();
@@ -153,7 +180,7 @@ public function test_social_auto_email_confirm()
153180 {
154181 config ([
155182 'services.google.client_id ' => 'abc123 ' , 'services.google.client_secret ' => '123abc ' ,
156- 'APP_URL ' => ' http://localhost ' , ' services.google.auto_register ' => true , 'services.google.auto_confirm ' => true ,
183+ 'services.google.auto_register ' => true , 'services.google.auto_confirm ' => true ,
157184 ]);
158185
159186 $ user = User::factory ()->make ();
@@ -191,7 +218,7 @@ public function test_social_registration_with_no_name_uses_email_as_name()
191218 $ user = User::factory ()->make (['email ' => 'nonameuser@example.com ' ]);
192219
193220 $ this ->setSettings (['registration-enabled ' => 'true ' ]);
194- config (['GITHUB_APP_ID ' => 'abc123 ' , 'GITHUB_APP_SECRET ' => '123abc ' , ' APP_URL ' => ' http://localhost ' ]);
221+ config (['GITHUB_APP_ID ' => 'abc123 ' , 'GITHUB_APP_SECRET ' => '123abc ' ]);
195222
196223 $ mockSocialite = $ this ->mock (Factory::class);
197224 $ mockSocialDriver = Mockery::mock (Provider::class);
0 commit comments