/Tests/Security/Firewall/FacebookListenerTest.php

http://github.com/FriendsOfSymfony/FOSFacebookBundle · PHP · 91 lines · 56 code · 12 blank · 23 comment · 0 complexity · 6f9e6757365a071a040bd405022b7dce MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of the FOSFacebookBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\FacebookBundle\Tests\Security\Firewall\FacebookListener;
  11. use FOS\FacebookBundle\Security\Firewall\FacebookListener;
  12. class FacebookListenerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @covers FOS\FacebookBundle\Security\Firewall\FacebookListener::attemptAuthentication
  16. */
  17. public function testThatCanAttemptAuthenticationWithFacebook()
  18. {
  19. $listener = new FacebookListener(
  20. $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'),
  21. $this->getAuthenticationManager(),
  22. $this->getMock('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface'),
  23. $this->getHttpUtils(),
  24. 'providerKey',
  25. $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface'),
  26. $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface')
  27. );
  28. $listener->handle($this->getResponseEvent());
  29. }
  30. /**
  31. * @return Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface
  32. */
  33. private function getAuthenticationManager()
  34. {
  35. $authenticationManagerMock = $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
  36. $authenticationManagerMock->expects($this->once())
  37. ->method('authenticate')
  38. ->with($this->isInstanceOf('FOS\FacebookBundle\Security\Authentication\Token\FacebookUserToken'));
  39. return $authenticationManagerMock;
  40. }
  41. /**
  42. * @return Symfony\Component\Security\Http\HttpUtils
  43. */
  44. private function getHttpUtils()
  45. {
  46. $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
  47. $httpUtils->expects($this->once())
  48. ->method('checkRequestPath')
  49. ->will($this->returnValue(true));
  50. return $httpUtils;
  51. }
  52. /**
  53. * @return Symfony\Component\HttpKernel\Event\GetResponseEvent
  54. */
  55. private function getResponseEvent()
  56. {
  57. $responseEventMock = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array('getRequest'), array(), '', false);
  58. $responseEventMock->expects($this->any())
  59. ->method('getRequest')
  60. ->will($this->returnValue($this->getRequest()));
  61. return $responseEventMock;
  62. }
  63. /**
  64. * @return Symfony\Component\HttpFoundation\Request
  65. */
  66. private function getRequest()
  67. {
  68. $requestMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
  69. ->disableOriginalClone()
  70. ->getMock();
  71. $requestMock->expects($this->any())
  72. ->method('hasSession')
  73. ->will($this->returnValue('true'));
  74. $requestMock->expects($this->any())
  75. ->method('hasPreviousSession')
  76. ->will($this->returnValue('true'));
  77. return $requestMock;
  78. }
  79. }