Failed Conditions
Push — master ( c6baf0...a3629e )
by Florent
16:19
created

testCommonParameterRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\ClientRule\Tests;
15
16
use OAuth2Framework\Component\ClientRule;
17
use OAuth2Framework\Component\Core\Client\ClientId;
18
use OAuth2Framework\Component\Core\DataBag\DataBag;
19
use PHPUnit\Framework\TestCase;
20
21
/**
22
 * @group Tests
23
 */
24
final class CommonParametersRuleTest extends TestCase
25
{
26
    /**
27
     * @test
28
     * @expectedException \InvalidArgumentException
29
     * @expectedExceptionMessage The parameter with key "client_uri" is not a valid URL.
30
     */
31
    public function aParameterIsNotAValidUrl()
32
    {
33
        $clientId = new ClientId('CLIENT_ID');
34
        $commandParameters = new DataBag([
35
            'client_name' => 'Client name',
36
            'client_uri' => 'urn:foo:bar:OK',
37
        ]);
38
        $rule = new ClientRule\CommonParametersRule();
39
        $rule->handle($clientId, $commandParameters, new DataBag([]), $this->getCallable());
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function commonParameterRule()
46
    {
47
        $clientId = new ClientId('CLIENT_ID');
48
        $commandParameters = new DataBag([
49
            'client_name' => 'Client name',
50
            'client_name#fr' => 'Nom du client',
51
            'client_uri' => 'http://localhost/information',
52
            'logo_uri' => 'http://127.0.0.1:8000/logo.png',
53
            'tos_uri' => 'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/tos.html',
54
            'policy_uri' => 'http://localhost/policy',
55
        ]);
56
        $rule = new ClientRule\CommonParametersRule();
57
        $validatedParameters = $rule->handle($clientId, $commandParameters, new DataBag([]), $this->getCallable());
58
59
        static::assertTrue($validatedParameters->has('client_name'));
60
        static::assertEquals('Client name', $validatedParameters->get('client_name'));
61
        static::assertTrue($validatedParameters->has('client_uri'));
62
        static::assertEquals('http://localhost/information', $validatedParameters->get('client_uri'));
63
        static::assertTrue($validatedParameters->has('logo_uri'));
64
        static::assertEquals('http://127.0.0.1:8000/logo.png', $validatedParameters->get('logo_uri'));
65
        static::assertTrue($validatedParameters->has('tos_uri'));
66
        static::assertEquals('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/tos.html', $validatedParameters->get('tos_uri'));
67
        static::assertTrue($validatedParameters->has('policy_uri'));
68
        static::assertEquals('http://localhost/policy', $validatedParameters->get('policy_uri'));
69
    }
70
71
    private function getCallable(): callable
72
    {
73
        return function (ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters): DataBag {
74
            return $validatedParameters;
75
        };
76
    }
77
}
78