Skip to content

Commit

Permalink
Adds tests for oAuth2 provider trait
Browse files Browse the repository at this point in the history
  • Loading branch information
artstorm committed Aug 1, 2015
1 parent 0c9bb30 commit d4c5c74
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion api/tests/Extensions/SocialiteTest.php
Expand Up @@ -3,6 +3,7 @@
use Laravel\Socialite\Two\User;
use App\Exceptions\NotImplementedException;
use App\Extensions\Socialite\SocialiteManager;
use App\Extensions\Socialite\Two\FacebookProvider;
use App\Extensions\Socialite\Parsers\ParserFactory;

class SocialiteTest extends TestCase
Expand All @@ -24,7 +25,7 @@ public function testCreateFacebookDriver()
$manager = new SocialiteManager($this->app);
$driver = $manager->with('facebook');

$this->assertInstanceOf('App\Extensions\Socialite\Two\FacebookProvider', $driver);
$this->assertInstanceOf(FacebookProvider::class, $driver);
}

public function testCreateTwitterDriver()
Expand All @@ -49,6 +50,46 @@ public function testCreateGoogleDriver()
$this->assertInstanceOf('App\Extensions\Socialite\Two\GoogleProvider', $driver);
}

public function testProviderTraitUser()
{
$mock = Mockery::mock(FacebookProvider::class, [$this->app->request, null, null, null])->makePartial()->shouldAllowMockingProtectedMethods();
$mock->shouldReceive('getAccessToken')
->once()
->andReturn([]);
$mock->shouldReceive('getUserByToken')
->once()
->andReturn(['id' => 'foo']);

$user = $mock->user();

$this->assertInstanceOf(User::class, $user);
}

public function testProviderTraitgetCachedReturnUrlCache()
{
$returnUrl = 'http://foo.bar';
Cache::put('oauth_return_url_foo', $returnUrl, 1);
$request = Mockery::mock('Illuminate\Http\Request');
$request->shouldReceive('get')
->once()
->andReturn('foo');

$mock = Mockery::mock(FacebookProvider::class, [$request, null, null, null])->makePartial();

$url = $mock->getCachedReturnUrl();

$this->assertEquals($url, $returnUrl);
}

public function testProviderTraitgetCachedReturnUrlNoCache()
{
$mock = Mockery::mock(FacebookProvider::class, [$this->app->request, null, null, null])->makePartial();

$url = $mock->getCachedReturnUrl();

$this->assertEquals($url, config('hosts.app'));
}

public function testAbstractParserMagicMethods()
{
$mock = Mockery::mock('App\Extensions\Socialite\Parsers\AbstractParser')->makePartial();
Expand Down

0 comments on commit d4c5c74

Please sign in to comment.