1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Netgen\Bundle\SiteAccessRoutesBundle\Tests\Matcher; |
4
|
|
|
|
5
|
|
|
use Netgen\Bundle\SiteAccessRoutesBundle\Matcher\Matcher; |
6
|
|
|
use Netgen\Bundle\SiteAccessRoutesBundle\Matcher\Voter\VoterInterface; |
7
|
|
|
use Netgen\Bundle\SiteAccessRoutesBundle\Tests\TestCase; |
8
|
|
|
|
9
|
|
|
class MatcherTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var \Netgen\Bundle\SiteAccessRoutesBundle\Matcher\Matcher |
13
|
|
|
*/ |
14
|
|
|
protected $matcher; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject[] |
18
|
|
|
*/ |
19
|
|
|
protected $voterMocks; |
20
|
|
|
|
21
|
|
|
public function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->voterMocks = array( |
24
|
|
|
$this->createMock(VoterInterface::class), |
25
|
|
|
$this->createMock(VoterInterface::class), |
26
|
|
|
$this->createMock(VoterInterface::class), |
27
|
|
|
); |
28
|
|
|
|
29
|
|
|
$this->matcher = new Matcher($this->voterMocks); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param array $voterResults |
34
|
|
|
* @param bool $isAllowed |
35
|
|
|
* |
36
|
|
|
* @covers \Netgen\Bundle\SiteAccessRoutesBundle\Matcher\Matcher::__construct |
37
|
|
|
* @covers \Netgen\Bundle\SiteAccessRoutesBundle\Matcher\Matcher::isAllowed |
38
|
|
|
* |
39
|
|
|
* @dataProvider isAllowedProvider |
40
|
|
|
*/ |
41
|
|
|
public function testIsAllowed(array $voterResults, $isAllowed) |
42
|
|
|
{ |
43
|
|
|
foreach ($this->voterMocks as $index => $voter) { |
44
|
|
|
$voter |
45
|
|
|
->expects($this->any()) |
46
|
|
|
->method('vote') |
47
|
|
|
->will($this->returnValue($voterResults[$index])); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->assertEquals($isAllowed, $this->matcher->isAllowed('cro', array())); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function isAllowedProvider() |
54
|
|
|
{ |
55
|
|
|
return array( |
56
|
|
|
array(array(true, true, true), true), |
57
|
|
|
array(array(true, true, false), true), |
58
|
|
|
array(array(true, false, true), true), |
59
|
|
|
array(array(true, false, false), true), |
60
|
|
|
array(array(false, true, true), false), |
61
|
|
|
array(array(false, true, false), false), |
62
|
|
|
array(array(false, false, true), false), |
63
|
|
|
array(array(false, false, false), false), |
64
|
|
|
array(array(VoterInterface::ABSTAIN, true, true), true), |
65
|
|
|
array(array(VoterInterface::ABSTAIN, true, false), true), |
66
|
|
|
array(array(VoterInterface::ABSTAIN, false, true), false), |
67
|
|
|
array(array(VoterInterface::ABSTAIN, false, false), false), |
68
|
|
|
array(array(true, VoterInterface::ABSTAIN, true), true), |
69
|
|
|
array(array(true, VoterInterface::ABSTAIN, false), true), |
70
|
|
|
array(array(false, VoterInterface::ABSTAIN, true), false), |
71
|
|
|
array(array(false, VoterInterface::ABSTAIN, false), false), |
72
|
|
|
array(array(true, true, VoterInterface::ABSTAIN), true), |
73
|
|
|
array(array(true, false, VoterInterface::ABSTAIN), true), |
74
|
|
|
array(array(false, true, VoterInterface::ABSTAIN), false), |
75
|
|
|
array(array(false, false, VoterInterface::ABSTAIN), false), |
76
|
|
|
array(array(VoterInterface::ABSTAIN, VoterInterface::ABSTAIN, true), true), |
77
|
|
|
array(array(VoterInterface::ABSTAIN, VoterInterface::ABSTAIN, false), false), |
78
|
|
|
array(array(VoterInterface::ABSTAIN, true, VoterInterface::ABSTAIN), true), |
79
|
|
|
array(array(VoterInterface::ABSTAIN, false, VoterInterface::ABSTAIN), false), |
80
|
|
|
array(array(true, VoterInterface::ABSTAIN, VoterInterface::ABSTAIN), true), |
81
|
|
|
array(array(false, VoterInterface::ABSTAIN, VoterInterface::ABSTAIN), false), |
82
|
|
|
array(array(VoterInterface::ABSTAIN, VoterInterface::ABSTAIN, VoterInterface::ABSTAIN), false), |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|