mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-24 04:58:31 -05:00
Refactored and added test to get user information with GraphAPI
This commit is contained in:
@@ -649,7 +649,7 @@ class GraphContext implements Context {
|
||||
public function theAdministratorTriesToAddUserToGroupUsingTheGraphAPI(string $user, string $group): void {
|
||||
$this->featureContext->setResponse($this->addUserToGroup($group, $user));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @When user :user tries to add himself/herself to group :group using the Graph API
|
||||
*
|
||||
@@ -874,7 +874,7 @@ class GraphContext implements Context {
|
||||
$response = $this->userDeletesGroupWithGroupId($groupId, $user);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Then the following users should be listed in the following groups
|
||||
*
|
||||
@@ -998,4 +998,82 @@ class GraphContext implements Context {
|
||||
}
|
||||
$this->featureContext->setResponse($this->removeUserFromGroup($groupId, $userId, $byUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws JsonException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function retrieveUserInformationUsingGraphApi(
|
||||
string $user
|
||||
):ResponseInterface {
|
||||
$credentials = $this->getAdminOrUserCredentials($user);
|
||||
return GraphHelper::getUserInformation(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$credentials["username"],
|
||||
$credentials["password"],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the user "([^"]*)" retrives (:?her|his) information using the Graph API$/
|
||||
*
|
||||
* @param string $user
|
||||
*
|
||||
* @return void
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userRetrievesHisorHerInformationOfUserUsingGraphApi(
|
||||
string $user
|
||||
):void {
|
||||
$response = $this->retrieveUserInformationUsingGraphApi($user);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^the api response for user "([^"]*)" should contains the following information:$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param TableNode $table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theApiResponseForUserShouldContainsTheFollowingInformation(string $user, TableNode $table): void {
|
||||
$rows = $table->getRowsHash();
|
||||
$apiResponse = \json_decode((string)$this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
|
||||
// assertion of the user is member of groups
|
||||
if ($rows['memberOf']) {
|
||||
// collect memberOf from response
|
||||
$memberOfFromApiReponse = [];
|
||||
$memberOf = preg_split('/\s*,\s*/', trim($rows['memberOf']));
|
||||
foreach ($apiResponse['memberOf'] as $member) {
|
||||
$memberOfFromApiReponse[] = $member['displayName'];
|
||||
}
|
||||
Assert::assertEqualsCanonicalizing($memberOf, $memberOfFromApiReponse);
|
||||
}
|
||||
// get user_id for the given user
|
||||
$rows['id'] = $this->featureContext->substituteInLineCodes(
|
||||
$rows['id'],
|
||||
$this->featureContext->getCurrentUser(),
|
||||
[],
|
||||
[
|
||||
[
|
||||
"code" => "%user_id%",
|
||||
"function" =>
|
||||
[$this->spacesContext, "getUserIdByUserName"],
|
||||
"parameter" => [$user]
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// assertion for remaining key other than 'memberOf'
|
||||
foreach (array_keys($rows) as $keyName) {
|
||||
if ($keyName !== 'memberOf') {
|
||||
Assert::assertEquals($rows[$keyName], $apiResponse[$keyName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user