No Description

LegacyApacheUrlMatcherTest.php 5.2KB

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