|
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\ParticipantProviderSecurityToken; |
|
14
|
|
|
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Test file for Miliooo\Messaging\User\ParticipantProviderSecurityToken |
|
18
|
|
|
* |
|
19
|
|
|
* @author Michiel Boeckaert <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class ParticipantProviderSecurityTokenTest extends \PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* The class under test |
|
25
|
|
|
* |
|
26
|
|
|
* @var ParticipantProviderSecurityToken |
|
27
|
|
|
*/ |
|
28
|
|
|
private $participantProvider; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
|
32
|
|
|
*/ |
|
33
|
|
|
private $securityToken; |
|
34
|
|
|
|
|
35
|
|
|
public function setUp() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->securityToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); |
|
38
|
|
|
$this->participantProvider = new ParticipantProviderSecurityToken($this->securityToken); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testInterface() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->assertInstanceOf('Miliooo\Messaging\User\ParticipantProviderInterface', $this->participantProvider); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException |
|
48
|
|
|
* @expectedExceptionMessage You must be logged in with a participant interface |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testGetAuthenticatedParticipantTokenReturnsString() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->securityToken->expects($this->once())->method('getUser')->will($this->returnValue('anon')); |
|
53
|
|
|
$this->participantProvider->getAuthenticatedParticipant(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException |
|
58
|
|
|
* @expectedExceptionMessage You must be logged in with a participant interface |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testGetAuthenticatedParticpantReturnsObjectNotInstanceParticipantInterface() |
|
61
|
|
|
{ |
|
62
|
|
|
$obj = new \stdClass; |
|
63
|
|
|
$this->securityToken->expects($this->once())->method('getUser')->will($this->returnValue($obj)); |
|
64
|
|
|
$this->participantProvider->getAuthenticatedParticipant(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testGetAuthenticatedParticipantReturnsParticipant() |
|
68
|
|
|
{ |
|
69
|
|
|
$loggedInUser = new ParticipantTestHelper('user'); |
|
70
|
|
|
$this->securityToken->expects($this->once())->method('getUser') |
|
71
|
|
|
->will($this->returnValue($loggedInUser)); |
|
72
|
|
|
$this->assertEquals($loggedInUser, $this->participantProvider->getAuthenticatedParticipant()); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|