Browse Source

Add a test for #12295

Mark Story 7 years ago
parent
commit
acc11336a3
1 changed files with 21 additions and 0 deletions
  1. 21 0
      tests/TestCase/Routing/Route/RedirectRouteTest.php

+ 21 - 0
tests/TestCase/Routing/Route/RedirectRouteTest.php

@@ -14,6 +14,7 @@
  */
 namespace Cake\Test\TestCase\Routing\Route;
 
+use Cake\Http\ServerRequest;
 use Cake\Routing\Router;
 use Cake\Routing\Route\RedirectRoute;
 use Cake\TestSuite\TestCase;
@@ -146,6 +147,26 @@ class RedirectRouteTest extends TestCase
     }
 
     /**
+     * test redirecting with persist and a base directory
+     *
+     * @return void
+     */
+    public function testParsePersistBaseDirectory()
+    {
+        $request = new ServerRequest([
+            'base' => '/basedir',
+            'url' => '/posts/2'
+        ]);
+        Router::pushRequest($request);
+
+        $this->expectException(\Cake\Routing\Exception\RedirectException::class);
+        $this->expectExceptionMessage('http://localhost/basedir/posts/view/2');
+        $this->expectExceptionCode(301);
+        $route = new RedirectRoute('/posts/*', ['controller' => 'posts', 'action' => 'view'], ['persist' => true]);
+        $route->parse('/posts/2');
+    }
+
+    /**
      * test redirecting with persist and string target URLs
      *
      * @return void