Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

stefanzweifel/screeenly

520 stars
1 code files
View stefanzweifel/screeenly on GitHub

tests/modules/Screeenly/integration/web/OAuth/GithubOAuthLoginTest.php

Open in GitHub
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laravel\Socialite\Contracts\Factory as Socialite;
use Screeenly\Models\User;
 
class GithubOAuthLoginTest extends BrowserKitTestCase
{
use DatabaseTransactions;
 
public function mockSocialiteFacade($email = '[email protected]', $token = 'foo', $id = 1)
{
$socialiteUser = $this->createMock(Laravel\Socialite\Two\User::class);
$socialiteUser->token = $token;
$socialiteUser->id = $id;
$socialiteUser->email = $email;
 
$provider = $this->createMock(Laravel\Socialite\Two\GithubProvider::class);
$provider->expects($this->any())
->method('user')
->willReturn($socialiteUser);
 
$stub = $this->createMock(Socialite::class);
$stub->expects($this->any())
->method('driver')
->willReturn($provider);
 
// Replace Socialite Instance with our mock
$this->app->instance(Socialite::class, $stub);
}
 
/** @test */
public function it_redirects_to_github()
{
$response = $this->call('GET', '/oauth/github/redirect');
 
$this->assertStringcontainsString('github.com/login/oauth', $response->getTargetUrl());
}
 
/** @test */
public function it_retrieves_github_request_and_creates_a_new_user()
{
$this->mockSocialiteFacade();
 
$this->visit('/oauth/github/handle')
->seePageIs('/dashboard')
->see('Dashboard');
 
$this->seeInDatabase('users', [
'email' => '[email protected]',
]);
}
 
/** @test */
public function it_retrieves_github_request_and_login_existing_user()
{
$user = User::factory()->create();
 
$this->mockSocialiteFacade($user->email, $user->token, $user->provider_id);
 
$this->visit('/oauth/github/handle')
->seePageIs('/dashboard')
->see('Dashboard');
}
 
/** @test */
public function it_redirects_user_with_out_email_address_to_setup_page()
{
$this->mockSocialiteFacade(null, 'secret_token', '12345');
 
$this->visit('/oauth/github/handle')
->seePageIs('/setup/email?provider_id=12345');
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.