Skip to content

Commit

Permalink
Adjust hierarchy when removing item
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Dec 18, 2023
1 parent 1cf5f37 commit 71f7eb7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- Enh #204: Add simple storages for items and assignments (@arogachev)
- Chg #217: Raise PHP version to 8.1 (@arogachev)
- Bug #221: Exclude items with base names when getting children (@arogachev)
- Bug #?: Adjust hierarchy when removing item (@arogachev)

## 1.0.2 April 20, 2023

Expand Down
5 changes: 5 additions & 0 deletions src/SimpleItemsStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ private function updateChildrenForItemName(string $name, Item $item): void
$this->children[$item->getName()] = $this->children[$name];
unset($this->children[$name]);
}

foreach ($this->children as &$children) {
if (isset($children[$name])) {
$children[$item->getName()] = $item;
Expand All @@ -268,6 +269,10 @@ private function updateChildrenForItemName(string $name, Item $item): void
private function removeItemByName(string $name): void
{
unset($this->items[$name]);

foreach ($this->children as &$children) {
unset($children[$name]);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Common/ManagerLogicTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public function testRemoveRole(): void
$this->assertNull($manager->getRole('reader'));
$this->assertSame($manager, $returnedManager);
$this->assertFalse($manager->userHasPermission('reader A', 'readPost'));
$this->assertEqualsCanonicalizing(['author B', 'admin C'], $manager->getUserIdsByRoleName('reader'));
$this->assertEqualsCanonicalizing([], $manager->getUserIdsByRoleName('reader'));
}

public function testUpdateRoleNameAndRule(): void
Expand Down

0 comments on commit 71f7eb7

Please sign in to comment.