Failed Conditions
Pull Request — master (#262)
by Guilherme
10:25 queued 04:26
created

CompleteUserInfoTaskTest::testConstruct()   B

Complexity

Conditions 5
Paths 81

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 20
nc 81
nop 0
dl 0
loc 28
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Tests\Task;
12
13
use LoginCidadao\OpenIDBundle\Task\CompleteUserInfoTask;
14
use PHPUnit\Framework\TestCase;
15
16
class CompleteUserInfoTaskTest extends TestCase
17
{
18
    public function testTaskWithNonce()
19
    {
20
        $clientId = '1234_abcde';
21
        $scope = 'scope1 scope2 scope3';
22
        $nonce = 'noncehere';
23
        $expectedId = "lc.task.complete_userinfo_{$clientId}_{$nonce}";
24
25
        $task = new CompleteUserInfoTask($clientId, $scope, $nonce);
26
27
        $this->assertEquals($clientId, $task->getClientId());
28
        $this->assertEquals($scope, $task->getScope());
29
        $this->assertContains($clientId, $task->getId());
30
        $this->assertContains($nonce, $task->getId());
31
        $this->assertEquals($expectedId, $task->getId());
32
    }
33
34
    public function testTaskWithoutNonce()
35
    {
36
        $clientId = '1234_abcde';
37
        $scope = 'scope1 scope2 scope3';
38
        $expectedId = "lc.task.complete_userinfo_{$clientId}";
39
        $routes = [
40
            'fos_user_registration_confirm',
41
            'dynamic_form',
42
            'dynamic_form_skip',
43
            'wait_valid_email',
44
            'dynamic_form_location',
45
        ];
46
47
        $task = new CompleteUserInfoTask($clientId, $scope);
48
49
        $this->assertEquals($clientId, $task->getClientId());
50
        $this->assertEquals($scope, $task->getScope());
51
        $this->assertContains($clientId, $task->getId());
52
        $this->assertEquals($expectedId, $task->getId());
53
        $this->assertFalse($task->isMandatory());
54
        $this->assertInstanceOf('LoginCidadao\TaskStackBundle\Model\RouteTaskTarget', $task->getTarget());
55
        $this->assertEquals(count($routes), count($task->getRoutes()));
56
        foreach ($routes as $route) {
57
            $this->assertContains($route, $task->getRoutes());
58
        }
59
    }
60
61
    public function testConstruct()
62
    {
63
        try {
64
            new CompleteUserInfoTask(null, null);
65
            $this->fail('\InvalidArgumentException was not thrown for client_id');
66
        } catch (\InvalidArgumentException $e) {
67
            $this->assertContains('client_id', $e->getMessage());
68
        }
69
70
        try {
71
            new CompleteUserInfoTask('', null);
72
            $this->fail('\InvalidArgumentException was not thrown for client_id');
73
        } catch (\InvalidArgumentException $e) {
74
            $this->assertContains('client_id', $e->getMessage());
75
        }
76
77
        try {
78
            new CompleteUserInfoTask('something', null);
79
            $this->fail('\InvalidArgumentException was not thrown for scope');
80
        } catch (\InvalidArgumentException $e) {
81
            $this->assertContains('scope', $e->getMessage());
82
        }
83
84
        try {
85
            new CompleteUserInfoTask('something', '');
86
            $this->fail('\InvalidArgumentException was not thrown for scope');
87
        } catch (\InvalidArgumentException $e) {
88
            $this->assertContains('scope', $e->getMessage());
89
        }
90
    }
91
}
92