This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminBundle\Tests\Helper\Security\Acl\Permission; |
||
4 | |||
5 | use Exception; |
||
6 | use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\MaskBuilder; |
||
7 | use PHPUnit\Framework\TestCase; |
||
8 | |||
9 | /** |
||
10 | * MaskBuilderTest |
||
11 | */ |
||
12 | class MaskBuilderTest extends TestCase |
||
13 | { |
||
14 | /** |
||
15 | * @param mixed $invalidMask |
||
16 | * |
||
17 | * @dataProvider getInvalidConstructorData |
||
18 | */ |
||
19 | public function testSlugify($invalidMask) |
||
20 | { |
||
21 | $this->expectException(\InvalidArgumentException::class); |
||
22 | new MaskBuilder($invalidMask); |
||
23 | } |
||
24 | |||
25 | public function testGetCodeThrowsException() |
||
26 | { |
||
27 | $this->expectException(Exception::class); |
||
28 | $builder = new MaskBuilder(); |
||
29 | $builder->getCode(MaskBuilder::MASK_IDDQD); |
||
30 | } |
||
31 | |||
32 | public function testResolveMaskThrowsException() |
||
33 | { |
||
34 | $this->expectException(Exception::class); |
||
35 | $builder = new MaskBuilder(); |
||
36 | $builder->resolveMask('fail!'); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Provides data to the {@link testSlugify} function |
||
41 | * |
||
42 | * @return array |
||
0 ignored issues
–
show
|
|||
43 | */ |
||
44 | public function getInvalidConstructorData() |
||
45 | { |
||
46 | return array( |
||
47 | array(234.463), |
||
48 | array('asdgasdf'), |
||
49 | array(array()), |
||
50 | array(new \stdClass()), |
||
51 | ); |
||
52 | } |
||
53 | |||
54 | public function testConstructorWithoutArguments() |
||
55 | { |
||
56 | $builder = new MaskBuilder(); |
||
57 | |||
58 | $this->assertEquals(0, $builder->get()); |
||
59 | } |
||
60 | |||
61 | public function testConstructor() |
||
62 | { |
||
63 | $builder = new MaskBuilder(123456); |
||
64 | |||
65 | $this->assertEquals(123456, $builder->get()); |
||
66 | } |
||
67 | |||
68 | public function testAddAndRemove() |
||
69 | { |
||
70 | $builder = new MaskBuilder(); |
||
71 | |||
72 | $builder |
||
73 | ->add('view') |
||
74 | ->add('eDiT') |
||
75 | ->add('puBLisH'); |
||
76 | $mask = $builder->get(); |
||
77 | |||
78 | $this->assertEquals(MaskBuilder::MASK_VIEW, $mask & MaskBuilder::MASK_VIEW); |
||
79 | $this->assertEquals(MaskBuilder::MASK_EDIT, $mask & MaskBuilder::MASK_EDIT); |
||
80 | $this->assertEquals(MaskBuilder::MASK_PUBLISH, $mask & MaskBuilder::MASK_PUBLISH); |
||
81 | $this->assertEquals(0, $mask & MaskBuilder::MASK_DELETE); |
||
82 | $this->assertEquals(0, $mask & MaskBuilder::MASK_UNPUBLISH); |
||
83 | |||
84 | $builder->remove('edit')->remove('PUblish'); |
||
85 | $mask = $builder->get(); |
||
86 | $this->assertEquals(0, $mask & MaskBuilder::MASK_EDIT); |
||
87 | $this->assertEquals(0, $mask & MaskBuilder::MASK_PUBLISH); |
||
88 | $this->assertEquals(MaskBuilder::MASK_VIEW, $mask & MaskBuilder::MASK_VIEW); |
||
89 | } |
||
90 | |||
91 | public function testGetPattern() |
||
92 | { |
||
93 | $builder = new MaskBuilder(); |
||
94 | $this->assertEquals(MaskBuilder::ALL_OFF, $builder->getPattern()); |
||
95 | |||
96 | $builder->add('view'); |
||
97 | $this->assertEquals(str_repeat('.', 31).'V', $builder->getPattern()); |
||
98 | |||
99 | $builder->add('publish'); |
||
100 | $this->assertEquals(str_repeat('.', 27).'P...V', $builder->getPattern()); |
||
101 | |||
102 | $builder->add(1 << 10); |
||
103 | $this->assertEquals(str_repeat('.', 21).MaskBuilder::ON.'.....P...V', $builder->getPattern()); |
||
104 | } |
||
105 | |||
106 | public function testReset() |
||
107 | { |
||
108 | $builder = new MaskBuilder(); |
||
109 | $this->assertEquals(0, $builder->get()); |
||
110 | |||
111 | $builder->add('view'); |
||
112 | $this->assertTrue($builder->get() > 0); |
||
113 | |||
114 | $builder->reset(); |
||
115 | $this->assertEquals(0, $builder->get()); |
||
116 | } |
||
117 | |||
118 | public function testAddWithInvalidMask() |
||
119 | { |
||
120 | $this->expectException(\InvalidArgumentException::class); |
||
121 | $builder = new MaskBuilder(); |
||
122 | $builder->add(null); |
||
123 | } |
||
124 | |||
125 | public function testRemoveWithInvalidMask() |
||
126 | { |
||
127 | $this->expectException(\InvalidArgumentException::class); |
||
128 | $builder = new MaskBuilder(); |
||
129 | $builder->remove(null); |
||
130 | } |
||
131 | |||
132 | public function testGetCode() |
||
133 | { |
||
134 | $code = MaskBuilder::getCode(MaskBuilder::MASK_DELETE); |
||
135 | $this->assertEquals(MaskBuilder::CODE_DELETE, $code); |
||
136 | |||
137 | $code = MaskBuilder::getCode(MaskBuilder::MASK_UNPUBLISH); |
||
138 | $this->assertEquals(MaskBuilder::CODE_UNPUBLISH, $code); |
||
139 | } |
||
140 | |||
141 | public function testGetCodeWithInvalidMask() |
||
142 | { |
||
143 | $this->expectException(\InvalidArgumentException::class); |
||
144 | MaskBuilder::getCode(null); |
||
145 | } |
||
146 | |||
147 | public function testHas() |
||
148 | { |
||
149 | $builder = new MaskBuilder(); |
||
150 | $builder->add('edit') |
||
151 | ->add('view'); |
||
152 | |||
153 | $this->assertEquals(true, $builder->has(MaskBuilder::MASK_EDIT)); |
||
154 | $this->assertEquals(true, $builder->has('view')); |
||
155 | $this->assertEquals(false, $builder->has(MaskBuilder::MASK_UNPUBLISH)); |
||
156 | $this->assertEquals(false, $builder->has('publish')); |
||
157 | } |
||
158 | |||
159 | public function testHasWithInvalidMask() |
||
160 | { |
||
161 | $this->expectException(\InvalidArgumentException::class); |
||
162 | $builder = new MaskBuilder(); |
||
163 | $builder->add('edit') |
||
164 | ->add('view'); |
||
165 | |||
166 | $builder->has(null); |
||
167 | } |
||
168 | } |
||
169 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.