Skip to content

Commit d722282

Browse files
committed
Add test to generate a signed route
1 parent 25edcc7 commit d722282

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tests/Unit/UrlGeneratorTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use CodeZero\LocalizedRoutes\Tests\TestCase;
88
use CodeZero\LocalizedRoutes\UrlGenerator;
99
use Config;
10+
use Illuminate\Support\Facades\URL;
1011
use InvalidArgumentException;
1112
use Route;
1213

@@ -21,10 +22,10 @@ protected function setUp(): void
2122
App::setLocale('en');
2223
}
2324

24-
protected function registerRoute($url, $name)
25+
protected function registerRoute($url, $name, $callback = null)
2526
{
2627
Route::getRoutes()->add(
27-
Route::name($name)->get($url, function () use ($name) { return $name; })
28+
Route::name($name)->get($url, $callback ?: function () {})
2829
);
2930
}
3031

@@ -128,4 +129,23 @@ public function it_temporarily_changes_the_app_locale_when_generating_a_route_ur
128129
$this->assertEquals(url('en/route/en-slug'), route('route.name', [new Model], true, 'en'));
129130
$this->assertEquals(url('nl/route/nl-slug'), route('route.name', [new Model], true, 'nl'));
130131
}
132+
133+
/** @test */
134+
public function it_generates_a_localized_signed_route_url()
135+
{
136+
$callback = function () {
137+
return request()->hasValidSignature()
138+
? 'Valid Signature'
139+
: 'Invalid Signature';
140+
};
141+
142+
$this->registerRoute('en/route', 'en.route.name', $callback);
143+
$this->registerRoute('en/other/route', 'en.other.route.name', $callback);
144+
145+
$validUrl = URL::signedRoute('route.name');
146+
$tamperedUrl = str_replace('en/route', 'en/other/route', $validUrl);
147+
148+
$this->get($validUrl)->assertSee('Valid Signature');
149+
$this->get($tamperedUrl)->assertSee('Invalid Signature');
150+
}
131151
}

0 commit comments

Comments
 (0)