1 | <?php |
||
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() |
||
116 | } |
||
117 |