Completed
Push — master ( 500d1e...d5cda8 )
by dan
03:01
created

testVoteOnNotUsersChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 14
c 1
b 0
f 0
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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
}