|
@@ -175,4 +175,175 @@ class UserControllerTest extends FunctionalTest
|
175
|
175
|
$this->assertEquals(1, count($prefereds));
|
176
|
176
|
}
|
177
|
177
|
|
|
178
|
+ /**
|
|
179
|
+ * Test de al procédure de changement d'email.
|
|
180
|
+ */
|
|
181
|
+ public function testChangeEmail()
|
|
182
|
+ {
|
|
183
|
+ $this->client = self::createClient();
|
|
184
|
+ $this->connectUser('bob', 'toor');
|
|
185
|
+ $bob = $this->findUserByUsername('bob');
|
|
186
|
+
|
|
187
|
+ // Ouverture de la page Mon compte
|
|
188
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('my_account'));
|
|
189
|
+
|
|
190
|
+ // Le mail en cours n'est pas celui que nous voulons mettre
|
|
191
|
+ $this->assertFalse($bob->getEmail() == 'trololololooo@trolo.com');
|
|
192
|
+ // Nous n'avons pas encore demandé de nouveau mail
|
|
193
|
+ $this->assertTrue($bob->getEmailRequested() == null);
|
|
194
|
+ $this->assertTrue($bob->getEmailRequestedDatetime() == null);
|
|
195
|
+
|
|
196
|
+ // On fait un premier essaie avec une email mal formulé
|
|
197
|
+ $this->exist('form[action="'.($url = $this->generateUrl(
|
|
198
|
+ 'change_email_request'
|
|
199
|
+ )).'"]');
|
|
200
|
+ $this->exist('form[action="'.$url.'"] input[type="submit"]');
|
|
201
|
+
|
|
202
|
+ $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
|
|
203
|
+ $form['form[email]'] = 'trololololooo@trolo';
|
|
204
|
+ $this->submit($form);
|
|
205
|
+
|
|
206
|
+ // Il n'y as pas de redirection
|
|
207
|
+ $this->isResponseSuccess();
|
|
208
|
+
|
|
209
|
+ $bob = $this->findUserByUsername('bob');
|
|
210
|
+ // Les champs n'ont pas bougés
|
|
211
|
+ $this->assertFalse($bob->getEmail() == 'trololololooo@trolo.com');
|
|
212
|
+ // Nous n'avons pas encore demandé de nouveau mail
|
|
213
|
+ $this->assertTrue($bob->getEmailRequested() == null);
|
|
214
|
+ $this->assertTrue($bob->getEmailRequestedDatetime() == null);
|
|
215
|
+
|
|
216
|
+ $this->exist('form[action="'.($url = $this->generateUrl(
|
|
217
|
+ 'change_email_request'
|
|
218
|
+ )).'"]');
|
|
219
|
+ $this->exist('form[action="'.$url.'"] input[type="submit"]');
|
|
220
|
+
|
|
221
|
+ $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
|
|
222
|
+ $form['form[email]'] = 'trololololooo@trolo.com';
|
|
223
|
+ $this->submit($form);
|
|
224
|
+
|
|
225
|
+ // Ce coup-ci c'est bien une redirection
|
|
226
|
+ $this->isResponseRedirection();
|
|
227
|
+
|
|
228
|
+ // Un mail a été envoyé
|
|
229
|
+ $mc = $this->getMailerMessageDataCollector();
|
|
230
|
+ $this->assertEquals(1, $mc->getMessageCount());
|
|
231
|
+
|
|
232
|
+ $mails = $mc->getMessages();
|
|
233
|
+ $mail = $mails[0];
|
|
234
|
+
|
|
235
|
+ // Les champs ont bougés
|
|
236
|
+ $bob = $this->findUserByUsername('bob');
|
|
237
|
+ $this->assertFalse($bob->getEmail() == 'trololololooo@trolo.com');
|
|
238
|
+ $this->assertFalse($bob->getEmailRequested() == null);
|
|
239
|
+ $this->assertTrue($bob->getEmailRequested() == 'trololololooo@trolo.com');
|
|
240
|
+ $this->assertFalse($bob->getEmailRequestedDatetime() == null);
|
|
241
|
+
|
|
242
|
+ $this->followRedirection();
|
|
243
|
+ $this->isResponseSuccess();
|
|
244
|
+
|
|
245
|
+ // On ouvre un lien erroné
|
|
246
|
+ $badurl = $this->generateUrl(
|
|
247
|
+ 'change_email_confirm',
|
|
248
|
+ array('token' => $this->getUser()->getConfirmationToken()),
|
|
249
|
+ true
|
|
250
|
+ );
|
|
251
|
+ $this->crawler = $this->client->request('GET', $badurl);
|
|
252
|
+ $this->isResponseRedirection();
|
|
253
|
+ $this->followRedirection();
|
|
254
|
+ $this->isResponseSuccess();
|
|
255
|
+ $this->exist('div.error');
|
|
256
|
+
|
|
257
|
+ // Et les champs ont pas bougés
|
|
258
|
+ $bob = $this->findUserByUsername('bob');
|
|
259
|
+ $this->assertFalse($bob->getEmail() == 'trololololooo@trolo.com');
|
|
260
|
+ $this->assertFalse($bob->getEmailRequested() == null);
|
|
261
|
+ $this->assertTrue($bob->getEmailRequested() == 'trololololooo@trolo.com');
|
|
262
|
+ $this->assertFalse($bob->getEmailRequestedDatetime() == null);
|
|
263
|
+
|
|
264
|
+ $this->assertTrue(!is_null(strpos($mail->getBody(), ($url = $this->generateUrl(
|
|
265
|
+ 'change_email_confirm',
|
|
266
|
+ array('token' => $token = hash('sha256', $bob->getConfirmationToken().'trololololooo@trolo.com')),
|
|
267
|
+ true
|
|
268
|
+ )))));
|
|
269
|
+
|
|
270
|
+ // On ouvre le bon lien
|
|
271
|
+ $this->crawler = $this->client->request('GET', $url);
|
|
272
|
+
|
|
273
|
+ // C'est un succés
|
|
274
|
+ $this->isResponseRedirection();
|
|
275
|
+ $this->followRedirection();
|
|
276
|
+ $this->isResponseSuccess();
|
|
277
|
+
|
|
278
|
+ $this->outputDebug();
|
|
279
|
+ $this->notExist('div.error');
|
|
280
|
+
|
|
281
|
+ // Et les champs ont bougés
|
|
282
|
+ $bob = $this->findUserByUsername('bob');
|
|
283
|
+ $this->assertTrue($bob->getEmail() == 'trololololooo@trolo.com');
|
|
284
|
+ $this->assertTrue($bob->getEmailRequested() == null);
|
|
285
|
+ $this->assertFalse($bob->getEmailRequestedDatetime() == null);
|
|
286
|
+
|
|
287
|
+ // Par contre si on refait une demande maintenant ca échoue (délais entre demandes)
|
|
288
|
+ $this->exist('form[action="'.($url = $this->generateUrl(
|
|
289
|
+ 'change_email_request'
|
|
290
|
+ )).'"]');
|
|
291
|
+ $this->exist('form[action="'.$url.'"] input[type="submit"]');
|
|
292
|
+
|
|
293
|
+ $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
|
|
294
|
+ $form['form[email]'] = 'trololololooo222@trolo.com';
|
|
295
|
+ $this->submit($form);
|
|
296
|
+
|
|
297
|
+ // Il n'y as pas de redirection
|
|
298
|
+ $this->isResponseRedirection();
|
|
299
|
+ $this->followRedirection();
|
|
300
|
+ $this->isResponseSuccess();
|
|
301
|
+ $this->exist('div.error');
|
|
302
|
+
|
|
303
|
+ // Et les champs ont bougés
|
|
304
|
+ $bob = $this->findUserByUsername('bob');
|
|
305
|
+ $this->assertTrue($bob->getEmail() == 'trololololooo@trolo.com');
|
|
306
|
+ $this->assertTrue($bob->getEmailRequested() == null);
|
|
307
|
+ $this->assertFalse($bob->getEmailRequestedDatetime() == null);
|
|
308
|
+
|
|
309
|
+ // Si par contre on manipule le dateTime on pourra
|
|
310
|
+ $bob = $this->findUserByUsername('bob');
|
|
311
|
+ $bob->setEmailRequestedDatetime(
|
|
312
|
+ $this->getUser()->getEmailRequestedDatetime()
|
|
313
|
+ - $this->getContainer()->getParameter('changeemail_security_delay')
|
|
314
|
+ );
|
|
315
|
+
|
|
316
|
+ $this->getDoctrine()->getEntityManager()->flush();
|
|
317
|
+
|
|
318
|
+ $form = $this->selectForm('form[action="'.$url.'"] input[type="submit"]');
|
|
319
|
+ $form['form[email]'] = 'trololololooo222@trolo.com';
|
|
320
|
+ $this->submit($form);
|
|
321
|
+
|
|
322
|
+ // Ce coup-ci c'est bien une redirection
|
|
323
|
+ $this->isResponseRedirection();
|
|
324
|
+
|
|
325
|
+ // Un mail a été envoyé
|
|
326
|
+ $mc = $this->getMailerMessageDataCollector();
|
|
327
|
+ $this->assertEquals(1, $mc->getMessageCount());
|
|
328
|
+
|
|
329
|
+ $mails = $mc->getMessages();
|
|
330
|
+ $mail = $mails[0];
|
|
331
|
+
|
|
332
|
+ $this->assertTrue(!is_null(strpos($mail->getBody(), ($url = $this->generateUrl(
|
|
333
|
+ 'change_email_confirm',
|
|
334
|
+ array('token' => hash('sha256', $this->getUser()->getConfirmationToken().'trololololooo222@trolo.com')),
|
|
335
|
+ true
|
|
336
|
+ )))));
|
|
337
|
+
|
|
338
|
+ // Les champs ont bougés
|
|
339
|
+ $bob = $this->findUserByUsername('bob');
|
|
340
|
+ $this->assertFalse($bob->getEmail() == 'trololololooo222@trolo.com');
|
|
341
|
+ $this->assertFalse($bob->getEmailRequested() == null);
|
|
342
|
+ $this->assertTrue($bob->getEmailRequested() == 'trololololooo222@trolo.com');
|
|
343
|
+ $this->assertFalse($bob->getEmailRequestedDatetime() == null);
|
|
344
|
+
|
|
345
|
+ $this->followRedirection();
|
|
346
|
+ $this->isResponseSuccess();
|
|
347
|
+ }
|
|
348
|
+
|
178
|
349
|
}
|