Ejemplo n.º 1
0
 public function testCredentialStrategy()
 {
     $strat = $this->getMock('Trismegiste\\SocialBundle\\Security\\Credential\\Strategy');
     $this->sut->setCredential($strat);
     $this->assertEquals($strat, $this->sut->getCredential());
     $this->sut->eraseCredentials();
     // for CC
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Netizen from mandatory datas
  *
  * @param string $nick
  * @param string $OauthProviderKey the key of the OAuth provider (github,facebook,twitter...)
  * @param string $uniqueUserId the unique id of the user given by the OAuth provider
  *
  * @return \Trismegiste\SocialBundle\Security\Netizen
  */
 public function create($nick, $OauthProviderKey, $uniqueUserId)
 {
     $author = new Author($nick);
     $user = new Netizen($author);
     $strat = new Credential\OAuth($uniqueUserId, $OauthProviderKey);
     $user->setCredential($strat);
     $user->setProfile(new Profile());
     $user->setGroup('ROLE_USER');
     return $user;
 }
 /**
  * @dataProvider getUser
  */
 public function testRedirect($granted, $path)
 {
     $default = new Netizen(new Author('kirk'));
     $default->setCredential(new OAuth('1701', 'ufp'));
     $request = new Request();
     $token = new Token('secured_area', 'ufp', '1701');
     $token->setUser($default);
     $this->security->expects($this->atLeast(1))->method('isGranted')->will($this->returnCallback(function ($role) use($granted) {
         return $role == $granted;
     }));
     $this->urlGenerator->expects($this->once())->method('generate')->with($path)->willReturn('ok');
     $response = $this->sut->onAuthenticationSuccess($request, $token);
     $cookie = $response->headers->getCookies()[0];
     $this->assertEquals('oauth_provider', $cookie->getName());
     $this->assertEquals('ufp', $cookie->getValue());
 }