|
11 | 11 | use CodeIgniter\Test\FeatureTestTrait; |
12 | 12 | use Config\Services; |
13 | 13 | use Tests\Support\DatabaseTestCase; |
| 14 | +use Tests\Support\FakeUser; |
14 | 15 |
|
15 | 16 | /** |
16 | 17 | * @internal |
17 | 18 | */ |
18 | 19 | final class RegisterTest extends DatabaseTestCase |
19 | 20 | { |
20 | 21 | use FeatureTestTrait; |
| 22 | + use FakeUser; |
21 | 23 |
|
22 | 24 | protected $namespace; |
23 | 25 |
|
@@ -146,6 +148,35 @@ public function testRegisterRedirectsToActionIfDefined(): void |
146 | 148 | ]); |
147 | 149 | } |
148 | 150 |
|
| 151 | + public function testRegisterRedirectsIfLoggedIn(): void |
| 152 | + { |
| 153 | + // log them in |
| 154 | + session()->set('user', ['id' => $this->user->id]); |
| 155 | + |
| 156 | + $result = $this->withSession()->get('/register'); |
| 157 | + |
| 158 | + $result->assertStatus(302); |
| 159 | + $result->assertRedirect(); |
| 160 | + $result->assertRedirectTo(config('Auth')->registerRedirect()); |
| 161 | + } |
| 162 | + |
| 163 | + public function testRegisterActionRedirectsIfLoggedIn(): void |
| 164 | + { |
| 165 | + // log them in |
| 166 | + session()->set('user', ['id' => $this->user->id]); |
| 167 | + |
| 168 | + $result = $this->withSession()->post('/register', [ |
| 169 | + 'username' => 'JohnDoe', |
| 170 | + 'email' => 'john.doe@example.com', |
| 171 | + 'password' => 'secret things might happen here', |
| 172 | + 'password_confirm' => 'secret things might happen here', |
| 173 | + ]); |
| 174 | + |
| 175 | + $result->assertStatus(302); |
| 176 | + $result->assertRedirect(); |
| 177 | + $result->assertRedirectTo(config('Auth')->registerRedirect()); |
| 178 | + } |
| 179 | + |
149 | 180 | protected function setupConfig(): void |
150 | 181 | { |
151 | 182 | $config = config('Validation'); |
|
0 commit comments