diff --git a/CHANGELOG.md b/CHANGELOG.md index 880e7f04146..a40c39031b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ The present file will list all changes made to the project; according to the #### Changes #### Deprecated -- `Entity::cleanEntitySelectorCache` no longer has any effect as the entity selector is no longer cached as a unique entry +- `Entity::cleanEntitySelectorCache()` no longer has any effect as the entity selector is no longer cached as a unique entry #### Removed diff --git a/src/Entity.php b/src/Entity.php index 212eebaaf61..bb564fede76 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -678,7 +678,7 @@ public function cleanDBonPurge() */ public function cleanEntitySelectorCache() { - Toolbox::deprecated('Entity::cleanEntitySelectorCache no longer has any effect as the entity selector is no longer cached as a unique entry'); + Toolbox::deprecated('`Entity::cleanEntitySelectorCache()` no longer has any effect as the entity selector is no longer cached as a unique entry'); } public function rawSearchOptions() @@ -4146,6 +4146,9 @@ private static function getEntityTree(int $entities_id_root): array $grouped = []; foreach ($iterator as $row) { + if (!array_key_exists($row['entities_id'], $grouped)) { + $grouped[$row['entities_id']] = []; + } $grouped[$row['entities_id']][] = [ 'id' => $row['id'], 'name' => $row['name'] @@ -4157,8 +4160,10 @@ private static function getEntityTree(int $entities_id_root): array $tree = []; if (array_key_exists($root, $list)) { foreach ($list[$root] as $data) { - $tree[$data['id']]['name'] = $data['name']; - $tree[$data['id']]['tree'] = $fn_construct_tree_from_list($list, $data['id']); + $tree[$data['id']] = [ + 'name' => $data['name'], + 'tree' => $fn_construct_tree_from_list($list, $data['id']), + ]; } } return $tree; diff --git a/tests/functional/Entity.php b/tests/functional/Entity.php index b699c9cfdf3..c277e77944c 100644 --- a/tests/functional/Entity.php +++ b/tests/functional/Entity.php @@ -1157,7 +1157,90 @@ public function testRename() $this->string($new_entity->fields['name'])->isEqualTo('New entity'); } - public function testEntitySelector() + protected function entityTreeProvider(): iterable + { + $entity_test_root = getItemByTypeName('Entity', '_test_root_entity'); + $entity_test_child_1 = getItemByTypeName('Entity', '_test_child_1'); + $entity_test_child_2 = getItemByTypeName('Entity', '_test_child_2'); + + yield [ + 'entity_id' => 0, + 'result' => [ + 0 => [ + 'name' => 'Root entity', + 'tree' => [ + $entity_test_root->getID() => [ + 'name' => $entity_test_root->fields['name'], + 'tree' => [ + $entity_test_child_1->getID() => [ + 'name' => $entity_test_child_1->fields['name'], + 'tree' => [], + ], + $entity_test_child_2->getID() => [ + 'name' => $entity_test_child_2->fields['name'], + 'tree' => [], + ] + ] + ] + ] + ] + ] + ]; + + yield [ + 'entity_id' => $entity_test_root->getID(), + 'result' => [ + $entity_test_root->getID() => [ + 'name' => \Entity::sanitizeSeparatorInCompletename($entity_test_root->fields['completename']), + 'tree' => [ + $entity_test_child_1->getID() => [ + 'name' => $entity_test_child_1->fields['name'], + 'tree' => [], + ], + $entity_test_child_2->getID() => [ + 'name' => $entity_test_child_2->fields['name'], + 'tree' => [], + ] + ] + ] + ] + ]; + + yield [ + 'entity_id' => $entity_test_child_1->getID(), + 'result' => [ + $entity_test_child_1->getID() => [ + 'name' => \Entity::sanitizeSeparatorInCompletename($entity_test_child_1->fields['completename']), + 'tree' => [ + ] + ] + ] + ]; + + yield [ + 'entity_id' => $entity_test_child_2->getID(), + 'result' => [ + $entity_test_child_2->getID() => [ + 'name' => \Entity::sanitizeSeparatorInCompletename($entity_test_child_2->fields['completename']), + 'tree' => [ + ] + ] + ] + ]; + } + + /** + * @dataProvider entityTreeProvider + */ + public function testGetEntityTree(int $entity_id, array $result): void + { + $this->login(); + + $entity = $this->newTestedInstance(); + $this->array($this->callPrivateMethod($entity, 'getEntityTree', $entity_id))->isEqualTo($result); + } + + public function testGetEntitySelectorTree(): void { /** @var \DBmysql $DB */ global $DB;