|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* The MIT License (MIT) |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright (c) 2014-2019 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
|
|
|
* @internal |
|
25
|
|
|
*/ |
|
26
|
|
|
final class ClientIdIssuedAtRuleTest extends TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @test |
|
30
|
|
|
*/ |
|
31
|
|
|
public function clientIdIssuedAtRuleSetAsDefault() |
|
32
|
|
|
{ |
|
33
|
|
|
$clientId = new ClientId('CLIENT_ID'); |
|
34
|
|
|
$commandParameters = new DataBag([]); |
|
35
|
|
|
$rule = new ClientRule\ClientIdIssuedAtRule(); |
|
36
|
|
|
$validatedParameters = $rule->handle($clientId, $commandParameters, new DataBag([]), $this->getCallable()); |
|
37
|
|
|
|
|
38
|
|
|
static::assertTrue($validatedParameters->has('client_id_issued_at')); |
|
39
|
|
|
static::assertIsInt($validatedParameters->get('client_id_issued_at')); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @test |
|
44
|
|
|
*/ |
|
45
|
|
|
public function clientIdIssuedAtRuleDefineInParameters() |
|
46
|
|
|
{ |
|
47
|
|
|
$clientId = new ClientId('CLIENT_ID'); |
|
48
|
|
|
$commandParameters = new DataBag([ |
|
49
|
|
|
'client_id_issued_at' => time() - 1000, |
|
50
|
|
|
]); |
|
51
|
|
|
$rule = new ClientRule\ClientIdIssuedAtRule(); |
|
52
|
|
|
$validatedParameters = $rule->handle($clientId, $commandParameters, new DataBag([]), $this->getCallable()); |
|
53
|
|
|
|
|
54
|
|
|
static::assertTrue($validatedParameters->has('client_id_issued_at')); |
|
55
|
|
|
static::assertIsInt($validatedParameters->get('client_id_issued_at')); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function getCallable(): ClientRule\RuleHandler |
|
59
|
|
|
{ |
|
60
|
|
|
return new ClientRule\RuleHandler(function (ClientId $clientId, DataBag $commandParameters, DataBag $validatedParameters): DataBag { |
|
61
|
|
|
return $validatedParameters; |
|
62
|
|
|
}); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|