diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index bbe9eda598c..8200217e2fc 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -30,6 +30,7 @@ use Psr\Http\Message\ResponseInterface; use TestHelpers\HttpRequestHelper; use TestHelpers\SetupHelper; +use TestHelpers\GraphHelper; use PHPUnit\Framework\Assert; require_once 'bootstrap.php'; @@ -285,31 +286,23 @@ public function getETag(string $user, string $spaceName, string $fileName): stri * @return string */ public function getUserIdByUserName(string $userName): string { - $fullUrl = $this->baseUrl . "/api/v0/accounts/accounts-list"; - $this->featureContext->setResponse( - HttpRequestHelper::post( - $fullUrl, - "", - $this->featureContext->getAdminUsername(), - $this->featureContext->getAdminPassword(), - [], - "{}" - ) - ); + $this->featureContext->setResponse(GraphHelper::getUser( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $this->featureContext->getAdminUsername(), + $this->featureContext->getAdminPassword(), + $userName + )); if ($this->featureContext->getResponse()) { $rawBody = $this->featureContext->getResponse()->getBody()->getContents(); $response = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR); - if (isset($response["accounts"])) { - $accounts = $response["accounts"]; + if (isset($response["id"])) { + $user = $response; } else { throw new Exception(__METHOD__ . " accounts-list is empty"); } } - foreach ($accounts as $account) { - if ($account["preferredName"] === $userName) { - return $account["id"]; - } - } + return $user["id"]; throw new Exception(__METHOD__ . " user with name $userName not found"); } @@ -607,7 +600,6 @@ public function theAdministratorGivesUserTheRole(string $user, string $role): vo $password = $this->featureContext->getAdminPassword(); $headers = []; $bundles = []; - $accounts = []; $assignment = []; // get the roles list first @@ -628,22 +620,20 @@ public function theAdministratorGivesUserTheRole(string $user, string $role): vo } Assert::assertNotEmpty($roleToAssign, "The selected role $role could not be found"); - // get the accounts list first - $fullUrl = $this->baseUrl . "/api/v0/accounts/accounts-list"; - $this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}")); + $this->featureContext->setResponse(GraphHelper::getUser( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $this->featureContext->getAdminUsername(), + $this->featureContext->getAdminPassword(), + $user + )); if ($this->featureContext->getResponse()) { $rawBody = $this->featureContext->getResponse()->getBody()->getContents(); - if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["accounts"])) { - $accounts = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["accounts"]; - } - } - $accountToChange = ""; - foreach ($accounts as $account) { - // find the selected user - if ($account["preferredName"] === $user) { - $accountToChange = $account; + if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["id"])) { + $accountToChange = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR); } } + Assert::assertNotEmpty($accountToChange, "The selected account $user does not exist"); // set the new role