Merge pull request #4441 from owncloud/deleteAllProjectSpaceAfterTest

[tests-only] [full-ci] ApiTest. after each test users-manager delete their project space
This commit is contained in:
Phil Davis
2022-08-25 12:29:07 +05:45
committed by GitHub
@@ -420,38 +420,44 @@ class SpacesContext implements Context {
* @throws Exception|GuzzleException * @throws Exception|GuzzleException
*/ */
public function cleanDataAfterTests(): void { public function cleanDataAfterTests(): void {
// TODO enable when admin can disable and delete spaces $this->deleteAllProjectSpaces();
// $this->deleteAllSpacesOfTheType('project');
$this->deleteAllPersonalSpaces(); $this->deleteAllPersonalSpaces();
} }
/** /**
* Admin first disables and then deletes spaces * manager of the project space first disables and then deletes spaces
*
* @param string $driveType
* *
* @return void * @return void
* *
* @throws Exception|GuzzleException * @throws Exception|GuzzleException
*/ */
public function deleteAllSpacesOfTheType(string $driveType): void { public function deleteAllProjectSpaces(): void {
$query = "\$filter=driveType eq $driveType"; $query = "\$filter=driveType eq project";
$userAdmin = $this->featureContext->getAdminUsername(); $userAdmin = $this->featureContext->getAdminUsername();
for ($i = 0; $i < 2; ++$i) { $this->theUserListsAllAvailableSpacesUsingTheGraphApi(
$this->theUserListsAllAvailableSpacesUsingTheGraphApi( $userAdmin,
$userAdmin, $query
$query );
); $drives = $this->getAvailableSpaces();
$drives = $this->getAvailableSpaces(); $createdUsers = $this->featureContext->getCreatedUsers();
if (!empty($drives)) { foreach ($drives as $value) {
foreach ($drives as $value) { foreach ($value["root"]["permissions"] as $permissions) {
if (!\array_key_exists("deleted", $value["root"])) { // find an user who is a manager
$this->sendDisableSpaceRequest($userAdmin, $value["name"]); if ($permissions["roles"][0] === "manager") {
} else { $userId = $permissions["grantedTo"][0]["user"]["id"];
$this->sendDeleteSpaceRequest($userAdmin, $value["name"]);
} 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"]);
}
}
} }
} }
} }
@@ -466,9 +472,9 @@ class SpacesContext implements Context {
*/ */
public function deleteAllPersonalSpaces(): void { public function deleteAllPersonalSpaces(): void {
$query = "\$filter=driveType eq personal"; $query = "\$filter=driveType eq personal";
$createdUsers= $this->featureContext->getCreatedUsers(); $createdUsers = $this->featureContext->getCreatedUsers();
foreach($createdUsers as $user) { foreach ($createdUsers as $user) {
$this->theUserListsAllHisAvailableSpacesUsingTheGraphApi( $this->theUserListsAllHisAvailableSpacesUsingTheGraphApi(
$user["actualUsername"], $user["actualUsername"],
$query $query
@@ -901,13 +907,11 @@ class SpacesContext implements Context {
$drives = $drives["value"]; $drives = $drives["value"];
} }
Assert::assertArrayHasKey(0, $drives, "No drives were found on that endpoint");
$spaces = []; $spaces = [];
foreach ($drives as $drive) { foreach ($drives as $drive) {
$spaces[$drive["name"]] = $drive; $spaces[$drive["name"]] = $drive;
} }
$this->setAvailableSpaces($spaces); $this->setAvailableSpaces($spaces);
Assert::assertNotEmpty($spaces, "No spaces have been found");
} }
/** /**
@@ -3027,7 +3031,7 @@ class SpacesContext implements Context {
string $fileName = '' string $fileName = ''
): void { ): void {
$body = ''; $body = '';
if (!empty ($fileName)) { if (!empty($fileName)) {
$body = $this->getFileId($user, $spaceName, $fileName); $body = $this->getFileId($user, $spaceName, $fileName);
} else { } else {
$space = $this->getSpaceByName($user, $spaceName); $space = $this->getSpaceByName($user, $spaceName);