/**
  * @covers FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider::authenticate
  * @covers FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider::createAuthenticatedToken
  */
 public function testThatCanAutenticateUsingUserProvider()
 {
     $userMock = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
     $userMock->expects($this->once())->method('getUsername')->will($this->returnValue('l3l0'));
     $userMock->expects($this->once())->method('getRoles')->will($this->returnValue(array()));
     $facebookMock = $this->getMock('\\BaseFacebook', array('getUser'));
     $facebookMock->expects($this->once())->method('getUser')->will($this->returnValue('123'));
     $userProviderMock = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
     $userProviderMock->expects($this->once())->method('loadUserByUsername')->with('123')->will($this->returnValue($userMock));
     $userCheckerMock = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface');
     $userCheckerMock->expects($this->once())->method('checkPreAuth');
     $userCheckerMock->expects($this->once())->method('checkPostAuth');
     $tokenMock = $this->getMock('FOS\\FacebookBundle\\Security\\Authentication\\Token\\FacebookUserToken');
     $facebookProvider = new FacebookProvider($facebookMock, $userProviderMock, $userCheckerMock);
     $this->assertEquals('l3l0', $facebookProvider->authenticate($tokenMock)->getUsername());
 }
 /**
  * @covers FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider::authenticate
  * @covers FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider::createAuthenticatedToken
  */
 public function testThatCanAutenticateUsingUserProvider()
 {
     $providerKey = 'main';
     $userMock = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
     $userMock->expects($this->once())->method('getUsername')->will($this->returnValue('l3l0'));
     $userMock->expects($this->once())->method('getRoles')->will($this->returnValue(array()));
     $facebookMock = $this->getMockBuilder('FOS\\FacebookBundle\\Facebook\\FacebookSessionPersistence')->disableOriginalConstructor()->setMethods(array('getUser'))->getMock();
     $facebookMock->expects($this->once())->method('getUser')->will($this->returnValue('123'));
     $userProviderMock = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
     $userProviderMock->expects($this->once())->method('loadUserByUsername')->with('123')->will($this->returnValue($userMock));
     $userCheckerMock = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface');
     $userCheckerMock->expects($this->once())->method('checkPostAuth');
     $tokenMock = $this->getMock('FOS\\FacebookBundle\\Security\\Authentication\\Token\\FacebookUserToken', array('getAttributes', 'getProviderKey'), array($providerKey));
     $tokenMock->expects($this->once())->method('getAttributes')->will($this->returnValue(array()));
     $tokenMock->expects($this->any())->method('getProviderKey')->will($this->returnValue($providerKey));
     $facebookProvider = new FacebookProvider($providerKey, $facebookMock, $userProviderMock, $userCheckerMock);
     $this->assertEquals('l3l0', $facebookProvider->authenticate($tokenMock)->getUsername());
 }
 /**
  * @covers FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider::authenticate
  * @covers FOS\FacebookBundle\Security\Authentication\Provider\FacebookProvider::createAuthenticatedToken
  */
 public function testThatAccessTokenIsSetToNewFacebookUserTokenWhenAuthenticateWithoutUserProvider()
 {
     $providerKey = 'main';
     $accessToken = 'AbCd';
     $facebookMock = $this->getMockBuilder('FOS\\FacebookBundle\\Facebook\\FacebookSessionPersistence')->disableOriginalConstructor()->setMethods(array('getUser'))->getMock();
     $facebookMock->expects($this->once())->method('getUser')->will($this->returnValue('123'));
     $facebookProvider = new FacebookProvider($providerKey, $facebookMock);
     $tokenMock = $this->getMock('FOS\\FacebookBundle\\Security\\Authentication\\Token\\FacebookUserToken', array('getAttributes', 'getProviderKey'), array($providerKey, '', array(), $accessToken));
     $tokenMock->expects($this->once())->method('getAttributes')->will($this->returnValue(array()));
     $tokenMock->expects($this->any())->method('getProviderKey')->will($this->returnValue($providerKey));
     $this->assertEquals($accessToken, $facebookProvider->authenticate($tokenMock)->getAccessToken());
 }