Completed
Pull Request — dev (#22)
by
unknown
05:00
created

UserControllerTest::testActivationAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 22
rs 9.2
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
namespace Tests\AppBundle\Controller;
4
5
use AppBundle\Form\User\EditType;
6
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Doctrine\ORM\EntityManager;
9
use AppBundle\Entity\User;
10
11
class UserControllerTest extends WebTestCase
12
{
13
    public function testListAction()
14
    {
15
        $client = static::createClient();
16
        $crawler = $client->request('GET', '/users');
0 ignored issues
show
Unused Code introduced by
$crawler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
17
        $this->assertEquals('302', $client->getResponse()->getStatusCode());
18
        $crawler = $client->request('GET', '/login');
19
        $form = $crawler->selectButton('Login')->form();
20
        $client->submit($form, ['_username' => '[email protected]', '_password' => 'admin']);
21
        $crawler = $client->request('GET', '/users');
0 ignored issues
show
Unused Code introduced by
$crawler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
22
        $this->assertEquals('200', $client->getResponse()->getStatusCode());
23
    }
24
25
    public function testAddAction()
26
    {
27
        $client = static::createClient();
28
        $crawler = $client->request('GET', '/login');
29
        $form = $crawler->selectButton('Login')->form();
30
        $client->submit($form, ['_username' => '[email protected]', '_password' => 'admin']);
31
32
        $em = static::$kernel->getContainer()
33
            ->get('doctrine')
34
            ->getManager();
35
36
        $usersCount1 = count($em->getRepository('AppBundle:User')->findAll());
37
38
        $crawler = $client->request('GET', '/user/add');
39
        $form = $crawler->selectButton('Register')->form();
40
        $client->submit($form, [
41
            'registration[lastName]' => 'test',
42
            'registration[firstName]' => 'test',
43
            'registration[email]' => '[email protected]',
44
            'registration[plainPassword][first]' => 'test',
45
            'registration[plainPassword][second]' => 'test',
46
        ]);
47
48
        $usersCount2 = count($em->getRepository('AppBundle:User')->findAll());
49
        $this->assertEquals($usersCount1 + 1, $usersCount2);
50
    }
51
52
    public function testActivationAction()
53
    {
54
        $client = static::createClient();
55
        $crawler = $client->request('GET', '/login');
56
        $form = $crawler->selectButton('Login')->form();
57
        $client->submit($form, ['_username' => '[email protected]', '_password' => 'admin']);
58
59
        $em = static::$kernel->getContainer()
60
            ->get('doctrine')
61
            ->getManager();
62
63
        $crawler = $client->request('GET', '/users');
64
65
        $form = $crawler->filter('table td form')->form();
66
        $url_params = explode('/', $form->getUri());
67
        $userid = $url_params[count($url_params)-1];
68
69
        $client->submit($form, ['activation[enabled]' => false]);
70
        $user = $em->getRepository('AppBundle:User')->findOneBy(array("id" => $userid));
71
72
        $this->assertEquals(false, $user->isEnabled());
73
    }
74
75
    public function testEditAction()
76
    {
77
        $client = static::createClient();
78
        $crawler = $client->request('GET', '/login');
79
        $form = $crawler->selectButton('Login')->form();
80
        $client->submit($form, ['_username' => '[email protected]', '_password' => 'admin']);
81
82
        $em = static::$kernel->getContainer()
83
            ->get('doctrine')
84
            ->getManager();
85
86
        $crawler = $client->request('GET', '/users');
87
88
        $form = $crawler->filter('table td form')->form();
89
        $url_params = explode('/', $form->getUri());
90
        $userid = $url_params[count($url_params)-1];
91
92
        $crawler = $client->request('GET', '/user/edit/'.$userid);
93
        $form = $crawler->selectButton('Save')->form();
94
95
        $client->submit($form, [
96
            'edit[lastName]' => 'test1',
97
            'edit[firstName]' => 'test1',
98
            'edit[email]' => '[email protected]',
99
            'edit[plainPassword][first]' => 'test1',
100
            'edit[plainPassword][second]' => 'test1',
101
        ]);
102
103
        $this->assertInstanceOf(
104
            User::class,
105
            $em->getRepository(User::class)->findOneBy(['email' => '[email protected]'])
106
        );
107
    }
108
}
109