Пример #1
0
 /** @test */
 public function it_can_retrieve_authorize_urls_for_providers()
 {
     $providerRegistry = new ProviderRegistry();
     $session = M::mock('SocialNorm\\Session')->shouldIgnoreMissing();
     $authorizeUrl = 'http://example.com/authorize';
     $provider = new ProviderStub($authorizeUrl, M::mock('SocialNorm\\User'));
     $socialNorm = new SocialNorm($providerRegistry, $session, Request::createFromGlobals(), new StateGenerator());
     $socialNorm->registerProvider('foo', $provider);
     $this->assertStringStartsWith($authorizeUrl, $socialNorm->authorize('foo'));
 }
 /** @test */
 public function it_works()
 {
     $authorizeUrl = 'http://example.com/authorize';
     $user = M::mock('SocialNorm\\User');
     $provider = new ProviderStub($authorizeUrl, $user);
     $session = new InMemorySession();
     // Simulate first request
     $socialNorm = new SocialNorm(new ProviderRegistry(), $session, new Request([]), new StateGenerator());
     $socialNorm->registerProvider('foo', $provider);
     $returnedUrl = $socialNorm->authorize('foo');
     $this->assertStringStartsWith($authorizeUrl, $returnedUrl);
     // Simulate second request
     $state = $this->parseStateFromUrl($returnedUrl);
     $socialNorm = new SocialNorm(new ProviderRegistry(), $session, new Request(['state' => $state]), new StateGenerator());
     $socialNorm->registerProvider('foo', $provider);
     $returnedUser = $socialNorm->getUser('foo');
     $this->assertEquals($user, $returnedUser);
 }