1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the MilioooMessageBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Michiel boeckaert <[email protected]> |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Miliooo\Messaging\Tests\User; |
12
|
|
|
|
13
|
|
|
use Miliooo\Messaging\User\ParticipantProviderSecurityContext; |
14
|
|
|
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Test file for Miliooo\Messaging\User\ParticipantProviderSecurityContext |
18
|
|
|
* |
19
|
|
|
* @author Michiel Boeckaert <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class ParticipantProviderSecurityContextTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The class under test |
25
|
|
|
* |
26
|
|
|
* @var ParticipantProviderSecurityContext |
27
|
|
|
*/ |
28
|
|
|
private $participantProvider; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
32
|
|
|
*/ |
33
|
|
|
private $securityContext; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
37
|
|
|
*/ |
38
|
|
|
private $securityToken; |
39
|
|
|
|
40
|
|
|
public function setUp() |
41
|
|
|
{ |
42
|
|
|
$this->securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); |
43
|
|
|
$this->securityToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); |
44
|
|
|
$this->participantProvider = new ParticipantProviderSecurityContext($this->securityContext); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testInterface() |
48
|
|
|
{ |
49
|
|
|
$this->assertInstanceOf('Miliooo\Messaging\User\ParticipantProviderInterface', $this->participantProvider); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException |
54
|
|
|
* @expectedExceptionMessage You must be logged in with a participant interface |
55
|
|
|
*/ |
56
|
|
|
public function testGetAuthenticatedParticipantTokenReturnsString() |
57
|
|
|
{ |
58
|
|
|
$this->expectsToken(); |
59
|
|
|
$this->securityToken->expects($this->once())->method('getUser')->will($this->returnValue('anon')); |
60
|
|
|
$this->participantProvider->getAuthenticatedParticipant(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException |
65
|
|
|
* @expectedExceptionMessage You must be logged in with a participant interface |
66
|
|
|
*/ |
67
|
|
|
public function testGetAuthenticatedParticpantReturnsObjectNotInstanceParticipantInterface() |
68
|
|
|
{ |
69
|
|
|
$this->expectsToken(); |
70
|
|
|
$obj = new \stdClass; |
71
|
|
|
$this->securityToken->expects($this->once())->method('getUser')->will($this->returnValue($obj)); |
72
|
|
|
$this->participantProvider->getAuthenticatedParticipant(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetAuthenticatedParticipantReturnsParticipant() |
76
|
|
|
{ |
77
|
|
|
$this->expectsToken(); |
78
|
|
|
$loggedInUser = new ParticipantTestHelper('user'); |
79
|
|
|
$this->securityToken->expects($this->once())->method('getUser') |
80
|
|
|
->will($this->returnValue($loggedInUser)); |
81
|
|
|
$this->assertEquals($loggedInUser, $this->participantProvider->getAuthenticatedParticipant()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function expectsToken() |
85
|
|
|
{ |
86
|
|
|
$this->securityContext->expects($this->once())->method('getToken') |
87
|
|
|
->will($this->returnValue($this->securityToken)); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|