|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Tests\Routing; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Bundle\FrameworkBundle\Routing\RedirectableCompiledUrlMatcher; |
| 16 | +use Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper; |
| 17 | +use Symfony\Component\Routing\RequestContext; |
| 18 | +use Symfony\Component\Routing\Route; |
| 19 | +use Symfony\Component\Routing\RouteCollection; |
| 20 | + |
| 21 | +/** |
| 22 | + * @requires function \Symfony\Component\Routing\Matcher\CompiledUrlMatcher::match |
| 23 | + */ |
| 24 | +class RedirectableCompiledUrlMatcherTest extends TestCase |
| 25 | +{ |
| 26 | + public function testRedirectWhenNoSlash() |
| 27 | + { |
| 28 | + $routes = new RouteCollection(); |
| 29 | + $routes->add('foo', new Route('/foo/')); |
| 30 | + |
| 31 | + $matcher = $this->getMatcher($routes, $context = new RequestContext()); |
| 32 | + |
| 33 | + $this->assertEquals([ |
| 34 | + '_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', |
| 35 | + 'path' => '/foo/', |
| 36 | + 'permanent' => true, |
| 37 | + 'scheme' => null, |
| 38 | + 'httpPort' => $context->getHttpPort(), |
| 39 | + 'httpsPort' => $context->getHttpsPort(), |
| 40 | + '_route' => 'foo', |
| 41 | + ], |
| 42 | + $matcher->match('/foo') |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + public function testSchemeRedirect() |
| 47 | + { |
| 48 | + $routes = new RouteCollection(); |
| 49 | + $routes->add('foo', new Route('/foo', [], [], [], '', ['https'])); |
| 50 | + |
| 51 | + $matcher = $this->getMatcher($routes, $context = new RequestContext()); |
| 52 | + |
| 53 | + $this->assertEquals([ |
| 54 | + '_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', |
| 55 | + 'path' => '/foo', |
| 56 | + 'permanent' => true, |
| 57 | + 'scheme' => 'https', |
| 58 | + 'httpPort' => $context->getHttpPort(), |
| 59 | + 'httpsPort' => $context->getHttpsPort(), |
| 60 | + '_route' => 'foo', |
| 61 | + ], |
| 62 | + $matcher->match('/foo') |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + private function getMatcher(RouteCollection $routes, RequestContext $context) |
| 67 | + { |
| 68 | + $dumper = new CompiledUrlMatcherDumper($routes); |
| 69 | + |
| 70 | + return new RedirectableCompiledUrlMatcher($dumper->getCompiledRoutes(), $context); |
| 71 | + } |
| 72 | +} |
0 commit comments