RetryAuthenticationEntryPointTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Security\Http\Tests\EntryPoint;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Security\Http\EntryPoint\RetryAuthenticationEntryPoint;
  14. class RetryAuthenticationEntryPointTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider dataForStart
  18. */
  19. public function testStart($httpPort, $httpsPort, $request, $expectedUrl)
  20. {
  21. $entryPoint = new RetryAuthenticationEntryPoint($httpPort, $httpsPort);
  22. $response = $entryPoint->start($request);
  23. $this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
  24. $this->assertEquals($expectedUrl, $response->headers->get('Location'));
  25. }
  26. public function dataForStart()
  27. {
  28. if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
  29. return array(array());
  30. }
  31. return array(
  32. array(
  33. 80,
  34. 443,
  35. Request::create('http://localhost/foo/bar?baz=bat'),
  36. 'https://localhost/foo/bar?baz=bat',
  37. ),
  38. array(
  39. 80,
  40. 443,
  41. Request::create('https://localhost/foo/bar?baz=bat'),
  42. 'http://localhost/foo/bar?baz=bat',
  43. ),
  44. array(
  45. 80,
  46. 123,
  47. Request::create('http://localhost/foo/bar?baz=bat'),
  48. 'https://localhost:123/foo/bar?baz=bat',
  49. ),
  50. array(
  51. 8080,
  52. 443,
  53. Request::create('https://localhost/foo/bar?baz=bat'),
  54. 'http://localhost:8080/foo/bar?baz=bat',
  55. ),
  56. );
  57. }
  58. }