mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-31 17:31:23 -05:00
Merge pull request #4488 from owncloud/refactoringTests
[test-only] Refactoring tests.
This commit is contained in:
@@ -14,7 +14,7 @@ use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* A helper class for managing users and groups using the Graph API
|
||||
* A helper class for managing Graph API requests
|
||||
*/
|
||||
class GraphHelper {
|
||||
/**
|
||||
@@ -524,6 +524,233 @@ class GraphHelper {
|
||||
return \json_encode($payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph Create Space Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $body
|
||||
* @param string $xRequestId
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function createSpace(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $body,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'drives');
|
||||
|
||||
return HttpRequestHelper::post($url, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph Update Space Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param mixed $body
|
||||
* @param string $spaceId
|
||||
* @param string $xRequestId
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function updateSpace(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
$body,
|
||||
string $spaceId,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'drives/' . $spaceId);
|
||||
|
||||
return HttpRequestHelper::sendRequest($url, $xRequestId, 'PATCH', $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph List My Spaces Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $urlArguments
|
||||
* @param string $xRequestId
|
||||
* @param array $body
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getMySpaces(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $urlArguments = '',
|
||||
string $xRequestId = '',
|
||||
array $body = [],
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'me/drives/' . $urlArguments);
|
||||
|
||||
return HttpRequestHelper::get($url, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph List All Spaces Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $urlArguments
|
||||
* @param string $xRequestId
|
||||
* @param array $body
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function getAllSpaces(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $urlArguments = '',
|
||||
string $xRequestId = '',
|
||||
array $body = [],
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'drives/' . $urlArguments);
|
||||
|
||||
return HttpRequestHelper::get($url, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph List Single Space Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $spaceId
|
||||
* @param string $urlArguments
|
||||
* @param string $xRequestId
|
||||
* @param array $body
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
*/
|
||||
public static function getSingleSpace(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $spaceId,
|
||||
string $urlArguments = '',
|
||||
string $xRequestId = '',
|
||||
array $body = [],
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'drives/' . $spaceId . "/" . $urlArguments);
|
||||
|
||||
return HttpRequestHelper::get($url, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* send disable space request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $spaceId
|
||||
* @param string $xRequestId
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function disableSpace(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $spaceId,
|
||||
string $xRequestId = ''
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'drives/' . $spaceId);
|
||||
|
||||
return HttpRequestHelper::delete(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$password
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* send delete space request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $spaceId
|
||||
* @param array $header
|
||||
* @param string $xRequestId
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function deleteSpace(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $spaceId,
|
||||
array $header,
|
||||
string $xRequestId = ''
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'drives/' . $spaceId);
|
||||
|
||||
return HttpRequestHelper::delete(
|
||||
$url,
|
||||
$xRequestId,
|
||||
$user,
|
||||
$password,
|
||||
$header
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send restore Space Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $spaceId
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function restoreSpace(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $spaceId
|
||||
): ResponseInterface {
|
||||
$url = self::getFullUrl($baseUrl, 'drives/' . $spaceId);
|
||||
$header = ["restore" => true];
|
||||
$body = '{}';
|
||||
|
||||
return HttpRequestHelper::sendRequest($url, '', 'PATCH', $user, $password, $header, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $baseUrl
|
||||
* @param string $xRequestId
|
||||
|
||||
@@ -495,113 +495,6 @@ class SpacesContext implements Context {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph List My Spaces Request
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $urlArguments
|
||||
* @param string $xRequestId
|
||||
* @param array $body
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function listMySpacesRequest(
|
||||
string $user,
|
||||
string $password,
|
||||
string $urlArguments = '',
|
||||
string $xRequestId = '',
|
||||
array $body = [],
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/me/drives/" . $urlArguments;
|
||||
|
||||
return HttpRequestHelper::get($fullUrl, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph List All Spaces Request
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $urlArguments
|
||||
* @param string $xRequestId
|
||||
* @param array $body
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function listAllSpacesRequest(
|
||||
string $user,
|
||||
string $password,
|
||||
string $urlArguments = '',
|
||||
string $xRequestId = '',
|
||||
array $body = [],
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $urlArguments;
|
||||
|
||||
return HttpRequestHelper::get($fullUrl, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph List Single Space Request
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $spaceId
|
||||
* @param string $urlArguments
|
||||
* @param string $xRequestId
|
||||
* @param array $body
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
*/
|
||||
public function listSingleSpaceRequest(
|
||||
string $user,
|
||||
string $password,
|
||||
string $spaceId,
|
||||
string $urlArguments = '',
|
||||
string $xRequestId = '',
|
||||
array $body = [],
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $spaceId . "/" . $urlArguments;
|
||||
|
||||
return HttpRequestHelper::get($fullUrl, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph Create Space Request
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $body
|
||||
* @param string $xRequestId
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sendCreateSpaceRequest(
|
||||
string $user,
|
||||
string $password,
|
||||
string $body,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/";
|
||||
|
||||
return HttpRequestHelper::post($fullUrl, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Propfind Request to Url
|
||||
*
|
||||
@@ -738,7 +631,8 @@ class SpacesContext implements Context {
|
||||
*/
|
||||
public function theUserListsAllHisAvailableSpacesUsingTheGraphApi(string $user, string $query = ''): void {
|
||||
$this->featureContext->setResponse(
|
||||
$this->listMySpacesRequest(
|
||||
GraphHelper::getMySpaces(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
"?" . $query
|
||||
@@ -759,7 +653,8 @@ class SpacesContext implements Context {
|
||||
*/
|
||||
public function theUserListsAllAvailableSpacesUsingTheGraphApi(string $user, string $query = ''): void {
|
||||
$this->featureContext->setResponse(
|
||||
$this->listAllSpacesRequest(
|
||||
GraphHelper::getAllSpaces(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
"?" . $query
|
||||
@@ -783,7 +678,8 @@ class SpacesContext implements Context {
|
||||
Assert::assertNotEmpty($spaceId = $space["id"]);
|
||||
Assert::assertNotEmpty($space["root"]["webDavUrl"]);
|
||||
$this->featureContext->setResponse(
|
||||
$this->listSingleSpaceRequest(
|
||||
GraphHelper::getSingleSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$spaceId
|
||||
@@ -811,12 +707,14 @@ class SpacesContext implements Context {
|
||||
$space = ["Name" => $spaceName, "driveType" => $spaceType];
|
||||
$body = json_encode($space, JSON_THROW_ON_ERROR);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendCreateSpaceRequest(
|
||||
GraphHelper::createSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body
|
||||
)
|
||||
);
|
||||
|
||||
$this->setSpaceCreator($spaceName, $user);
|
||||
}
|
||||
|
||||
@@ -842,7 +740,8 @@ class SpacesContext implements Context {
|
||||
$space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]];
|
||||
$body = json_encode($space);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendCreateSpaceRequest(
|
||||
GraphHelper::createSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body
|
||||
@@ -1630,7 +1529,8 @@ class SpacesContext implements Context {
|
||||
$body = json_encode($bodyData, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendUpdateSpaceRequest(
|
||||
GraphHelper::updateSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
@@ -1661,7 +1561,8 @@ class SpacesContext implements Context {
|
||||
$body = json_encode($bodyData, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendUpdateSpaceRequest(
|
||||
GraphHelper::updateSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
@@ -1693,7 +1594,8 @@ class SpacesContext implements Context {
|
||||
$body = json_encode($bodyData, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendUpdateSpaceRequest(
|
||||
GraphHelper::updateSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
@@ -1734,7 +1636,8 @@ class SpacesContext implements Context {
|
||||
$body = json_encode($bodyData, JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendUpdateSpaceRequest(
|
||||
GraphHelper::updateSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
@@ -1768,34 +1671,6 @@ class SpacesContext implements Context {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph Update Space Request
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param mixed $body
|
||||
* @param string $spaceId
|
||||
* @param string $xRequestId
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sendUpdateSpaceRequest(
|
||||
string $user,
|
||||
string $password,
|
||||
$body,
|
||||
string $spaceId,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/$spaceId";
|
||||
$method = 'PATCH';
|
||||
|
||||
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^user "([^"]*)" has created a space "([^"]*)" of type "([^"]*)" with quota "([^"]*)"$/
|
||||
*
|
||||
@@ -1816,7 +1691,8 @@ class SpacesContext implements Context {
|
||||
$space = ["Name" => $spaceName, "driveType" => $spaceType, "quota" => ["total" => $quota]];
|
||||
$body = json_encode($space);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendCreateSpaceRequest(
|
||||
GraphHelper::createSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body
|
||||
@@ -1846,7 +1722,8 @@ class SpacesContext implements Context {
|
||||
$space = ["Name" => $spaceName];
|
||||
$body = json_encode($space, JSON_THROW_ON_ERROR);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendCreateSpaceRequest(
|
||||
GraphHelper::createSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body
|
||||
@@ -2390,13 +2267,12 @@ class SpacesContext implements Context {
|
||||
string $spaceName
|
||||
): void {
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $space["id"];
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::delete(
|
||||
$fullUrl,
|
||||
"",
|
||||
GraphHelper::disableSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user)
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$space["id"]
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -2460,14 +2336,13 @@ class SpacesContext implements Context {
|
||||
): void {
|
||||
$header = ["Purge" => "T"];
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $space["id"];
|
||||
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::delete(
|
||||
$fullUrl,
|
||||
"",
|
||||
GraphHelper::deleteSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$space["id"],
|
||||
$header
|
||||
)
|
||||
);
|
||||
@@ -2493,18 +2368,12 @@ class SpacesContext implements Context {
|
||||
} else {
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
}
|
||||
$header = ["restore" => true];
|
||||
$body = '{}';
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/" . $space["id"];
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$fullUrl,
|
||||
"",
|
||||
'PATCH',
|
||||
GraphHelper::restoreSpace(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$header,
|
||||
$body
|
||||
$space["id"]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user