ApacheRequestTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 array(
  29. array(
  30. array(
  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. array(
  40. array(
  41. 'REQUEST_URI' => '/foo/bar',
  42. 'SCRIPT_NAME' => '/foo/app_dev.php',
  43. ),
  44. '/foo/bar',
  45. '/foo',
  46. '/bar',
  47. ),
  48. array(
  49. array(
  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. array(
  59. array(
  60. 'REQUEST_URI' => '/foo/bar',
  61. 'SCRIPT_NAME' => '/app_dev.php',
  62. ),
  63. '/foo/bar',
  64. '',
  65. '/foo/bar',
  66. ),
  67. array(
  68. array(
  69. 'REQUEST_URI' => '/app_dev.php',
  70. 'SCRIPT_NAME' => '/app_dev.php',
  71. ),
  72. '/app_dev.php',
  73. '/app_dev.php',
  74. '/',
  75. ),
  76. array(
  77. array(
  78. 'REQUEST_URI' => '/',
  79. 'SCRIPT_NAME' => '/app_dev.php',
  80. ),
  81. '/',
  82. '',
  83. '/',
  84. ),
  85. );
  86. }
  87. }