ApacheUrlMatcherTest.php 5.1 KB

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