mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
~ fix RedirectResponse::route unable to call with default/suggested parameter ( docu )
~ fix RedirectResponse::route baseurl was not applied + added test for RedirectResponse::route Signed-off-by: Christoph Potas <christoph286@googlemail.com>
This commit is contained in:
parent
655481298c
commit
6e297acba3
@ -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
|
||||
@ -74,7 +76,7 @@ class RedirectResponse extends Response
|
||||
*
|
||||
* @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);
|
||||
|
||||
@ -85,7 +87,7 @@ class RedirectResponse extends Response
|
||||
throw HTTPException::forInvalidRedirectRoute($route);
|
||||
}
|
||||
|
||||
return $this->redirect($route, $method, $code);
|
||||
return $this->redirect( config( App::class )->baseURL.rtrim( $route, '\\' ), $method, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@ use Tests\Support\HTTP\MockIncomingRequest;
|
||||
|
||||
class RedirectResponseTest extends \CIUnitTestCase
|
||||
{
|
||||
/** @var RouteCollection */
|
||||
protected $routes;
|
||||
|
||||
protected $request;
|
||||
@ -42,6 +43,18 @@ class RedirectResponseTest extends \CIUnitTestCase
|
||||
$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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user