|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +/** |
| 4 | + * Functional tests for Magic Login login form. |
| 5 | + */ |
| 6 | + |
3 | 7 | namespace creode\magiclogintests\acceptance; |
4 | 8 |
|
5 | 9 | use Craft; |
|
8 | 12 | use craft\elements\User; |
9 | 13 | use creode\magiclogin\records\AuthRecord; |
10 | 14 |
|
| 15 | +/** |
| 16 | + * Tests the Magic Login frontend login form workflow. |
| 17 | + */ |
11 | 18 | class LoginFormTest extends BaseFunctionalTest |
12 | 19 | { |
13 | 20 | /** |
| 21 | + * Functional test actor. |
| 22 | + * |
14 | 23 | * @var \FunctionalTester |
15 | 24 | */ |
16 | 25 | protected $tester; |
@@ -200,8 +209,44 @@ public function testSuccessfulLogin() |
200 | 209 | $this->assertEquals($emailSubject, $magicLoginEmail->getSubject()); |
201 | 210 | } |
202 | 211 |
|
| 212 | + /** |
| 213 | + * Tests that the magicLoginRedirectUrl POST param is persisted on the auth record, |
| 214 | + * and will be used after the user clicks their magic link. |
| 215 | + * |
| 216 | + * @return void |
| 217 | + */ |
| 218 | + public function testSuccessfulLoginPersistsProvidedRedirectUrl() |
| 219 | + { |
| 220 | + $validUser = User::findOne(); |
| 221 | + |
| 222 | + AuthRecord::deleteAll(); |
| 223 | + |
| 224 | + $authRecords = AuthRecord::find()->all(); |
| 225 | + |
| 226 | + $targetRedirect = '/after-magic-login'; |
| 227 | + |
| 228 | + $this->tester->amOnPage('/magic-login/login'); |
| 229 | + $this->tester->submitForm( |
| 230 | + '#magic-login-form', |
| 231 | + [ |
| 232 | + 'email' => $validUser->email, |
| 233 | + 'magicLoginRedirectUrl' => $targetRedirect, |
| 234 | + ], |
| 235 | + 'submitButton' |
| 236 | + ); |
| 237 | + |
| 238 | + $updatedAuthRecords = AuthRecord::find()->all(); |
| 239 | + $this->assertEquals(count($authRecords) + 1, count($updatedAuthRecords)); |
| 240 | + |
| 241 | + $authRecord = AuthRecord::find()->one(); |
| 242 | + $this->assertNotNull($authRecord, 'AuthRecord should be created for a valid login request.'); |
| 243 | + $this->assertEquals($targetRedirect, $authRecord->redirectUrl); |
| 244 | + } |
| 245 | + |
203 | 246 | /** |
204 | 247 | * Tests that we have a rate limit setup for Magic Login. |
| 248 | + * |
| 249 | + * @return void |
205 | 250 | */ |
206 | 251 | public function testMagicLoginEmailRateLimit() |
207 | 252 | { |
|
0 commit comments