|
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\Manager; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityManager; |
|
14
|
|
|
use LoginCidadao\OpenIDBundle\Manager\ScopeManager; |
|
15
|
|
|
use OAuth2\ServerBundle\Entity\Scope; |
|
16
|
|
|
|
|
17
|
|
|
class ScopeManagerTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
const SCOPE_CLASS = 'OAuth2\ServerBundle\Entity\Scope'; |
|
20
|
|
|
|
|
21
|
|
|
public function testFindScopeByScope() |
|
22
|
|
|
{ |
|
23
|
|
|
$manager = $this->getScopeManager(); |
|
24
|
|
|
$manager->setScopes('scope1 scope2 scope3'); |
|
25
|
|
|
|
|
26
|
|
|
foreach (['scope1', 'scope2', 'scope3'] as $scopeName) { |
|
27
|
|
|
/** @var Scope $scope */ |
|
28
|
|
|
$scope = $manager->findScopeByScope($scopeName); |
|
29
|
|
|
$this->assertInstanceOf(self::SCOPE_CLASS, $scope); |
|
30
|
|
|
$this->assertSame($scopeName, $scope->getScope()); |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testFindNonExistentScope() |
|
35
|
|
|
{ |
|
36
|
|
|
$manager = $this->getScopeManager(); |
|
37
|
|
|
$manager->setScopes('scope1 scope2 scope3'); |
|
38
|
|
|
|
|
39
|
|
|
$scope = $manager->findScopeByScope('foobar'); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertNotInstanceOf(self::SCOPE_CLASS, $scope); |
|
42
|
|
|
$this->assertNull($scope); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testSetScopes() |
|
46
|
|
|
{ |
|
47
|
|
|
$scopes = [ |
|
48
|
|
|
'', |
|
49
|
|
|
[], |
|
50
|
|
|
'scope1 scope2 scope3', |
|
51
|
|
|
['scope1'], |
|
52
|
|
|
['scope1', 'scope2', 'scope3'], |
|
53
|
|
|
]; |
|
54
|
|
|
$manager = $this->getScopeManager(); |
|
55
|
|
|
|
|
56
|
|
|
foreach ($scopes as $scope) { |
|
57
|
|
|
$manager->setScopes($scope); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$this->assertInstanceOf(self::SCOPE_CLASS, $manager->findScopeByScope('scope1')); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testFindScopesByScopes() |
|
64
|
|
|
{ |
|
65
|
|
|
$manager = $this->getScopeManager(); |
|
66
|
|
|
$manager->setScopes('scope1 scope2 scope3'); |
|
67
|
|
|
|
|
68
|
|
|
$scopes = $manager->findScopesByScopes(['scope0', 'scope1', 'scope3']); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertContains('scope1', array_keys($scopes)); |
|
71
|
|
|
$this->assertContains('scope3', array_keys($scopes)); |
|
72
|
|
|
$this->assertNotContains('scope0', array_keys($scopes)); |
|
73
|
|
|
$this->assertNotContains('scope2', array_keys($scopes)); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
private function getScopeManager() |
|
77
|
|
|
{ |
|
78
|
|
|
return new ScopeManager($this->getEntityManager()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return EntityManager|\PHPUnit_Framework_MockObject_MockObject |
|
83
|
|
|
*/ |
|
84
|
|
|
private function getEntityManager() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->getMockBuilder('Doctrine\ORM\EntityManager')->disableOriginalConstructor()->getMock(); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|