Skip to content

Commit

Permalink
Merge pull request #4441 from owncloud/deleteAllProjectSpaceAfterTest
Browse files Browse the repository at this point in the history
[tests-only] [full-ci] ApiTest. after each test users-manager delete their project space
  • Loading branch information
phil-davis authored Aug 25, 2022
2 parents 9ceaf14 + c7a6d5a commit bbca91b
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,38 +420,44 @@ public function setUpScenario(BeforeScenarioScope $scope): void {
* @throws Exception|GuzzleException
*/
public function cleanDataAfterTests(): void {
// TODO enable when admin can disable and delete spaces
// $this->deleteAllSpacesOfTheType('project');
$this->deleteAllProjectSpaces();
$this->deleteAllPersonalSpaces();
}

/**
* Admin first disables and then deletes spaces
*
* @param string $driveType
* manager of the project space first disables and then deletes spaces
*
* @return void
*
* @throws Exception|GuzzleException
*/
public function deleteAllSpacesOfTheType(string $driveType): void {
$query = "\$filter=driveType eq $driveType";
public function deleteAllProjectSpaces(): void {
$query = "\$filter=driveType eq project";
$userAdmin = $this->featureContext->getAdminUsername();

for ($i = 0; $i < 2; ++$i) {
$this->theUserListsAllAvailableSpacesUsingTheGraphApi(
$userAdmin,
$query
);
$drives = $this->getAvailableSpaces();

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"]);
}
$this->theUserListsAllAvailableSpacesUsingTheGraphApi(
$userAdmin,
$query
);
$drives = $this->getAvailableSpaces();
$createdUsers = $this->featureContext->getCreatedUsers();

foreach ($drives as $value) {
foreach ($value["root"]["permissions"] as $permissions) {
// find an user who is a manager
if ($permissions["roles"][0] === "manager") {
$userId = $permissions["grantedTo"][0]["user"]["id"];

foreach ($createdUsers as $user) {
if ($user["id"] === $userId) {
$userName = $user["actualUsername"];

if (!\array_key_exists("deleted", $value["root"])) {
$this->sendDisableSpaceRequest($userName, $value["name"]);
}
$this->sendDeleteSpaceRequest($userName, $value["name"]);
}
}
}
}
}
Expand All @@ -466,9 +472,9 @@ public function deleteAllSpacesOfTheType(string $driveType): void {
*/
public function deleteAllPersonalSpaces(): void {
$query = "\$filter=driveType eq personal";
$createdUsers= $this->featureContext->getCreatedUsers();
$createdUsers = $this->featureContext->getCreatedUsers();

foreach($createdUsers as $user) {
foreach ($createdUsers as $user) {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi(
$user["actualUsername"],
$query
Expand Down Expand Up @@ -901,13 +907,11 @@ public function rememberTheAvailableSpaces(): void {
$drives = $drives["value"];
}

Assert::assertArrayHasKey(0, $drives, "No drives were found on that endpoint");
$spaces = [];
foreach ($drives as $drive) {
$spaces[$drive["name"]] = $drive;
}
$this->setAvailableSpaces($spaces);
Assert::assertNotEmpty($spaces, "No spaces have been found");
}

/**
Expand Down Expand Up @@ -3027,7 +3031,7 @@ public function forUserSpaceShouldContainLinks(
string $fileName = ''
): void {
$body = '';
if (!empty ($fileName)) {
if (!empty($fileName)) {
$body = $this->getFileId($user, $spaceName, $fileName);
} else {
$space = $this->getSpaceByName($user, $spaceName);
Expand Down

0 comments on commit bbca91b

Please sign in to comment.