1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\KI\UserBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Tests\KI\CoreBundle\WebTestCase; |
6
|
|
|
|
7
|
|
|
class DefaultControllerTest extends WebTestCase |
8
|
|
|
{ |
9
|
|
|
public function testRefresh() |
10
|
|
|
{ |
11
|
|
|
$this->client->request('GET', '/refresh'); |
12
|
|
|
$this->assertJsonResponse($this->client->getResponse(), 200); |
13
|
|
|
|
14
|
|
|
$this->client->request('GET', '/refresh?delay=5'); |
15
|
|
|
$this->assertJsonResponse($this->client->getResponse(), 200); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
public function testRequestResetting() |
20
|
|
|
{ |
21
|
|
|
$client = static::createClient(); |
22
|
|
|
$client->enableProfiler(); |
23
|
|
|
$client->request('POST', '/resetting/request', ['username' => 'iqhjioqiosois']); |
24
|
|
|
|
25
|
|
|
// On vérifie que l'email a été envoyé |
26
|
|
|
$mailCollector = $client->getProfile()->getCollector('swiftmailer'); |
27
|
|
|
$this->assertEquals(0, $mailCollector->getMessageCount()); |
|
|
|
|
28
|
|
|
$this->assertJsonResponse($client->getResponse(), 404); |
29
|
|
|
|
30
|
|
|
$client = static::createClient(); |
31
|
|
|
$client->enableProfiler(); |
32
|
|
|
$client->request('POST', '/resetting/request', ['username' => 'trancara']); |
33
|
|
|
|
34
|
|
|
// On vérifie que l'email a été envoyé |
35
|
|
|
$mailCollector = $client->getProfile()->getCollector('swiftmailer'); |
36
|
|
|
$this->assertEquals(1, $mailCollector->getMessageCount()); |
|
|
|
|
37
|
|
|
$this->assertJsonResponse($client->getResponse(), 204); |
38
|
|
|
|
39
|
|
|
$collectedMessages = $mailCollector->getMessages(); |
40
|
|
|
$message = $collectedMessages[0]; |
41
|
|
|
|
42
|
|
|
// On vérifie le message |
43
|
|
|
$this->assertInstanceOf('Swift_Message', $message); |
44
|
|
|
$this->assertEquals('Réinitialisation du mot de passe', $message->getSubject()); |
45
|
|
|
$this->assertEquals('[email protected]', key($message->getFrom())); |
46
|
|
|
$this->assertEquals('[email protected]', key($message->getTo())); |
47
|
|
|
|
48
|
|
|
// On récupère le token |
49
|
|
|
$this->assertTrue(preg_match('#/reset/(.*)\n\n.*Si#is', $message->getBody(), $token) == 1); |
50
|
|
|
$token = $token[1]; |
51
|
|
|
$this->assertTrue(!empty($token)); |
52
|
|
|
|
53
|
|
|
// On teste le reset en lui même |
54
|
|
|
$this->client->request('POST', '/resetting/token/dfdsdsfdsfsfds', ['password' => '1234', 'check' => '1234']); |
55
|
|
|
$this->assertJsonResponse($this->client->getResponse(), 404); |
56
|
|
|
|
57
|
|
|
$this->client->request('POST', '/resetting/token/'.$token, ['password' => 'password', 'check' => '12sdqsdsqdqds34']); |
|
|
|
|
58
|
|
|
$this->assertJsonResponse($this->client->getResponse(), 400); |
59
|
|
|
|
60
|
|
|
$this->client->request('POST', '/resetting/token/'.$token, ['password' => 'azerty', 'check' => 'azerty']); |
61
|
|
|
$this->assertJsonResponse($this->client->getResponse(), 204); |
62
|
|
|
|
63
|
|
|
// On vérifie que le mot de passe a bien été changé |
64
|
|
|
$client = static::createClient(); |
65
|
|
|
$client->request('POST', '/login', ['username' => 'trancara', 'password' => 'azerty']); |
66
|
|
|
$this->assertJsonResponse($client->getResponse(), 200, true); |
67
|
|
|
|
68
|
|
|
// On remet l'ancien mot de passe |
69
|
|
|
$client = static::createClient(); |
70
|
|
|
$client->request('POST', '/resetting/token/'.$token, ['password' => 'password', 'check' => 'password']); |
71
|
|
|
$this->assertJsonResponse($this->client->getResponse(), 204); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.