'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([ 'Route name', 'URI template', 'Defaults' ]); $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([ 'Route name', 'URI template', 'Defaults' ]); $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([ 'Route name', 'URI template', 'Defaults' ]); $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'); } }