ApacheRequestTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\HttpFoundation\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\ApacheRequest;
  13. class ApacheRequestTest extends TestCase
  14. {
  15. /**
  16. * @dataProvider provideServerVars
  17. */
  18. public function testUriMethods($server, $expectedRequestUri, $expectedBaseUrl, $expectedPathInfo)
  19. {
  20. $request = new ApacheRequest();
  21. $request->server->replace($server);
  22. $this->assertEquals($expectedRequestUri, $request->getRequestUri(), '->getRequestUri() is correct');
  23. $this->assertEquals($expectedBaseUrl, $request->getBaseUrl(), '->getBaseUrl() is correct');
  24. $this->assertEquals($expectedPathInfo, $request->getPathInfo(), '->getPathInfo() is correct');
  25. }
  26. public function provideServerVars()
  27. {
  28. return [
  29. [
  30. [
  31. 'REQUEST_URI' => '/foo/app_dev.php/bar',
  32. 'SCRIPT_NAME' => '/foo/app_dev.php',
  33. 'PATH_INFO' => '/bar',
  34. ],
  35. '/foo/app_dev.php/bar',
  36. '/foo/app_dev.php',
  37. '/bar',
  38. ],
  39. [
  40. [
  41. 'REQUEST_URI' => '/foo/bar',
  42. 'SCRIPT_NAME' => '/foo/app_dev.php',
  43. ],
  44. '/foo/bar',
  45. '/foo',
  46. '/bar',
  47. ],
  48. [
  49. [
  50. 'REQUEST_URI' => '/app_dev.php/foo/bar',
  51. 'SCRIPT_NAME' => '/app_dev.php',
  52. 'PATH_INFO' => '/foo/bar',
  53. ],
  54. '/app_dev.php/foo/bar',
  55. '/app_dev.php',
  56. '/foo/bar',
  57. ],
  58. [
  59. [
  60. 'REQUEST_URI' => '/foo/bar',
  61. 'SCRIPT_NAME' => '/app_dev.php',
  62. ],
  63. '/foo/bar',
  64. '',
  65. '/foo/bar',
  66. ],
  67. [
  68. [
  69. 'REQUEST_URI' => '/app_dev.php',
  70. 'SCRIPT_NAME' => '/app_dev.php',
  71. ],
  72. '/app_dev.php',
  73. '/app_dev.php',
  74. '/',
  75. ],
  76. [
  77. [
  78. 'REQUEST_URI' => '/',
  79. 'SCRIPT_NAME' => '/app_dev.php',
  80. ],
  81. '/',
  82. '',
  83. '/',
  84. ],
  85. ];
  86. }
  87. }