|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
6
|
|
|
use AppBundle\Entity\User; |
|
7
|
|
|
|
|
8
|
|
|
class UserControllerTest extends WebTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testListAction() |
|
11
|
|
|
{ |
|
12
|
|
|
exec('./bin/console d:d:c --env=test'); |
|
13
|
|
|
exec('./bin/console d:s:c --env=test'); |
|
14
|
|
|
exec('./bin/console h:f:l -n --env=test'); |
|
15
|
|
|
|
|
16
|
|
|
$client = static::createClient(); |
|
17
|
|
|
$client->request('GET', '/users'); |
|
18
|
|
|
$this->assertEquals('302', $client->getResponse()->getStatusCode()); |
|
19
|
|
|
$crawler = $client->request('GET', '/login'); |
|
20
|
|
|
|
|
21
|
|
|
$form = $crawler->selectButton('Login')->form(); |
|
22
|
|
|
$client->submit($form, ['_username' => '[email protected]', '_password' => 'admin']); |
|
23
|
|
|
$client->request('GET', '/users'); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertEquals('200', $client->getResponse()->getStatusCode()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testAddAction() |
|
29
|
|
|
{ |
|
30
|
|
|
$client = static::createClient(); |
|
31
|
|
|
$client->request('GET', '/users'); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertEquals('302', $client->getResponse()->getStatusCode()); |
|
34
|
|
|
|
|
35
|
|
|
$crawler = $client->request('GET', '/login'); |
|
36
|
|
|
$form = $crawler->selectButton('Login')->form(); |
|
37
|
|
|
$client->submit($form, ['_username' => '[email protected]', '_password' => 'admin']); |
|
38
|
|
|
|
|
39
|
|
|
$em = static::$kernel->getContainer() |
|
40
|
|
|
->get('doctrine') |
|
41
|
|
|
->getManager(); |
|
42
|
|
|
|
|
43
|
|
|
$usersCount1 = count($em->getRepository('AppBundle:User')->findAll()); |
|
44
|
|
|
|
|
45
|
|
|
$crawler = $client->request('GET', '/user/add'); |
|
46
|
|
|
$form = $crawler->selectButton('Register')->form(); |
|
47
|
|
|
$client->submit($form, [ |
|
48
|
|
|
'edit[lastName]' => 'test', |
|
49
|
|
|
'edit[firstName]' => 'test', |
|
50
|
|
|
'edit[email]' => '[email protected]', |
|
51
|
|
|
'edit[plainPassword][first]' => 'test', |
|
52
|
|
|
'edit[plainPassword][second]' => 'test', |
|
53
|
|
|
]); |
|
54
|
|
|
$usersCount2 = count($em->getRepository('AppBundle:User')->findAll()); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertEquals($usersCount1 + 1, $usersCount2); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testActivationAction() |
|
60
|
|
|
{ |
|
61
|
|
|
$client = static::createClient(); |
|
62
|
|
|
$crawler = $client->request('GET', '/login'); |
|
63
|
|
|
$form = $crawler->selectButton('Login')->form(); |
|
64
|
|
|
$client->submit($form, ['_username' => '[email protected]', '_password' => 'admin']); |
|
65
|
|
|
|
|
66
|
|
|
$em = static::$kernel->getContainer() |
|
67
|
|
|
->get('doctrine') |
|
68
|
|
|
->getManager(); |
|
69
|
|
|
|
|
70
|
|
|
$crawler = $client->request('GET', '/users'); |
|
71
|
|
|
|
|
72
|
|
|
$form = $crawler->filter('table td form')->form(); |
|
73
|
|
|
$url_params = explode('/', $form->getUri()); |
|
74
|
|
|
$userid = $url_params[count($url_params) - 1]; |
|
75
|
|
|
|
|
76
|
|
|
$client->submit($form, ['activation[enabled]' => false]); |
|
77
|
|
|
$user = $em->getRepository('AppBundle:User')->findOneBy(array('id' => $userid)); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertEquals(false, $user->isEnabled()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testEditAction() |
|
83
|
|
|
{ |
|
84
|
|
|
$client = static::createClient(); |
|
85
|
|
|
$client->request('GET', '/users'); |
|
86
|
|
|
$this->assertEquals('302', $client->getResponse()->getStatusCode()); |
|
87
|
|
|
$crawler = $client->request('GET', '/login'); |
|
88
|
|
|
$form = $crawler->selectButton('Login')->form(); |
|
89
|
|
|
$client->submit($form, ['_username' => '[email protected]', '_password' => 'admin']); |
|
90
|
|
|
|
|
91
|
|
|
$em = static::$kernel->getContainer() |
|
92
|
|
|
->get('doctrine') |
|
93
|
|
|
->getManager(); |
|
94
|
|
|
|
|
95
|
|
|
$crawler = $client->request('GET', '/users'); |
|
96
|
|
|
|
|
97
|
|
|
$form = $crawler->filter('table td form')->form(); |
|
98
|
|
|
$url_params = explode('/', $form->getUri()); |
|
99
|
|
|
$userid = $url_params[count($url_params) - 1]; |
|
100
|
|
|
$crawler = $client->request('GET', '/user/edit/'.$userid); |
|
101
|
|
|
$form = $crawler->selectButton('Save')->form(); |
|
102
|
|
|
$client->submit($form, [ |
|
103
|
|
|
'edit[lastName]' => 'test1', |
|
104
|
|
|
'edit[firstName]' => 'test1', |
|
105
|
|
|
'edit[email]' => '[email protected]', |
|
106
|
|
|
'edit[plainPassword][first]' => 'test1', |
|
107
|
|
|
'edit[plainPassword][second]' => 'test1', |
|
108
|
|
|
]); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertInstanceOf( |
|
111
|
|
|
User::class, |
|
112
|
|
|
$em->getRepository(User::class)->findOneBy(['email' => '[email protected]']) |
|
113
|
|
|
); |
|
114
|
|
|
exec('./bin/console d:d:d --force --env=test'); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|