-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from 5pm-HDH/feat/group-hierarchie
GroupHierarchie
- Loading branch information
Showing
9 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
|
||
namespace CTApi\Requests; | ||
|
||
|
||
use CTApi\CTClient; | ||
use CTApi\Utils\CTResponseUtil; | ||
|
||
abstract class GroupHierarchieAbstractRequest | ||
{ | ||
private $groupId; | ||
|
||
public function __construct(int $groupId) | ||
{ | ||
$this->groupId = $groupId; | ||
} | ||
|
||
protected function requestHierarchieObject() | ||
{ | ||
$client = CTClient::getClient(); | ||
$response = $client->get('api/groups/hierarchies', [ | ||
'json' => [ | ||
'ids' => [$this->groupId] | ||
] | ||
]); | ||
return CTResponseUtil::dataAsArray($response); | ||
} | ||
|
||
abstract public function get(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
|
||
namespace CTApi\Requests; | ||
|
||
|
||
class GroupHierarchieChildrenRequest extends GroupHierarchieAbstractRequest | ||
{ | ||
public function get(): array | ||
{ | ||
$hierarchie = $this->requestHierarchieObject(); | ||
$children = []; | ||
foreach ($hierarchie as $hierarchieItem) { | ||
if (array_key_exists("children", $hierarchieItem)) { | ||
foreach ($hierarchieItem["children"] as $childId) { | ||
$group = GroupRequest::find($childId); | ||
if ($group != null) { | ||
$children[] = $group; | ||
} | ||
} | ||
} | ||
} | ||
return $children; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
|
||
namespace CTApi\Requests; | ||
|
||
|
||
class GroupHierarchieParentsRequest extends GroupHierarchieAbstractRequest | ||
{ | ||
public function get(): array | ||
{ | ||
$hierarchie = $this->requestHierarchieObject(); | ||
$parents = []; | ||
foreach ($hierarchie as $hierarchieItem) { | ||
if (array_key_exists("parents", $hierarchieItem)) { | ||
foreach ($hierarchieItem["parents"] as $parentId) { | ||
$group = GroupRequest::find($parentId); | ||
if ($group != null) { | ||
$parents[] = $group; | ||
} | ||
} | ||
} | ||
} | ||
return $parents; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
|
||
namespace Tests\Integration\Requests; | ||
|
||
|
||
use CTApi\Requests\GroupRequest; | ||
use Tests\Integration\TestCaseAuthenticated; | ||
use Tests\Integration\TestData; | ||
|
||
class GroupHierarchieRequestTest extends TestCaseAuthenticated | ||
{ | ||
|
||
private $groupId = ""; | ||
private $groupName = ""; | ||
private $groupParentId = ""; | ||
private $groupParentName = ""; | ||
private $groupChildId = ""; | ||
private $groupChildName = ""; | ||
|
||
protected function setUp(): void | ||
{ | ||
if (!TestData::getValue("GROUP_HIERARCHIE_SHOULD_TEST") == "YES") { | ||
$this->markTestSkipped("Test suite is disabled in testdata.ini"); | ||
} else { | ||
$this->groupId = TestData::getValue("GROUP_HIERARCHIE_ID"); | ||
$this->groupName = TestData::getValue("GROUP_HIERARCHIE_NAME"); | ||
$this->groupParentId = TestData::getValue("GROUP_HIERARCHIE_PARENT_ID"); | ||
$this->groupParentName = TestData::getValue("GROUP_HIERARCHIE_PARENT_NAME"); | ||
$this->groupChildId = TestData::getValue("GROUP_HIERARCHIE_CHILD_ID"); | ||
$this->groupChildName = TestData::getValue("GROUP_HIERARCHIE_CHILD_NAME"); | ||
} | ||
} | ||
|
||
public function testRequestGroup() | ||
{ | ||
$group = GroupRequest::findOrFail($this->groupId); | ||
$this->assertEquals($this->groupName, $group->getName()); | ||
} | ||
|
||
public function testRequestGroupParents() | ||
{ | ||
$group = GroupRequest::findOrFail($this->groupId); | ||
|
||
$parents = $group->requestGroupParents()?->get(); | ||
$this->assertNotNull($parents); | ||
|
||
$foundParent = null; | ||
foreach ($parents as $parent) { | ||
if ($parent->getId() == $this->groupParentId) { | ||
$foundParent = $parent; | ||
} | ||
} | ||
|
||
$this->assertNotNull($foundParent); | ||
$this->assertEquals($this->groupParentName, $foundParent->getName()); | ||
} | ||
|
||
public function testRequestGroupChildren() | ||
{ | ||
$group = GroupRequest::findOrFail($this->groupId); | ||
|
||
$children = $group->requestGroupChildren()?->get(); | ||
$this->assertNotNull($children); | ||
|
||
$foundChild = null; | ||
foreach ($children as $child) { | ||
if ($child->getId() == $this->groupChildId) { | ||
$foundChild = $child; | ||
} | ||
} | ||
|
||
$this->assertNotNull($foundChild); | ||
$this->assertEquals($this->groupChildName, $foundChild->getName()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters