1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Test\Security; |
4
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\PusherChannel; |
6
|
|
|
use IrishDan\NotificationBundle\Security\PusherChannelVoter; |
7
|
|
|
use IrishDan\NotificationBundle\Test\NotificationTestCase; |
8
|
|
|
|
9
|
|
|
class PusherChannelVoterTest extends NotificationTestCase |
10
|
|
|
{ |
11
|
|
|
protected $voter; |
12
|
|
|
protected $pusherChannel; |
13
|
|
|
|
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
$config = $this->getNotificationChannelConfiguration('pusher'); |
17
|
|
|
|
18
|
|
|
$this->voter = new PusherChannelVoter(true, $config); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testVote() |
22
|
|
|
{ |
23
|
|
|
$this->pusherChannel = new PusherChannel('pusher_test_1', '1234567'); |
24
|
|
|
|
25
|
|
|
$user = $this->getTestUser(); |
26
|
|
|
$token = $this->getToken(); |
27
|
|
|
$token->expects($this->any()) |
28
|
|
|
->method('getUser') |
29
|
|
|
->will($this->returnValue($user)); |
30
|
|
|
|
31
|
|
|
// Vote should pass |
32
|
|
|
$vote = $this->voter->vote($token, $this->pusherChannel, ['subscribe']); |
33
|
|
|
$this->assertEquals(1, $vote); |
34
|
|
|
|
35
|
|
|
// Unsupported action |
36
|
|
|
// Vote should not pass |
37
|
|
|
$vote = $this->voter->vote($token, $this->pusherChannel, ['sizzle']); |
38
|
|
|
$this->assertEquals(-1, $vote); |
39
|
|
|
|
40
|
|
|
// Unsupported entity |
41
|
|
|
// Vote should not vote |
42
|
|
|
$vote = $this->voter->vote($token, $user, ['subscribe']); |
43
|
|
|
$this->assertEquals(0, $vote); |
44
|
|
|
|
45
|
|
|
// Vote should not pass |
46
|
|
|
$user->setSubscribedChannels([]); |
47
|
|
|
$vote = $this->voter->vote($token, $this->pusherChannel, ['subscribe']); |
48
|
|
|
$this->assertEquals(-1, $vote); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testVoteOnNotUsersChannel() |
52
|
|
|
{ |
53
|
|
|
$this->pusherChannel = new PusherChannel('pusher_test_2', '1234567'); |
54
|
|
|
|
55
|
|
|
$user = $this->getTestUser(); |
56
|
|
|
$token = $this->getToken(); |
57
|
|
|
$token->expects($this->once()) |
58
|
|
|
->method('getUser') |
59
|
|
|
->will($this->returnValue($user)); |
60
|
|
|
|
61
|
|
|
// Vote should pass |
62
|
|
|
$vote = $this->voter->vote($token, $this->pusherChannel, ['subscribe']); |
63
|
|
|
$this->assertEquals(-1, $vote); |
64
|
|
|
} |
65
|
|
|
} |