|
21 | 21 | use Authorization\Policy\BeforePolicyInterface; |
22 | 22 | use Authorization\Policy\Exception\MissingMethodException; |
23 | 23 | use Authorization\Policy\MapResolver; |
| 24 | +use Authorization\Policy\OrmResolver; |
24 | 25 | use Authorization\Policy\Result; |
25 | 26 | use Authorization\Policy\ResultInterface; |
| 27 | +use Cake\Datasource\QueryInterface; |
26 | 28 | use Cake\TestSuite\TestCase; |
27 | 29 | use TestApp\Model\Entity\Article; |
| 30 | +use TestApp\Model\Table\ArticlesTable; |
28 | 31 | use TestApp\Policy\ArticlePolicy; |
29 | 32 | use TestApp\Policy\MagicCallPolicy; |
30 | 33 |
|
@@ -173,6 +176,38 @@ public function testApplyScopeMethodMissing() |
173 | 176 | $result = $service->applyScope($user, 'nope', $article); |
174 | 177 | } |
175 | 178 |
|
| 179 | + public function testApplyScopeAdditionalArguments() |
| 180 | + { |
| 181 | + $service = new AuthorizationService(new OrmResolver()); |
| 182 | + $user = new IdentityDecorator($service, [ |
| 183 | + 'id' => 9, |
| 184 | + 'role' => 'admin', |
| 185 | + ]); |
| 186 | + |
| 187 | + $articles = new ArticlesTable(); |
| 188 | + $query = $this->createMock(QueryInterface::class); |
| 189 | + $query->method('getRepository') |
| 190 | + ->willReturn($articles); |
| 191 | + |
| 192 | + $query->expects($this->exactly(2)) |
| 193 | + ->method('where') |
| 194 | + ->with([ |
| 195 | + 'identity_id' => 9, |
| 196 | + 'firstArg' => 'first argument', |
| 197 | + 'secondArg' => false, |
| 198 | + ]) |
| 199 | + ->willReturn($query); |
| 200 | + |
| 201 | + $result = $service->applyScope($user, 'additionalArguments', $query, 'first argument', false); |
| 202 | + $this->assertInstanceOf(QueryInterface::class, $result); |
| 203 | + $this->assertSame($query, $result); |
| 204 | + |
| 205 | + // Test with named args as well |
| 206 | + $result = $service->applyScope($user, 'additionalArguments', $query, firstArg: 'first argument', secondArg: false); |
| 207 | + $this->assertInstanceOf(QueryInterface::class, $result); |
| 208 | + $this->assertSame($query, $result); |
| 209 | + } |
| 210 | + |
176 | 211 | public function testBeforeFalse() |
177 | 212 | { |
178 | 213 | $entity = new Article(); |
|
0 commit comments