Browse Source

Port fixes from #15304 to 3.x

Mark Story 5 years ago
parent
commit
7964adf996
2 changed files with 30 additions and 0 deletions
  1. 8 0
      src/Shell/RoutesShell.php
  2. 22 0
      tests/TestCase/Shell/RoutesShellTest.php

+ 8 - 0
src/Shell/RoutesShell.php

@@ -17,6 +17,7 @@ namespace Cake\Shell;
 use Cake\Console\Shell;
 use Cake\Http\ServerRequest;
 use Cake\Routing\Exception\MissingRouteException;
+use Cake\Routing\Exception\RedirectException;
 use Cake\Routing\Router;
 
 /**
@@ -72,6 +73,13 @@ class RoutesShell extends Shell
             ];
             $this->helper('table')->output($output);
             $this->out();
+        } catch (RedirectException $e) {
+           $output = [
+                ['URI template', 'Redirect'],
+                [$url, $e->getMessage()],
+            ];
+            $this->helper('table')->output($output);
+            $this->out();
         } catch (MissingRouteException $e) {
             $this->warn("'$url' did not match any routes.");
             $this->out();

+ 22 - 0
tests/TestCase/Shell/RoutesShellTest.php

@@ -34,6 +34,9 @@ class RoutesShellTest extends ConsoleIntegrationTestCase
         Router::connect('/articles/:action/*', ['controller' => 'Articles']);
         Router::connect('/bake/:controller/:action', ['plugin' => 'Bake']);
         Router::connect('/tests/:action/*', ['controller' => 'Tests'], ['_name' => 'testName']);
+        Router::scope('/', function ($routes) {
+            $routes->redirect('/redirect', 'http://example.com/test.html');
+        });
     }
 
     /**
@@ -133,6 +136,25 @@ class RoutesShellTest extends ConsoleIntegrationTestCase
     }
 
     /**
+     * Test checking an existing route with redirect route.
+     *
+     * @return void
+     */
+    public function testCheckWithRedirectRoute()
+    {
+        $this->exec('routes check /redirect');
+        $this->assertExitCode(Shell::CODE_SUCCESS);
+        $this->assertOutputContainsRow([
+            '<info>URI template</info>',
+            '<info>Redirect</info>',
+        ]);
+        $this->assertOutputContainsRow([
+            '/redirect',
+            'http://example.com/test.html',
+        ]);
+    }
+
+    /**
      * Test generating URLs
      *
      * @return void