Esempio n. 1
0
 /** @test */
 public function authenticate_with_oauth1_with_unlinked_non_existent_user()
 {
     $manager = $this->mockManager('make');
     $user = m::mock('Cartalyst\\Sentinel\\Users\\UserInterface');
     $manager->shouldReceive('make')->with('foo', 'http://example.com/callback')->once()->andReturn($provider = m::mock('League\\OAuth1\\Client\\Server\\Server'));
     // Request proxy
     $this->requestProvider->shouldReceive('getOAuth1TemporaryCredentialsIdentifier')->once()->andReturn('identifier');
     $this->requestProvider->shouldReceive('getOAuth1Verifier')->once()->andReturn('verifier');
     // Mock retrieving credentials from the underlying package
     $this->session->shouldReceive('get')->andReturn($temporaryCredentials = m::mock('League\\OAuth1\\Client\\Credentials\\TemporaryCredentials'));
     $provider->shouldReceive('getTokenCredentials')->with($temporaryCredentials, 'identifier', 'verifier')->once()->andReturn($tokenCredentials = m::mock('League\\OAuth1\\Client\\Credentials\\TokenCredentials'));
     // Unique ID
     $provider->shouldReceive('getUserUid')->once()->andReturn(789);
     // Finding an appropriate link
     $this->linkRepository->shouldReceive('findLink')->with('foo', 789)->once()->andReturn($link = m::mock('Cartalyst\\Sentinel\\Addons\\Social\\Models\\LinkInterface'));
     $link->shouldReceive('storeToken')->with($tokenCredentials)->once();
     $this->sentinel->shouldReceive('getUser')->once();
     $link->shouldReceive('getUser')->once();
     $link->shouldReceive('getUser')->once()->andReturn($user);
     $link->shouldReceive('setUser')->with($user)->once();
     $provider->shouldReceive('getUserEmail')->once()->andReturn('*****@*****.**');
     $this->sentinel->shouldReceive('findByCredentials')->with(['login' => '*****@*****.**'])->once();
     $this->sentinel->shouldReceive('getUserRepository')->once()->andReturn($users = m::mock('Cartalyst\\Sentinel\\Users\\UserRepositoryInterface'));
     $users->shouldReceive('createModel')->once()->andReturn($user);
     $provider->shouldReceive('getUserScreenName')->once()->andReturn(['Ben', 'Corlett']);
     $this->sentinel->shouldReceive('registerAndActivate')->once()->andReturn($user);
     $this->sentinel->shouldReceive('authenticate')->with($user, true)->once()->andReturn($user);
     $manager->registering(function ($link, $provider, $token, $slug) {
         $_SERVER['__sentinel_social_registering'] = true;
     });
     $manager->registered(function ($link, $provider, $token, $slug) {
         $_SERVER['__sentinel_social_registered'] = true;
     });
     $user = $manager->authenticate('foo', 'http://example.com/callback', function () {
         $_SERVER['__sentinel_social_linking'] = func_get_args();
     }, true);
     $this->assertTrue(isset($_SERVER['__sentinel_social_registering']));
     $this->assertTrue(isset($_SERVER['__sentinel_social_registered']));
     $this->assertTrue(isset($_SERVER['__sentinel_social_linking']));
     $eventArgs = $_SERVER['__sentinel_social_linking'];
     unset($_SERVER['__sentinel_social_registering']);
     unset($_SERVER['__sentinel_social_registered']);
     unset($_SERVER['__sentinel_social_linking']);
     $this->assertCount(4, $eventArgs);
     list($_link, $_provider, $_tokenCredentials, $_slug) = $eventArgs;
     $this->assertEquals($link, $_link);
     $this->assertEquals($provider, $_provider);
     $this->assertEquals($tokenCredentials, $_tokenCredentials);
     $this->assertEquals('foo', $_slug);
 }