ソースを参照

[FrameworkBundle] Fix a bug in the RedirectableUrlMatcher

Victor Berchet 13 年 前
コミット
66d0d3dd4b

+ 2 - 3
src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php

@@ -11,13 +11,12 @@
 
 namespace Symfony\Bundle\FrameworkBundle\Routing;
 
-use Symfony\Component\Routing\Matcher\UrlMatcher;
-use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
+use Symfony\Component\Routing\Matcher\RedirectableUrlMatcher as BaseMatcher;
 
 /**
  * @author Fabien Potencier <fabien@symfony.com>
  */
-class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
+class RedirectableUrlMatcher extends BaseMatcher
 {
     /**
      * Redirects the user to another URL.

+ 61 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RedirectableUrlMatcherTest.php

@@ -0,0 +1,61 @@
+<?php
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Symfony\Bundle\FrameworkBundle\Tests\Routing;
+
+use Symfony\Bundle\FrameworkBundle\Routing\Router;
+use Symfony\Component\Routing\Route;
+use Symfony\Component\Routing\RouteCollection;
+use Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher;
+use Symfony\Component\Routing\RequestContext;
+
+class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase
+{
+    public function testRedirectWhenNoSlash()
+    {
+        $coll = new RouteCollection();
+        $coll->add('foo', new Route('/foo/'));
+
+        $matcher = new RedirectableUrlMatcher($coll, $context = new RequestContext());
+
+        $this->assertEquals(array(
+                '_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction',
+                'path'        => '/foo/',
+                'permanent'   => true,
+                'scheme'      => null,
+                'httpPort'    => $context->getHttpPort(),
+                'httpsPort'   => $context->getHttpsPort(),
+                '_route'      => null,
+            ),
+            $matcher->match('/foo')
+        );
+    }
+
+    public function testSchemeRedirect()
+    {
+        $coll = new RouteCollection();
+        $coll->add('foo', new Route('/foo', array(), array('_scheme' => 'https')));
+
+        $matcher = new RedirectableUrlMatcher($coll, $context = new RequestContext());
+
+        $this->assertEquals(array(
+                '_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction',
+                'path'        => '/foo',
+                'permanent'   => true,
+                'scheme'      => 'https',
+                'httpPort'    => $context->getHttpPort(),
+                'httpsPort'   => $context->getHttpsPort(),
+                '_route'      => 'foo',
+            ),
+            $matcher->match('/foo')
+        );
+    }
+}