|
156 | 156 | ]); |
157 | 157 | }); |
158 | 158 |
|
| 159 | + it('must delete the ability when the rule is matched', function () { |
| 160 | + $repository = new MutableUserAbilityRepository( |
| 161 | + 1, |
| 162 | + $storage = new StorageFixture([ |
| 163 | + 1 => 'scope:resource/123:read', |
| 164 | + 2 => 'scope:resource/4:*', |
| 165 | + 3 => 'scope:resource2/123:read' |
| 166 | + ]) |
| 167 | + ); |
| 168 | + |
| 169 | + $repository->unsetAbility('read', '*', 'scope', 123); |
| 170 | + |
| 171 | + expect($storage->getRules()) |
| 172 | + ->toEqual([ |
| 173 | + 2 => 'scope:resource/4:*' |
| 174 | + ]); |
| 175 | + }); |
| 176 | + |
159 | 177 | it('must not remove the ability when the rule is unmatched', function () { |
160 | 178 | $repository = new MutableUserAbilityRepository( |
161 | 179 | 1, |
|
165 | 183 | ]) |
166 | 184 | ); |
167 | 185 |
|
168 | | - $repository->unsetAbility('*', 'resource', 'scope', 123); |
| 186 | + $repository->unsetAbility('update', 'resource', 'scope', 123); |
| 187 | + |
| 188 | + expect($storage->getRules()) |
| 189 | + ->toEqual([ |
| 190 | + 1 => 'scope:resource/123:read', |
| 191 | + 2 => 'scope:resource/4:*' |
| 192 | + ]); |
| 193 | + }); |
| 194 | + |
| 195 | + it('must only remove expected field when unset one item from arrayable field', function () { |
| 196 | + $repository = new MutableUserAbilityRepository( |
| 197 | + 1, |
| 198 | + $storage = new StorageFixture([ |
| 199 | + 1 => 'scope:resource/123:read', |
| 200 | + 2 => 'scope:resource/4:*', |
| 201 | + 3 => 'scope:resource/[6, 7, 8]:read' |
| 202 | + ]) |
| 203 | + ); |
| 204 | + |
| 205 | + $repository->unsetAbility('read', 'resource', 'scope', 7); |
| 206 | + |
| 207 | + expect($storage->getRules()) |
| 208 | + ->toEqual([ |
| 209 | + 1 => 'scope:resource/123:read', |
| 210 | + 2 => 'scope:resource/4:*', |
| 211 | + 3 => 'scope:resource/[6,8]:read' |
| 212 | + ]); |
| 213 | + }); |
| 214 | + |
| 215 | + it('must correctly remove 2 item from 3 item arrayable fields', function () { |
| 216 | + $repository = new MutableUserAbilityRepository( |
| 217 | + 1, |
| 218 | + $storage = new StorageFixture([ |
| 219 | + 1 => 'scope:resource/123:read', |
| 220 | + 2 => 'scope:resource/4:*', |
| 221 | + 3 => 'scope:resource/[6, 7, 8]:read' |
| 222 | + ]) |
| 223 | + ); |
| 224 | + |
| 225 | + $repository->unsetAbility('read', 'resource', 'scope', [6, 8]); |
| 226 | + |
| 227 | + expect($storage->getRules()) |
| 228 | + ->toEqual([ |
| 229 | + 1 => 'scope:resource/123:read', |
| 230 | + 2 => 'scope:resource/4:*', |
| 231 | + 3 => 'scope:resource/7:read' |
| 232 | + ]); |
| 233 | + }); |
| 234 | + |
| 235 | + it('must correctly remove the rule when unset all items from arrayable fields', function () { |
| 236 | + $repository = new MutableUserAbilityRepository( |
| 237 | + 1, |
| 238 | + $storage = new StorageFixture([ |
| 239 | + 1 => 'scope:resource/123:read', |
| 240 | + 2 => 'scope:resource/4:*', |
| 241 | + 3 => 'scope:resource/[6, 7, 8]:read' |
| 242 | + ]) |
| 243 | + ); |
| 244 | + |
| 245 | + $repository->unsetAbility('read', 'resource', 'scope', [6, 8, 7]); |
169 | 246 |
|
170 | 247 | expect($storage->getRules()) |
171 | 248 | ->toEqual([ |
|
0 commit comments