LegacyApacheUrlMatcherTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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\Routing\Tests\Matcher;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Routing\Matcher\ApacheUrlMatcher;
  13. use Symfony\Component\Routing\RequestContext;
  14. use Symfony\Component\Routing\RouteCollection;
  15. /**
  16. * @group legacy
  17. */
  18. class LegacyApacheUrlMatcherTest extends TestCase
  19. {
  20. protected $server;
  21. protected function setUp()
  22. {
  23. $this->server = $_SERVER;
  24. }
  25. protected function tearDown()
  26. {
  27. $_SERVER = $this->server;
  28. }
  29. /**
  30. * @dataProvider getMatchData
  31. */
  32. public function testMatch($name, $pathinfo, $server, $expect)
  33. {
  34. $collection = new RouteCollection();
  35. $context = new RequestContext();
  36. $matcher = new ApacheUrlMatcher($collection, $context);
  37. $_SERVER = $server;
  38. $result = $matcher->match($pathinfo);
  39. $this->assertSame(var_export($expect, true), var_export($result, true));
  40. }
  41. public function getMatchData()
  42. {
  43. return array(
  44. array(
  45. 'Simple route',
  46. '/hello/world',
  47. array(
  48. '_ROUTING_route' => 'hello',
  49. '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
  50. '_ROUTING_param_name' => 'world',
  51. ),
  52. array(
  53. '_controller' => 'AcmeBundle:Default:index',
  54. 'name' => 'world',
  55. '_route' => 'hello',
  56. ),
  57. ),
  58. array(
  59. 'Route with params and defaults',
  60. '/hello/hugo',
  61. array(
  62. '_ROUTING_route' => 'hello',
  63. '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
  64. '_ROUTING_param_name' => 'hugo',
  65. '_ROUTING_default_name' => 'world',
  66. ),
  67. array(
  68. 'name' => 'hugo',
  69. '_controller' => 'AcmeBundle:Default:index',
  70. '_route' => 'hello',
  71. ),
  72. ),
  73. array(
  74. 'Route with defaults only',
  75. '/hello',
  76. array(
  77. '_ROUTING_route' => 'hello',
  78. '_ROUTING_param__controller' => 'AcmeBundle:Default:index',
  79. '_ROUTING_default_name' => 'world',
  80. ),
  81. array(
  82. 'name' => 'world',
  83. '_controller' => 'AcmeBundle:Default:index',
  84. '_route' => 'hello',
  85. ),
  86. ),
  87. array(
  88. 'Redirect with many ignored attributes',
  89. '/legacy/{cat1}/{cat2}/{id}.html',
  90. array(
  91. '_ROUTING_route' => 'product_view',
  92. '_ROUTING_param__controller' => 'FrameworkBundle:Redirect:redirect',
  93. '_ROUTING_default_ignoreAttributes[0]' => 'attr_a',
  94. '_ROUTING_default_ignoreAttributes[1]' => 'attr_b',
  95. ),
  96. array(
  97. 'ignoreAttributes' => array('attr_a', 'attr_b'),
  98. '_controller' => 'FrameworkBundle:Redirect:redirect',
  99. '_route' => 'product_view',
  100. ),
  101. ),
  102. array(
  103. 'REDIRECT_ envs',
  104. '/hello/world',
  105. array(
  106. 'REDIRECT__ROUTING_route' => 'hello',
  107. 'REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
  108. 'REDIRECT__ROUTING_param_name' => 'world',
  109. ),
  110. array(
  111. '_controller' => 'AcmeBundle:Default:index',
  112. 'name' => 'world',
  113. '_route' => 'hello',
  114. ),
  115. ),
  116. array(
  117. 'REDIRECT_REDIRECT_ envs',
  118. '/hello/world',
  119. array(
  120. 'REDIRECT_REDIRECT__ROUTING_route' => 'hello',
  121. 'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
  122. 'REDIRECT_REDIRECT__ROUTING_param_name' => 'world',
  123. ),
  124. array(
  125. '_controller' => 'AcmeBundle:Default:index',
  126. 'name' => 'world',
  127. '_route' => 'hello',
  128. ),
  129. ),
  130. array(
  131. 'REDIRECT_REDIRECT_ envs',
  132. '/hello/world',
  133. array(
  134. 'REDIRECT_REDIRECT__ROUTING_route' => 'hello',
  135. 'REDIRECT_REDIRECT__ROUTING_param__controller' => 'AcmeBundle:Default:index',
  136. 'REDIRECT_REDIRECT__ROUTING_param_name' => 'world',
  137. ),
  138. array(
  139. '_controller' => 'AcmeBundle:Default:index',
  140. 'name' => 'world',
  141. '_route' => 'hello',
  142. ),
  143. ),
  144. );
  145. }
  146. }