FormAuthenticationEntryPointTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Symfony\Tests\Component\Security\Http\EntryPoint;
  3. use Symfony\Component\Security\Http\EntryPoint\FormAuthenticationEntryPoint;
  4. use Symfony\Component\HttpKernel\HttpKernelInterface;
  5. class FormAuthenticationEntryPointTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function testStart()
  8. {
  9. $request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
  10. $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
  11. $httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
  12. $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
  13. $httpUtils
  14. ->expects($this->once())
  15. ->method('createRedirectResponse')
  16. ->with($this->equalTo($request), $this->equalTo('/the/login/path'))
  17. ->will($this->returnValue($response))
  18. ;
  19. $entryPoint = new FormAuthenticationEntryPoint($httpKernel, $httpUtils, '/the/login/path', false);
  20. $this->assertEquals($response, $entryPoint->start($request));
  21. }
  22. public function testStartWithUseForward()
  23. {
  24. $request = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
  25. $subRequest = $this->getMock('Symfony\Component\HttpFoundation\Request', array(), array(), '', false, false);
  26. $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
  27. $httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
  28. $httpUtils
  29. ->expects($this->once())
  30. ->method('createRequest')
  31. ->with($this->equalTo($request), $this->equalTo('/the/login/path'))
  32. ->will($this->returnValue($subRequest))
  33. ;
  34. $httpKernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
  35. $httpKernel
  36. ->expects($this->once())
  37. ->method('handle')
  38. ->with($this->equalTo($request), $this->equalTo(HttpKernelInterface::SUB_REQUEST))
  39. ->will($this->returnValue($response))
  40. ;
  41. $entryPoint = new FormAuthenticationEntryPoint($httpKernel, $httpUtils, '/the/login/path', true);
  42. $this->assertEquals($response, $entryPoint->start($request));
  43. }
  44. }