-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass route params to
redirect
tag (#3801)
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace Tests\Tags; | ||
|
||
use Illuminate\Http\Exceptions\HttpResponseException; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Route; | ||
use Statamic\Facades\Parse; | ||
use Statamic\Facades\Site; | ||
use Tests\TestCase; | ||
|
||
class RedirectTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Site::setConfig(['sites' => [ | ||
'en' => ['url' => '/'], | ||
'fr' => ['url' => '/fr'], | ||
]]); | ||
} | ||
|
||
protected function resolveApplicationConfiguration($app) | ||
{ | ||
parent::resolveApplicationConfiguration($app); | ||
|
||
$app->booted(function () { | ||
Route::statamic('/named-route', 'test')->name('named-route'); | ||
|
||
Route::statamic('/route-with-params/{foo}/baz', 'test')->name('param-route'); | ||
}); | ||
} | ||
|
||
private function tag($tag, $data = []) | ||
{ | ||
return (string) Parse::template($tag, $data); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_http_response_exception() | ||
{ | ||
$this->expectException(HttpResponseException::class); | ||
$this->tag('{{ redirect to="/foo" }}'); | ||
} | ||
|
||
/** @test */ | ||
public function it_redirects_to() | ||
{ | ||
try { | ||
$this->tag('{{ redirect to="/foo" }}'); | ||
} catch (HttpResponseException $e) { | ||
$response = $e->getResponse(); | ||
$this->assertInstanceOf(RedirectResponse::class, $response); | ||
$this->assertEquals('http://localhost/foo', $response->getTargetUrl()); | ||
} | ||
} | ||
|
||
/** @test */ | ||
public function it_redirects_to_route() | ||
{ | ||
try { | ||
$this->tag('{{ redirect route="named-route" }}'); | ||
} catch (HttpResponseException $e) { | ||
$response = $e->getResponse(); | ||
$this->assertEquals('http://localhost/named-route', $response->getTargetUrl()); | ||
} | ||
} | ||
|
||
/** @test */ | ||
public function it_redirects_to_route_with_query_params() | ||
{ | ||
try { | ||
$this->tag('{{ redirect route="param-route" foo="bar" }}'); | ||
} catch (HttpResponseException $e) { | ||
$response = $e->getResponse(); | ||
$this->assertEquals('http://localhost/route-with-params/bar/baz', $response->getTargetUrl()); | ||
} | ||
} | ||
} |