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
|
|
|
$this->pusherChannel = new PusherChannel('pusher_test_1', '1234567'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testVote() |
23
|
|
|
{ |
24
|
|
|
$user = $this->getTestUser(); |
25
|
|
|
$token = $this->getToken(); |
26
|
|
|
$token->expects($this->any()) |
27
|
|
|
->method('getUser') |
28
|
|
|
->will($this->returnValue($user)); |
29
|
|
|
|
30
|
|
|
// Vote should pass |
31
|
|
|
$vote = $this->voter->vote($token, $this->pusherChannel, ['subscribe']); |
32
|
|
|
$this->assertEquals(1, $vote); |
33
|
|
|
|
34
|
|
|
// Unsupported action |
35
|
|
|
// Vote should not pass |
36
|
|
|
$vote = $this->voter->vote($token, $this->pusherChannel, ['sizzle']); |
37
|
|
|
$this->assertEquals(-1, $vote); |
38
|
|
|
|
39
|
|
|
// Unsupported entity |
40
|
|
|
// Vote should not vote |
41
|
|
|
$vote = $this->voter->vote($token, $user, ['subscribe']); |
42
|
|
|
$this->assertEquals(0, $vote); |
43
|
|
|
|
44
|
|
|
// Vote should not pass |
45
|
|
|
$user->setSubscribedChannels([]); |
46
|
|
|
$vote = $this->voter->vote($token, $this->pusherChannel, ['subscribe']); |
47
|
|
|
$this->assertEquals(-1, $vote); |
48
|
|
|
} |
49
|
|
|
} |