Exemplo n.º 1
0
 public function setUp()
 {
     parent::setUp();
     //simulate what we would get from an OAuth2 provider
     $this->providerUser = new ThirdPartyUser();
     $this->providerUser->map(['id' => uniqid(), 'name' => 'John Peterson', 'email' => 'john.' . uniqid() . '@peterson.example.com', 'avatar' => 'avatar' . time() . '.jpg']);
     $this->socialite = Mockery::mock('Laravel\\Socialite\\SocialiteManager');
     $this->socialite->shouldReceive('driver')->andReturn($this->socialite);
     $this->socialite->shouldReceive('user')->andReturn($this->providerUser);
     $this->app->instance('Laravel\\Socialite\\Contracts\\Factory', $this->socialite);
 }
Exemplo n.º 2
0
 public function testUserIsRegistered()
 {
     $tw_user = new User();
     $tw_user->map(['id' => '123']);
     $mock = Mockery::mock('Laravel\\Socialite\\Contracts\\Factory');
     $mock->shouldReceive('driver')->once()->with('twitter')->andReturnSelf();
     $mock->shouldReceive('user')->once()->andReturn($tw_user);
     $this->app->instance('Laravel\\Socialite\\Contracts\\Factory', $mock);
     $authMock = Mockery::mock('App\\Services\\Authentication');
     $authMock->shouldReceive('loginOrCreateUser')->with($tw_user, 'twitter')->once();
     $this->app->instance('App\\Services\\Authentication', $authMock);
     $this->get('login/twitter/callback');
     $this->assertRedirectedTo('/');
 }
Exemplo n.º 3
0
 public function testUniqueUsername()
 {
     // Insert some test users to
     $this->createUser(['username' => 'Foo Baz']);
     $this->createUser(['username' => 'Bar Foo']);
     $this->createUser(['username' => 'BarFoo']);
     $this->createUser(['username' => 'Bar Baz']);
     $this->createUser(['username' => 'BarBaz']);
     $this->createUser(['username' => 'Bar.Baz']);
     $this->createUser(['username' => 'foo']);
     $this->createUser(['username' => 'bar']);
     $this->createUser(['username' => 'bar 1']);
     $this->createUser(['username' => 'bar 2']);
     $user = new User();
     $user->map(['user' => ['first_name' => '', 'last_name' => '']]);
     $user->name = 'Foo Bar';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('Foo Bar', $socialUser->username);
     $user->name = 'Foo Baz';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('FooBaz', $socialUser->username);
     $user->name = 'Bar Baz';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('Baz Bar', $socialUser->username);
     $this->createUser(['username' => 'Baz Bar']);
     $user->name = 'Bar Baz';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('BBaz', $socialUser->username);
     $user->name = 'Foo';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('Foo 1', $socialUser->username);
     $user->name = 'bar';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('bar 3', $socialUser->username);
 }