Skip to content

Commit

Permalink
Small fixes and test
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Jan 11, 2024
1 parent d1d1548 commit 4c11f06
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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']
Expand All @@ -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;
Expand Down
85 changes: 84 additions & 1 deletion tests/functional/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4c11f06

Please sign in to comment.