Skip to content

Commit

Permalink
Merge pull request #1147 from puschie286/RedirectRouteBaseURL
Browse files Browse the repository at this point in the history
fix RedirectResponse::route and added test
  • Loading branch information
lonnieezell authored Aug 9, 2018
2 parents 8d2f569 + 6e297ac commit 2136bbb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions system/HTTP/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
* @since Version 3.0.0
* @filesource
*/

use CodeIgniter\HTTP\Exceptions\HTTPException;
use Config\App;
use Config\Services;

class RedirectResponse extends Response
Expand Down Expand Up @@ -74,7 +76,7 @@ public function to(string $uri, int $code=null, string $method='auto')
*
* @return $this
*/
public function route(string $route, array $params=[], int $code=null, string $method='auto')
public function route(string $route, array $params=[], int $code=302, string $method='auto')
{
$routes = Services::routes(true);

Expand All @@ -85,7 +87,7 @@ public function route(string $route, array $params=[], int $code=null, string $m
throw HTTPException::forInvalidRedirectRoute($route);
}

return $this->redirect($route, $method, $code);
return $this->redirect( config( App::class )->baseURL.rtrim( $route, '\\' ), $method, $code);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/system/HTTP/RedirectResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

class RedirectResponseTest extends \CIUnitTestCase
{
/** @var RouteCollection */
protected $routes;

protected $request;
Expand Down Expand Up @@ -42,6 +43,18 @@ public function testRedirectToFullURI()
$this->assertEquals('http://example.com/foo', $response->getHeaderLine('Location'));
}

public function testRedirectRoute()
{
$response = new RedirectResponse(new App());

$this->routes->add( 'exampleRoute', 'Home::index' );

$response->route( 'exampleRoute' );

$this->assertTrue($response->hasHeader('Location'));
$this->assertEquals('http://example.com/exampleRoute', $response->getHeaderLine('Location'));
}

public function testRedirectRelativeConvertsToFullURI()
{
$response = new RedirectResponse($this->config);
Expand Down

0 comments on commit 2136bbb

Please sign in to comment.