| @@ 47-244 (lines=198) @@ | ||
| 44 | ); |
|
| 45 | } |
|
| 46 | ||
| 47 | public function providerForTestGetPermissionsCriterion() |
|
| 48 | { |
|
| 49 | $criterionMock = $this |
|
| 50 | ->getMockBuilder(Criterion::class) |
|
| 51 | ->disableOriginalConstructor() |
|
| 52 | ->getMock(); |
|
| 53 | $limitationMock = $this |
|
| 54 | ->getMockBuilder(Limitation::class) |
|
| 55 | ->getMockForAbstractClass(); |
|
| 56 | $limitationMock |
|
| 57 | ->expects($this->any()) |
|
| 58 | ->method('getIdentifier') |
|
| 59 | ->will($this->returnValue('limitationIdentifier')); |
|
| 60 | ||
| 61 | $policy1 = new Policy(['limitations' => [$limitationMock]]); |
|
| 62 | $policy2 = new Policy(['limitations' => [$limitationMock, $limitationMock]]); |
|
| 63 | ||
| 64 | return [ |
|
| 65 | [ |
|
| 66 | $criterionMock, |
|
| 67 | 1, |
|
| 68 | [ |
|
| 69 | [ |
|
| 70 | 'limitation' => null, |
|
| 71 | 'policies' => [$policy1], |
|
| 72 | ], |
|
| 73 | ], |
|
| 74 | $criterionMock, |
|
| 75 | ], |
|
| 76 | [ |
|
| 77 | $criterionMock, |
|
| 78 | 2, |
|
| 79 | [ |
|
| 80 | [ |
|
| 81 | 'limitation' => null, |
|
| 82 | 'policies' => [$policy1, $policy1], |
|
| 83 | ], |
|
| 84 | ], |
|
| 85 | new Criterion\LogicalOr([$criterionMock, $criterionMock]), |
|
| 86 | ], |
|
| 87 | [ |
|
| 88 | $criterionMock, |
|
| 89 | 0, |
|
| 90 | [ |
|
| 91 | [ |
|
| 92 | 'limitation' => null, |
|
| 93 | 'policies' => [new Policy(['limitations' => '*']), $policy1], |
|
| 94 | ], |
|
| 95 | ], |
|
| 96 | false, |
|
| 97 | ], |
|
| 98 | [ |
|
| 99 | $criterionMock, |
|
| 100 | 0, |
|
| 101 | [ |
|
| 102 | [ |
|
| 103 | 'limitation' => null, |
|
| 104 | 'policies' => [new Policy(['limitations' => []]), $policy1], |
|
| 105 | ], |
|
| 106 | ], |
|
| 107 | false, |
|
| 108 | ], |
|
| 109 | [ |
|
| 110 | $criterionMock, |
|
| 111 | 2, |
|
| 112 | [ |
|
| 113 | [ |
|
| 114 | 'limitation' => null, |
|
| 115 | 'policies' => [$policy2], |
|
| 116 | ], |
|
| 117 | ], |
|
| 118 | new Criterion\LogicalAnd([$criterionMock, $criterionMock]), |
|
| 119 | ], |
|
| 120 | [ |
|
| 121 | $criterionMock, |
|
| 122 | 3, |
|
| 123 | [ |
|
| 124 | [ |
|
| 125 | 'limitation' => null, |
|
| 126 | 'policies' => [$policy1, $policy2], |
|
| 127 | ], |
|
| 128 | ], |
|
| 129 | new Criterion\LogicalOr( |
|
| 130 | [ |
|
| 131 | $criterionMock, |
|
| 132 | new Criterion\LogicalAnd([$criterionMock, $criterionMock]), |
|
| 133 | ] |
|
| 134 | ), |
|
| 135 | ], |
|
| 136 | [ |
|
| 137 | $criterionMock, |
|
| 138 | 2, |
|
| 139 | [ |
|
| 140 | [ |
|
| 141 | 'limitation' => null, |
|
| 142 | 'policies' => [$policy1], |
|
| 143 | ], |
|
| 144 | [ |
|
| 145 | 'limitation' => null, |
|
| 146 | 'policies' => [$policy1], |
|
| 147 | ], |
|
| 148 | ], |
|
| 149 | new Criterion\LogicalOr([$criterionMock, $criterionMock]), |
|
| 150 | ], |
|
| 151 | [ |
|
| 152 | $criterionMock, |
|
| 153 | 3, |
|
| 154 | [ |
|
| 155 | [ |
|
| 156 | 'limitation' => null, |
|
| 157 | 'policies' => [$policy1], |
|
| 158 | ], |
|
| 159 | [ |
|
| 160 | 'limitation' => null, |
|
| 161 | 'policies' => [$policy1, $policy1], |
|
| 162 | ], |
|
| 163 | ], |
|
| 164 | new Criterion\LogicalOr([$criterionMock, $criterionMock, $criterionMock]), |
|
| 165 | ], |
|
| 166 | [ |
|
| 167 | $criterionMock, |
|
| 168 | 3, |
|
| 169 | [ |
|
| 170 | [ |
|
| 171 | 'limitation' => null, |
|
| 172 | 'policies' => [$policy2], |
|
| 173 | ], |
|
| 174 | [ |
|
| 175 | 'limitation' => null, |
|
| 176 | 'policies' => [$policy1], |
|
| 177 | ], |
|
| 178 | ], |
|
| 179 | new Criterion\LogicalOr( |
|
| 180 | [ |
|
| 181 | new Criterion\LogicalAnd([$criterionMock, $criterionMock]), |
|
| 182 | $criterionMock, |
|
| 183 | ] |
|
| 184 | ), |
|
| 185 | ], |
|
| 186 | [ |
|
| 187 | $criterionMock, |
|
| 188 | 2, |
|
| 189 | [ |
|
| 190 | [ |
|
| 191 | 'limitation' => $limitationMock, |
|
| 192 | 'policies' => [$policy1], |
|
| 193 | ], |
|
| 194 | ], |
|
| 195 | new Criterion\LogicalAnd([$criterionMock, $criterionMock]), |
|
| 196 | ], |
|
| 197 | [ |
|
| 198 | $criterionMock, |
|
| 199 | 4, |
|
| 200 | [ |
|
| 201 | [ |
|
| 202 | 'limitation' => $limitationMock, |
|
| 203 | 'policies' => [$policy1], |
|
| 204 | ], |
|
| 205 | [ |
|
| 206 | 'limitation' => $limitationMock, |
|
| 207 | 'policies' => [$policy1], |
|
| 208 | ], |
|
| 209 | ], |
|
| 210 | new Criterion\LogicalOr( |
|
| 211 | [ |
|
| 212 | new Criterion\LogicalAnd([$criterionMock, $criterionMock]), |
|
| 213 | new Criterion\LogicalAnd([$criterionMock, $criterionMock]), |
|
| 214 | ] |
|
| 215 | ), |
|
| 216 | ], |
|
| 217 | [ |
|
| 218 | $criterionMock, |
|
| 219 | 1, |
|
| 220 | [ |
|
| 221 | [ |
|
| 222 | 'limitation' => $limitationMock, |
|
| 223 | 'policies' => [new Policy(['limitations' => '*'])], |
|
| 224 | ], |
|
| 225 | ], |
|
| 226 | $criterionMock, |
|
| 227 | ], |
|
| 228 | [ |
|
| 229 | $criterionMock, |
|
| 230 | 2, |
|
| 231 | [ |
|
| 232 | [ |
|
| 233 | 'limitation' => $limitationMock, |
|
| 234 | 'policies' => [new Policy(['limitations' => '*'])], |
|
| 235 | ], |
|
| 236 | [ |
|
| 237 | 'limitation' => $limitationMock, |
|
| 238 | 'policies' => [new Policy(['limitations' => '*'])], |
|
| 239 | ], |
|
| 240 | ], |
|
| 241 | new Criterion\LogicalOr([$criterionMock, $criterionMock]), |
|
| 242 | ], |
|
| 243 | ]; |
|
| 244 | } |
|
| 245 | ||
| 246 | protected function mockServices($criterionMock, $limitationCount, $permissionSets) |
|
| 247 | { |
|
| @@ 114-308 (lines=195) @@ | ||
| 111 | $this->assertEquals($expectedCriterion, $givenCriterion); |
|
| 112 | } |
|
| 113 | ||
| 114 | public function providerForTestGetPermissionsCriterion() |
|
| 115 | { |
|
| 116 | $criterionMock = $this->createMock(Criterion::class); |
|
| 117 | $limitationMock = $this |
|
| 118 | ->getMockBuilder(APILimitation::class) |
|
| 119 | ->getMockForAbstractClass(); |
|
| 120 | $limitationMock |
|
| 121 | ->expects($this->any()) |
|
| 122 | ->method('getIdentifier') |
|
| 123 | ->will($this->returnValue('limitationIdentifier')); |
|
| 124 | ||
| 125 | $policy1 = new Policy(array('limitations' => array($limitationMock))); |
|
| 126 | $policy2 = new Policy(array('limitations' => array($limitationMock, $limitationMock))); |
|
| 127 | ||
| 128 | return array( |
|
| 129 | array( |
|
| 130 | $criterionMock, |
|
| 131 | 1, |
|
| 132 | array( |
|
| 133 | array( |
|
| 134 | 'limitation' => null, |
|
| 135 | 'policies' => array($policy1), |
|
| 136 | ), |
|
| 137 | ), |
|
| 138 | $criterionMock, |
|
| 139 | ), |
|
| 140 | array( |
|
| 141 | $criterionMock, |
|
| 142 | 2, |
|
| 143 | array( |
|
| 144 | array( |
|
| 145 | 'limitation' => null, |
|
| 146 | 'policies' => array($policy1, $policy1), |
|
| 147 | ), |
|
| 148 | ), |
|
| 149 | new Criterion\LogicalOr(array($criterionMock, $criterionMock)), |
|
| 150 | ), |
|
| 151 | array( |
|
| 152 | $criterionMock, |
|
| 153 | 0, |
|
| 154 | array( |
|
| 155 | array( |
|
| 156 | 'limitation' => null, |
|
| 157 | 'policies' => array(new Policy(array('limitations' => '*')), $policy1), |
|
| 158 | ), |
|
| 159 | ), |
|
| 160 | false, |
|
| 161 | ), |
|
| 162 | array( |
|
| 163 | $criterionMock, |
|
| 164 | 0, |
|
| 165 | array( |
|
| 166 | array( |
|
| 167 | 'limitation' => null, |
|
| 168 | 'policies' => array(new Policy(array('limitations' => array())), $policy1), |
|
| 169 | ), |
|
| 170 | ), |
|
| 171 | false, |
|
| 172 | ), |
|
| 173 | array( |
|
| 174 | $criterionMock, |
|
| 175 | 2, |
|
| 176 | array( |
|
| 177 | array( |
|
| 178 | 'limitation' => null, |
|
| 179 | 'policies' => array($policy2), |
|
| 180 | ), |
|
| 181 | ), |
|
| 182 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
|
| 183 | ), |
|
| 184 | array( |
|
| 185 | $criterionMock, |
|
| 186 | 3, |
|
| 187 | array( |
|
| 188 | array( |
|
| 189 | 'limitation' => null, |
|
| 190 | 'policies' => array($policy1, $policy2), |
|
| 191 | ), |
|
| 192 | ), |
|
| 193 | new Criterion\LogicalOr( |
|
| 194 | array( |
|
| 195 | $criterionMock, |
|
| 196 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
|
| 197 | ) |
|
| 198 | ), |
|
| 199 | ), |
|
| 200 | array( |
|
| 201 | $criterionMock, |
|
| 202 | 2, |
|
| 203 | array( |
|
| 204 | array( |
|
| 205 | 'limitation' => null, |
|
| 206 | 'policies' => array($policy1), |
|
| 207 | ), |
|
| 208 | array( |
|
| 209 | 'limitation' => null, |
|
| 210 | 'policies' => array($policy1), |
|
| 211 | ), |
|
| 212 | ), |
|
| 213 | new Criterion\LogicalOr(array($criterionMock, $criterionMock)), |
|
| 214 | ), |
|
| 215 | array( |
|
| 216 | $criterionMock, |
|
| 217 | 3, |
|
| 218 | array( |
|
| 219 | array( |
|
| 220 | 'limitation' => null, |
|
| 221 | 'policies' => array($policy1), |
|
| 222 | ), |
|
| 223 | array( |
|
| 224 | 'limitation' => null, |
|
| 225 | 'policies' => array($policy1, $policy1), |
|
| 226 | ), |
|
| 227 | ), |
|
| 228 | new Criterion\LogicalOr(array($criterionMock, $criterionMock, $criterionMock)), |
|
| 229 | ), |
|
| 230 | array( |
|
| 231 | $criterionMock, |
|
| 232 | 3, |
|
| 233 | array( |
|
| 234 | array( |
|
| 235 | 'limitation' => null, |
|
| 236 | 'policies' => array($policy2), |
|
| 237 | ), |
|
| 238 | array( |
|
| 239 | 'limitation' => null, |
|
| 240 | 'policies' => array($policy1), |
|
| 241 | ), |
|
| 242 | ), |
|
| 243 | new Criterion\LogicalOr( |
|
| 244 | array( |
|
| 245 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
|
| 246 | $criterionMock, |
|
| 247 | ) |
|
| 248 | ), |
|
| 249 | ), |
|
| 250 | array( |
|
| 251 | $criterionMock, |
|
| 252 | 2, |
|
| 253 | array( |
|
| 254 | array( |
|
| 255 | 'limitation' => $limitationMock, |
|
| 256 | 'policies' => array($policy1), |
|
| 257 | ), |
|
| 258 | ), |
|
| 259 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
|
| 260 | ), |
|
| 261 | array( |
|
| 262 | $criterionMock, |
|
| 263 | 4, |
|
| 264 | array( |
|
| 265 | array( |
|
| 266 | 'limitation' => $limitationMock, |
|
| 267 | 'policies' => array($policy1), |
|
| 268 | ), |
|
| 269 | array( |
|
| 270 | 'limitation' => $limitationMock, |
|
| 271 | 'policies' => array($policy1), |
|
| 272 | ), |
|
| 273 | ), |
|
| 274 | new Criterion\LogicalOr( |
|
| 275 | array( |
|
| 276 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
|
| 277 | new Criterion\LogicalAnd(array($criterionMock, $criterionMock)), |
|
| 278 | ) |
|
| 279 | ), |
|
| 280 | ), |
|
| 281 | array( |
|
| 282 | $criterionMock, |
|
| 283 | 1, |
|
| 284 | array( |
|
| 285 | array( |
|
| 286 | 'limitation' => $limitationMock, |
|
| 287 | 'policies' => array(new Policy(array('limitations' => '*'))), |
|
| 288 | ), |
|
| 289 | ), |
|
| 290 | $criterionMock, |
|
| 291 | ), |
|
| 292 | array( |
|
| 293 | $criterionMock, |
|
| 294 | 2, |
|
| 295 | array( |
|
| 296 | array( |
|
| 297 | 'limitation' => $limitationMock, |
|
| 298 | 'policies' => array(new Policy(array('limitations' => '*'))), |
|
| 299 | ), |
|
| 300 | array( |
|
| 301 | 'limitation' => $limitationMock, |
|
| 302 | 'policies' => array(new Policy(array('limitations' => '*'))), |
|
| 303 | ), |
|
| 304 | ), |
|
| 305 | new Criterion\LogicalOr(array($criterionMock, $criterionMock)), |
|
| 306 | ), |
|
| 307 | ); |
|
| 308 | } |
|
| 309 | ||
| 310 | protected function mockServices($criterionMock, $limitationCount, $permissionSets) |
|
| 311 | { |
|