fix removing single permissions from event (#1661)
This commit is contained in:
@@ -36,8 +36,8 @@ final class PermissionsEvent extends Event
|
||||
public function removePermission(string $section, string $permission): PermissionsEvent
|
||||
{
|
||||
if (\array_key_exists($section, $this->sections)) {
|
||||
if (\array_key_exists($permission, $this->sections[$section])) {
|
||||
unset($this->sections[$section][$permission]);
|
||||
if (($key = array_search($permission, $this->sections[$section])) !== false) {
|
||||
unset($this->sections[$section][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,15 +36,22 @@ class PermissionsEventTest extends TestCase
|
||||
self::assertFalse($sut->hasSection('foo'));
|
||||
self::assertNull($sut->getSection('foo'));
|
||||
|
||||
$sut->addPermissions('bar', ['foo' => 123, 'hello' => 'world', 'test' => false]);
|
||||
self::assertEquals(['bar' => ['foo' => 123, 'hello' => 'world', 'test' => false]], $sut->getPermissions());
|
||||
$sut->addPermissions('bar', ['foo', 'hello', 'world', 'test']);
|
||||
self::assertEquals(['bar' => ['foo', 'hello', 'world', 'test']], $sut->getPermissions());
|
||||
|
||||
self::assertInstanceOf(PermissionsEvent::class, $sut->removePermission('bar', 'xxx'));
|
||||
self::assertEquals(['bar' => ['foo' => 123, 'hello' => 'world', 'test' => false]], $sut->getPermissions());
|
||||
self::assertEquals(['foo', 'hello', 'world', 'test'], array_values($sut->getSection('bar')));
|
||||
|
||||
self::assertInstanceOf(PermissionsEvent::class, $sut->removePermission('bar', 'foo'));
|
||||
self::assertEquals(['bar' => ['hello' => 'world', 'test' => false]], $sut->getPermissions());
|
||||
self::assertEquals(['hello', 'world', 'test'], array_values($sut->getSection('bar')));
|
||||
|
||||
self::assertInstanceOf(PermissionsEvent::class, $sut->removePermission('bar', 'test'));
|
||||
self::assertEquals(['bar' => ['hello' => 'world']], $sut->getPermissions());
|
||||
self::assertEquals(['hello', 'world'], array_values($sut->getSection('bar')));
|
||||
|
||||
self::assertInstanceOf(PermissionsEvent::class, $sut->removePermission('bar', 'hello'));
|
||||
self::assertEquals(['bar' => []], $sut->getPermissions());
|
||||
self::assertEquals(['world'], array_values($sut->getSection('bar')));
|
||||
|
||||
self::assertInstanceOf(PermissionsEvent::class, $sut->removePermission('bar', 'world'));
|
||||
self::assertEquals([], array_values($sut->getSection('bar')));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user