Skip to content

Commit

Permalink
Refactor the fake spaceid function to get fake space_id for non-exist…
Browse files Browse the repository at this point in the history
…ent user
  • Loading branch information
SagarGi committed Nov 23, 2022
1 parent 2ba7c63 commit 72547f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
50 changes: 36 additions & 14 deletions tests/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,36 @@ public static function getPersonalSpaceIdForUser(string $baseUrl, string $user,
throw new Exception(__METHOD__ . " Personal space not found for user " . $user);
}

/**
* First checks if a user exist to return its space ID
* In case of any exception, it returns a fake space ID
*
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $xRequestId
*
* @return string
* @throws Exception
*/
public static function checkAndGetPersonalSpaceIdForUser(string $baseUrl, string $user, string $password, string $xRequestId):string {
try {
$spaceId = self::getPersonalSpaceIdForUser(
$baseUrl,
$user,
$password,
$xRequestId,
);
} catch (Exception $e) {
// if the fetch fails, and the user is not found, then a fake space id is prepared
// this is useful for testing when the personal space is of a non-existing user
$fakeSpaceId = self::generateUUIDv4();
self::$spacesIdRef[$user]["personal"] = $fakeSpaceId;
$spaceId = $fakeSpaceId;
}
return $spaceId;
}

/**
* sends a DAV request
*
Expand Down Expand Up @@ -597,20 +627,12 @@ public static function makeDavRequest(

// get space id if testing with spaces dav
if (self::$SPACE_ID_FROM_OCIS === '' && $davPathVersionToUse === self::DAV_VERSION_SPACES) {
try {
$spaceId = self::getPersonalSpaceIdForUser(
$baseUrl,
$doDavRequestAsUser ?? $user,
$password,
$xRequestId,
);
} catch (Exception $e) {
// if the fetch fails, and the user is not found, then a fake space id is prepared
// this is useful for testing when the personal space is of a non-existing user
$fakeSpaceId = self::generateUUIDv4();
self::$spacesIdRef[$user]["personal"] = $fakeSpaceId;
$spaceId = $fakeSpaceId;
}
$spaceId = self::checkAndGetPersonalSpaceIdForUser(
$baseUrl,
$doDavRequestAsUser ?? $user,
$password,
$xRequestId
);
} else {
$spaceId = self::$SPACE_ID_FROM_OCIS;
}
Expand Down
5 changes: 1 addition & 4 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3329,11 +3329,8 @@ public function substituteInLineCodes(
* @throws GuzzleException
*/
public function getPersonalSpaceIdForUser(string $user, bool $alwaysDoIt = false): ?string {
if ($user === 'non-existent-user') {
return WebDavHelper::generateUUIDv4();
}
if ($alwaysDoIt || ($this->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES)) {
return WebDavHelper::getPersonalSpaceIdForUser(
return WebDavHelper::checkAndGetPersonalSpaceIdForUser(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
Expand Down

0 comments on commit 72547f1

Please sign in to comment.