diff --git a/tests/TestHelpers/OcisHelper.php b/tests/TestHelpers/OcisHelper.php index 7b0026a900dd..af892967ed58 100644 --- a/tests/TestHelpers/OcisHelper.php +++ b/tests/TestHelpers/OcisHelper.php @@ -75,9 +75,10 @@ public static function getDeleteUserShareCommand() { * * @return void */ - public static function deleteRevaUserShares() { + public static function deleteRevaUserShares($user = "") { $deleteCmd = self::getDeleteUserShareCommand(); - if ($deleteCmd !== false) { + if ($deleteCmd !== false && $user !== "") { + $deleteCmd = \str_replace("%s", $user[0] . '/' . $user, $deleteCmd); \exec($deleteCmd); } } @@ -90,8 +91,7 @@ public static function deleteRevaUserShares() { public static function deleteRevaUserData($user = "") { $deleteCmd = self::getDeleteUserDataCommand(); if ($deleteCmd !== false) { - $deleteCmd = \sprintf($deleteCmd, $user[0] . '/' . $user); -// var_dump($deleteCmd); + $deleteCmd = \str_replace("%s", $user[0] . '/' . $user, $deleteCmd); \exec($deleteCmd); } else { self::recurseRmdir(self::getOcisRevaDataRoot() . "/data/" . $user); diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index f6d1f418b822..0206a49bce55 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -4247,20 +4247,21 @@ public function theListOfGroupsReturnedByTheApiShouldBeEmpty() { */ public function afterScenario() { $this->restoreParametersAfterScenario(); - if ($this->isTestingWithLdap()) { - $this->deleteLdapUsersAndGroups(); - } - $this->cleanupDatabaseUsers(); - $this->cleanupDatabaseGroups(); if (OcisHelper::isTestingOnOcis()) { foreach ($this->getCreatedUsers() as $user) { + OcisHelper::deleteRevaUserShares($user["actualUsername"]); + $this->deleteAllSharesForUser($user["actualUsername"]); OcisHelper::deleteRevaUserData($user["actualUsername"]); } - OcisHelper::deleteRevaUserShares(); } else { $this->resetAdminUserAttributes(); } + if ($this->isTestingWithLdap()) { + $this->deleteLdapUsersAndGroups(); + } + $this->cleanupDatabaseUsers(); + $this->cleanupDatabaseGroups(); } /** diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index affe35ba8264..74aab9445e1c 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -2757,6 +2757,34 @@ public function thePublicAccessesThePreviewOfTheSharedFileUsingTheSharingApi($pa $this->getPublicPreviewOfFile($path, $token); } + public function deleteAllSharesForUser($user) { + $user = $this->getActualUsername($user); + $url = $this->getSharesEndpointPath("?format=json"); + $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $user, "GET", $url, null + ); + if ($this->response->getStatusCode() !== 200) { + return; + } + $result = $this->response->getBody()->getContents(); + $usersShares = \json_decode($result, true); + if (!\is_array($usersShares)) { + throw new Exception( + __METHOD__ . " API result about shares is not valid JSON" + ); + } + if (!isset($usersShares['ocs']['data'])) { + return; + } + foreach ($usersShares['ocs']['data'] as $share) { + $share_id = $share['id']; + $url = $this->getSharesEndpointPath("/$share_id"); + $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $user, "DELETE", $url, null + ); + } + } + /** * replace values from table *