diff --git a/tests/acceptance/bootstrap/Provisioning.php b/tests/acceptance/bootstrap/Provisioning.php index da1187140..51dd7e755 100644 --- a/tests/acceptance/bootstrap/Provisioning.php +++ b/tests/acceptance/bootstrap/Provisioning.php @@ -1985,8 +1985,29 @@ trait Provisioning { if ($this->isTestingWithLdap()) { $this->deleteLdapUsersAndGroups(); } + + $assertionFailed = false; + $errorMessage = ''; + + // check that created users have only one personal space + try { + $this->setResponse( + $this->spacesContext->listAllAvailableSpaces("admin", "%24filter=driveType+eq+personal") + ); + $this->spacesContext->jsonRespondedShouldContainOnlyOneSpace(); + $this->spacesContext->jsonRespondedShouldNotContainSpaceWithoutName(); + } catch (\Throwable $e) { + $assertionFailed = true; + $errorMessage = $e->getMessage(); + echo "\n[WARNING] Space assertion failed: " . $errorMessage . "\n"; + } + $this->cleanupDatabaseUsers(); $this->cleanupDatabaseGroups(); + + if ($assertionFailed) { + throw new \Exception("Space assertion failed:\n" . $errorMessage); + } } /** diff --git a/tests/acceptance/bootstrap/SpacesContext.php b/tests/acceptance/bootstrap/SpacesContext.php index c21ffd2f0..4ab268302 100644 --- a/tests/acceptance/bootstrap/SpacesContext.php +++ b/tests/acceptance/bootstrap/SpacesContext.php @@ -1087,6 +1087,74 @@ class SpacesContext implements Context { ); } + /** + * @return void + * @throws Exception + */ + public function jsonRespondedShouldContainOnlyOneSpace(): void { + $response = $response ?? $this->featureContext->getResponse(); + $decodedResponse = $this->featureContext->getJsonDecodedResponse($response); + $userAdmin = $this->featureContext->getAdminUsername(); + + $aliases = []; + foreach ($decodedResponse['value'] as $space) { + $alias = $space['driveAlias']; + if (isset($aliases[$alias])) { + GraphHelper::disableSpace( + $this->featureContext->getBaseUrl(), + $userAdmin, + $this->featureContext->getPasswordForUser($userAdmin), + $space["id"], + $this->featureContext->getStepLineRef() + ); + GraphHelper::deleteSpace( + $this->featureContext->getBaseUrl(), + $userAdmin, + $this->featureContext->getPasswordForUser($userAdmin), + $space["id"], + $this->featureContext->getStepLineRef() + ); + Assert::fail( + "Duplicate space found: '$alias'\nResponse:\n" . json_encode($decodedResponse, JSON_PRETTY_PRINT) + ); + } + $aliases[$alias] = true; + } + + } + + /** + * @return void + * @throws Exception + */ + public function jsonRespondedShouldNotContainSpaceWithoutName(): void { + $response = $response ?? $this->featureContext->getResponse(); + $decodedResponse = $this->featureContext->getJsonDecodedResponse($response); + $userAdmin = $this->featureContext->getAdminUsername(); + + foreach ($decodedResponse['value'] as $space) { + if ($space['name'] === "") { + GraphHelper::disableSpace( + $this->featureContext->getBaseUrl(), + $userAdmin, + $this->featureContext->getPasswordForUser($userAdmin), + $space["id"], + $this->featureContext->getStepLineRef() + ); + GraphHelper::deleteSpace( + $this->featureContext->getBaseUrl(), + $userAdmin, + $this->featureContext->getPasswordForUser($userAdmin), + $space["id"], + $this->featureContext->getStepLineRef() + ); + Assert::fail( + "Space without name found. \nResponse:\n" . json_encode($decodedResponse, JSON_PRETTY_PRINT) + ); + } + } + } + /** * @Then /^the user "([^"]*)" should (not |)have a space called "([^"]*)"$/ *