Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit d97a787

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Validator] add Indonesian translation fixed CS [config] Fix issue when key removed and left value only [Security] AbstractVoter method supportsAttribute gives false positive if attribute is zero (0)
2 parents c5b0c58 + e396644 commit d97a787

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

Core/Authorization/Voter/AbstractVoter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract class AbstractVoter implements VoterInterface
3030
*/
3131
public function supportsAttribute($attribute)
3232
{
33-
return in_array($attribute, $this->getSupportedAttributes());
33+
return in_array($attribute, $this->getSupportedAttributes(), true);
3434
}
3535

3636
/**

Core/Tests/Authorization/Voter/AbstractVoterTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@
1818
*/
1919
class AbstractVoterTest extends \PHPUnit_Framework_TestCase
2020
{
21+
/**
22+
* @var TokenInterface
23+
*/
2124
protected $token;
2225

2326
protected function setUp()
2427
{
2528
$this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
2629
}
2730

31+
/**
32+
* @return array
33+
*/
2834
public function getTests()
2935
{
3036
return array(
@@ -55,4 +61,69 @@ public function testVote(array $attributes, $expectedVote, $object, $message)
5561

5662
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
5763
}
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+
}
58129
}

0 commit comments

Comments
 (0)