|
18 | 18 | */
|
19 | 19 | class AbstractVoterTest extends \PHPUnit_Framework_TestCase
|
20 | 20 | {
|
| 21 | + /** |
| 22 | + * @var TokenInterface |
| 23 | + */ |
21 | 24 | protected $token;
|
22 | 25 |
|
23 | 26 | protected function setUp()
|
24 | 27 | {
|
25 | 28 | $this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
26 | 29 | }
|
27 | 30 |
|
| 31 | + /** |
| 32 | + * @return array |
| 33 | + */ |
28 | 34 | public function getTests()
|
29 | 35 | {
|
30 | 36 | return array(
|
@@ -55,4 +61,69 @@ public function testVote(array $attributes, $expectedVote, $object, $message)
|
55 | 61 |
|
56 | 62 | $this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
|
57 | 63 | }
|
| 64 | + |
| 65 | + /** |
| 66 | + * @return array |
| 67 | + */ |
| 68 | + public function getSupportsAttributeData() |
| 69 | + { |
| 70 | + return array( |
| 71 | + 'positive_string_edit' => array( |
| 72 | + 'expected' => true, |
| 73 | + 'attribute' => 'EDIT', |
| 74 | + 'message' => 'expected TRUE given as attribute EDIT is supported', |
| 75 | + ), |
| 76 | + 'positive_string_create' => array( |
| 77 | + 'expected' => true, |
| 78 | + 'attribute' => 'CREATE', |
| 79 | + 'message' => 'expected TRUE as given attribute CREATE is supported', |
| 80 | + ), |
| 81 | + |
| 82 | + 'negative_string_read' => array( |
| 83 | + 'expected' => false, |
| 84 | + 'attribute' => 'READ', |
| 85 | + 'message' => 'expected FALSE as given attribute READ is not supported', |
| 86 | + ), |
| 87 | + 'negative_string_random' => array( |
| 88 | + 'expected' => false, |
| 89 | + 'attribute' => 'random', |
| 90 | + 'message' => 'expected FALSE as given attribute "random" is not supported', |
| 91 | + ), |
| 92 | + 'negative_string_0' => array( |
| 93 | + 'expected' => false, |
| 94 | + 'attribute' => '0', |
| 95 | + 'message' => 'expected FALSE as given attribute "0" is not supported', |
| 96 | + ), |
| 97 | + // this set of data gives false positive if in_array is not used with strict flag set to 'true' |
| 98 | + 'negative_int_0' => array( |
| 99 | + 'expected' => false, |
| 100 | + 'attribute' => 0, |
| 101 | + 'message' => 'expected FALSE as given attribute 0 is not string', |
| 102 | + ), |
| 103 | + 'negative_int_1' => array( |
| 104 | + 'expected' => false, |
| 105 | + 'attribute' => 1, |
| 106 | + 'message' => 'expected FALSE as given attribute 1 is not string', |
| 107 | + ), |
| 108 | + 'negative_int_7' => array( |
| 109 | + 'expected' => false, |
| 110 | + 'attribute' => 7, |
| 111 | + 'message' => 'expected FALSE as attribute 7 is not string', |
| 112 | + ), |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @dataProvider getSupportsAttributeData |
| 118 | + * |
| 119 | + * @param bool $expected |
| 120 | + * @param string $attribute |
| 121 | + * @param string $message |
| 122 | + */ |
| 123 | + public function testSupportsAttribute($expected, $attribute, $message) |
| 124 | + { |
| 125 | + $voter = new AbstractVoterTest_Voter(); |
| 126 | + |
| 127 | + $this->assertEquals($expected, $voter->supportsAttribute($attribute), $message); |
| 128 | + } |
58 | 129 | }
|
0 commit comments