Skip to content

Commit bb58cfd

Browse files
[5.x] Revert "Escape start_page Preference to avoid invalid Redirect" (statamic#11651)
* Revert "[5.x] Escape start_page Preference to avoid invalid Redirect (statamic#11616)" This reverts commit b4b7875. * Add test
1 parent 07ad39b commit bb58cfd

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Diff for: src/Http/Controllers/CP/StartPageController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function __invoke()
1010
{
1111
session()->reflash();
1212

13-
$url = config('statamic.cp.route').'/'.urlencode(Preference::get('start_page', config('statamic.cp.start_page')));
13+
$url = config('statamic.cp.route').'/'.Preference::get('start_page', config('statamic.cp.start_page'));
1414

1515
return redirect($url);
1616
}

Diff for: tests/CP/StartPageTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace CP;
4+
5+
use PHPUnit\Framework\Attributes\Test;
6+
use Statamic\Facades\File;
7+
use Statamic\Facades\Preference;
8+
use Statamic\Facades\User;
9+
use Tests\PreventSavingStacheItemsToDisk;
10+
use Tests\TestCase;
11+
12+
class StartPageTest extends TestCase
13+
{
14+
use PreventSavingStacheItemsToDisk;
15+
16+
protected function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
File::delete(resource_path('preferences.yaml'));
21+
}
22+
23+
#[Test]
24+
public function it_uses_start_page_preference()
25+
{
26+
config('statamic.cp.start_page', 'dashboard');
27+
28+
Preference::default()->setPreference('start_page', 'collections/pages')->save();
29+
30+
$this
31+
->actingAs(User::make()->makeSuper()->save())
32+
->get('/cp')
33+
->assertRedirect('/cp/collections/pages');
34+
}
35+
36+
#[Test]
37+
public function it_falls_back_to_start_page_config_option_when_preference_is_missing()
38+
{
39+
config('statamic.cp.start_page', 'dashboard');
40+
41+
$this
42+
->actingAs(User::make()->makeSuper()->save())
43+
->get('/cp')
44+
->assertRedirect('/cp/dashboard');
45+
}
46+
}

0 commit comments

Comments
 (0)