From b34a957f8735b6fc9c117a09284b455e2135a357 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Mon, 25 Apr 2022 13:19:46 +0200 Subject: [PATCH] addSteps: clean project space after test --- .../features/bootstrap/SpacesContext.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 8200217e2fc..61d8f20b0d3 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -24,6 +24,7 @@ use Behat\Behat\Context\Context; use Behat\Behat\Hook\Scope\BeforeScenarioScope; +use Behat\Behat\Hook\Call\AfterScenario; use Behat\Gherkin\Node\TableNode; use Behat\Testwork\Environment\Environment; use GuzzleHttp\Exception\GuzzleException; @@ -333,6 +334,55 @@ public function setUpScenario(BeforeScenarioScope $scope): void { ); } + /** + * @AfterScenario + * + * @return void + * + * @throws Exception + */ + public function cleanDataAfterTests(): void + { + $this->deleteAllSpacesOfTheType('project'); + } + + /** + * The method first disables and then deletes spaces + * @param string $driveType + * + * @return void + * + * @throws Exception + */ + public function deleteAllSpacesOfTheType(string $driveType): void + { + $query = "\$filter=driveType eq $driveType"; + $userAdmin = $this->featureContext->getAdminUsername(); + + for ($i = 0; $i < 2; ++$i) { + $this->theUserListsAllHisAvailableSpacesUsingTheGraphApiWithFilter( + $userAdmin, + $query + ); + + $rawBody = $this->featureContext->getResponse()->getBody()->getContents(); + $drives = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR); + if (isset($drives["value"])) { + $drives = $drives["value"]; + } + + if (!empty($drives)) { + foreach ($drives as $value) { + if (!array_key_exists("deleted", $value["root"])) { + $this->sendDisableSpaceRequest($userAdmin, $value["name"]); + } else { + $this->sendDeleteSpaceRequest($userAdmin, $value["name"]); + } + } + } + } + } + /** * Send Graph List My Spaces Request *