mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-23 19:32:29 +01:00
Started Social Auth Testing
This commit is contained in:
parent
1b736ac045
commit
fd3929e809
@ -112,18 +112,6 @@ class AuthTest extends TestCase
|
|||||||
->seePageIs('/login');
|
->seePageIs('/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Quickly sets an array of settings.
|
|
||||||
* @param $settingsArray
|
|
||||||
*/
|
|
||||||
private function setSettings($settingsArray)
|
|
||||||
{
|
|
||||||
$settings = app('BookStack\Services\SettingService');
|
|
||||||
foreach ($settingsArray as $key => $value) {
|
|
||||||
$settings->put($key, $value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a login
|
* Perform a login
|
||||||
* @param string $email
|
* @param string $email
|
||||||
|
42
tests/SocialAuthTest.php
Normal file
42
tests/SocialAuthTest.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class SocialAuthTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function testSocialRegistration()
|
||||||
|
{
|
||||||
|
// http://docs.mockery.io/en/latest/reference/startup_methods.html
|
||||||
|
$user = factory(\BookStack\User::class)->make();
|
||||||
|
|
||||||
|
$this->setSettings(['registration-enabled' => 'true']);
|
||||||
|
$this->setEnvironment(['GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);
|
||||||
|
|
||||||
|
$mockSocialite = Mockery::mock('Laravel\Socialite\Contracts\Factory');
|
||||||
|
$this->app['Laravel\Socialite\Contracts\Factory'] = $mockSocialite;
|
||||||
|
$mockSocialDriver = Mockery::mock('Laravel\Socialite\Contracts\Provider');
|
||||||
|
$mockSocialUser = Mockery::mock('\Laravel\Socialite\Contracts\User');
|
||||||
|
|
||||||
|
$mockSocialite->shouldReceive('driver')->twice()->with('google')->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($user->name);
|
||||||
|
$mockSocialUser->shouldReceive('getAvatar')->once()->andReturn('avatar_placeholder');
|
||||||
|
|
||||||
|
$this->visit('/register/service/google');
|
||||||
|
$this->visit('/login/service/google/callback');
|
||||||
|
$this->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email]);
|
||||||
|
$user = $user->whereEmail($user->email)->first();
|
||||||
|
$this->seeInDatabase('social_accounts', ['user_id' => $user->id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setEnvironment($array)
|
||||||
|
{
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
putenv("$key=$value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -36,4 +36,16 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
}
|
}
|
||||||
return $this->actingAs($this->admin);
|
return $this->actingAs($this->admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quickly sets an array of settings.
|
||||||
|
* @param $settingsArray
|
||||||
|
*/
|
||||||
|
protected function setSettings($settingsArray)
|
||||||
|
{
|
||||||
|
$settings = app('BookStack\Services\SettingService');
|
||||||
|
foreach ($settingsArray as $key => $value) {
|
||||||
|
$settings->put($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user