Skip to content

Commit

Permalink
Add test for redirect exception creating a response.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 22, 2016
1 parent 1b10d28 commit cbe2e9e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/TestCase/Routing/Filter/RoutingFilterTest.php
Expand Up @@ -16,6 +16,7 @@

use Cake\Event\Event;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\Filter\RoutingFilter;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
Expand Down Expand Up @@ -68,6 +69,27 @@ public function testBeforeDispatchSetsParameters()
$this->assertFalse(!empty($request['form']));
}

/**
* test setting parameters in beforeDispatch method
*
* @return void
* @triggers __CLASS__ $this, compact(request)
*/
public function testBeforeDispatchRedirectRoute()
{
Router::redirect('/home', ['controller' => 'articles']);
Router::connect('/:controller/:action/*');
$filter = new RoutingFilter();

$request = new Request("/home");
$response = new Response();
$event = new Event(__CLASS__, $this, compact('request', 'response'));
$response = $filter->beforeDispatch($event);
$this->assertInstanceOf('Cake\Network\Response', $response);
$this->assertSame('http://localhost/articles/index', $response->header()['Location']);
$this->assertSame(301, $response->statusCode());
}

/**
* test setting parameters in beforeDispatch method
*
Expand Down

0 comments on commit cbe2e9e

Please sign in to comment.