| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- /**
- * CakePHP : Rapid Development Framework (https://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @link https://cakephp.org CakePHP Project
- * @since 3.1.0
- * @license https://opensource.org/licenses/mit-license.php MIT License
- */
- namespace Cake\Test\TestCase\Shell;
- use Cake\Console\Shell;
- use Cake\Routing\Router;
- use Cake\TestSuite\ConsoleIntegrationTestCase;
- /**
- * RoutesShellTest
- */
- class RoutesShellTest extends ConsoleIntegrationTestCase
- {
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp()
- {
- parent::setUp();
- Router::connect('/articles/:action/*', ['controller' => 'Articles']);
- Router::connect('/bake/:controller/:action', ['plugin' => 'Bake']);
- Router::connect('/tests/:action/*', ['controller' => 'Tests'], ['_name' => 'testName']);
- }
- /**
- * tearDown
- *
- * @return void
- */
- public function tearDown()
- {
- parent::tearDown();
- Router::reload();
- }
- /**
- * Test checking an non-existing route.
- *
- * @return void
- */
- public function testMain()
- {
- $this->exec('routes');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContainsRow([
- '<info>Route name</info>',
- '<info>URI template</info>',
- '<info>Defaults</info>'
- ]);
- $this->assertOutputContainsRow([
- 'articles:_action',
- '/articles/:action/*',
- '{"controller":"Articles","action":"index","plugin":null}'
- ]);
- $this->assertOutputContainsRow([
- 'bake._controller:_action',
- '/bake/:controller/:action',
- '{"plugin":"Bake","action":"index"}'
- ]);
- $this->assertOutputContainsRow([
- 'testName',
- '/tests/:action/*',
- '{"controller":"Tests","action":"index","plugin":null}'
- ]);
- }
- /**
- * Test checking an existing route.
- *
- * @return void
- */
- public function testCheck()
- {
- $this->exec('routes check /articles/check');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContainsRow([
- '<info>Route name</info>',
- '<info>URI template</info>',
- '<info>Defaults</info>'
- ]);
- $this->assertOutputContainsRow([
- 'articles:_action',
- '/articles/check',
- '{"action":"check","pass":[],"controller":"Articles","plugin":null}'
- ]);
- }
- /**
- * Test checking an existing route with named route.
- *
- * @return void
- */
- public function testCheckWithNamedRoute()
- {
- $this->exec('routes check /tests/index');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContainsRow([
- '<info>Route name</info>',
- '<info>URI template</info>',
- '<info>Defaults</info>'
- ]);
- $this->assertOutputContainsRow([
- 'testName',
- '/tests/index',
- '{"action":"index","pass":[],"controller":"Tests","plugin":null,"_name":"testName"}'
- ]);
- }
- /**
- * Test checking an non-existing route.
- *
- * @return void
- */
- public function testCheckNotFound()
- {
- $this->exec('routes check /nope');
- $this->assertExitCode(Shell::CODE_ERROR);
- $this->assertErrorContains('did not match');
- }
- /**
- * Test generating URLs
- *
- * @return void
- */
- public function testGenerateNoPassArgs()
- {
- $this->exec('routes generate controller:Articles action:index');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContains('> /articles/index');
- $this->assertErrorEmpty();
- }
- /**
- * Test generating URLs with passed arguments
- *
- * @return void
- */
- public function testGeneratePassedArguments()
- {
- $this->exec('routes generate controller:Articles action:view 2 3');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContains('> /articles/view/2/3');
- $this->assertErrorEmpty();
- }
- /**
- * Test generating URLs with bool params
- *
- * @return void
- */
- public function testGenerateBoolParams()
- {
- $this->exec('routes generate controller:Articles action:index _ssl:true _host:example.com');
- $this->assertExitCode(Shell::CODE_SUCCESS);
- $this->assertOutputContains('> https://example.com/articles/index');
- }
- /**
- * Test generating URLs
- *
- * @return void
- */
- public function testGenerateMissing()
- {
- $this->exec('routes generate controller:Derp');
- $this->assertExitCode(Shell::CODE_ERROR);
- $this->assertErrorContains('do not match');
- }
- }
|