Merge pull request #2697 from owncloud/code-style
[tests-only] More refactoring
This commit is contained in:
1 file changed
+34
-16
@@ -3,6 +3,7 @@
|
|||||||
use Behat\Behat\Context\Context;
|
use Behat\Behat\Context\Context;
|
||||||
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
||||||
use Behat\Gherkin\Node\TableNode;
|
use Behat\Gherkin\Node\TableNode;
|
||||||
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use TestHelpers\HttpRequestHelper;
|
use TestHelpers\HttpRequestHelper;
|
||||||
use TestHelpers\SetupHelper;
|
use TestHelpers\SetupHelper;
|
||||||
@@ -96,7 +97,7 @@ class SpacesContext implements Context {
|
|||||||
*/
|
*/
|
||||||
public function getSpaceIdByName(string $name): string
|
public function getSpaceIdByName(string $name): string
|
||||||
{
|
{
|
||||||
$response = json_decode($this->featureContext->getResponse()->getBody(), true);
|
$response = json_decode($this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
|
||||||
if (isset($response['name']) && $response['name'] === $name) {
|
if (isset($response['name']) && $response['name'] === $name) {
|
||||||
return $response["id"];
|
return $response["id"];
|
||||||
}
|
}
|
||||||
@@ -113,10 +114,11 @@ class SpacesContext implements Context {
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getSpaceByName(string $name): array
|
public function getSpaceByName(string $name): array
|
||||||
{
|
{
|
||||||
$response = json_decode($this->featureContext->getResponse()->getBody(), true);
|
$response = json_decode($this->featureContext->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
|
||||||
$spaceAsArray = $response;
|
$spaceAsArray = $response;
|
||||||
if (isset($response['name']) && $response['name'] === $name) {
|
if (isset($response['name']) && $response['name'] === $name) {
|
||||||
return $response;
|
return $response;
|
||||||
@@ -162,6 +164,7 @@ class SpacesContext implements Context {
|
|||||||
* @param array $body
|
* @param array $body
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function listSpacesRequest(
|
public function listSpacesRequest(
|
||||||
string $baseUrl,
|
string $baseUrl,
|
||||||
@@ -191,6 +194,7 @@ class SpacesContext implements Context {
|
|||||||
* @param string $xRequestId
|
* @param string $xRequestId
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function sendCreateSpaceRequest(
|
public function sendCreateSpaceRequest(
|
||||||
string $baseUrl,
|
string $baseUrl,
|
||||||
@@ -219,6 +223,7 @@ class SpacesContext implements Context {
|
|||||||
* @param string $xRequestId
|
* @param string $xRequestId
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function sendPropfindRequestToUrl(
|
public function sendPropfindRequestToUrl(
|
||||||
string $fullUrl,
|
string $fullUrl,
|
||||||
@@ -234,8 +239,9 @@ class SpacesContext implements Context {
|
|||||||
/**
|
/**
|
||||||
* @When /^user "([^"]*)" lists all available spaces via the GraphApi$/
|
* @When /^user "([^"]*)" lists all available spaces via the GraphApi$/
|
||||||
*
|
*
|
||||||
* @param $user
|
* @param string $user
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function theUserListsAllHisAvailableSpacesUsingTheGraphApi(string $user): void
|
public function theUserListsAllHisAvailableSpacesUsingTheGraphApi(string $user): void
|
||||||
{
|
{
|
||||||
@@ -259,6 +265,8 @@ class SpacesContext implements Context {
|
|||||||
* @param string $spaceType
|
* @param string $spaceType
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws GuzzleException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function theUserCreatesASpaceUsingTheGraphApi(
|
public function theUserCreatesASpaceUsingTheGraphApi(
|
||||||
string $user,
|
string $user,
|
||||||
@@ -266,7 +274,7 @@ class SpacesContext implements Context {
|
|||||||
string $spaceType): void
|
string $spaceType): void
|
||||||
{
|
{
|
||||||
$space = ["Name" => $spaceName, "driveType" => $spaceType];
|
$space = ["Name" => $spaceName, "driveType" => $spaceType];
|
||||||
$body = json_encode($space);
|
$body = json_encode($space, JSON_THROW_ON_ERROR);
|
||||||
$this->featureContext->setResponse(
|
$this->featureContext->setResponse(
|
||||||
$this->sendCreateSpaceRequest(
|
$this->sendCreateSpaceRequest(
|
||||||
$this->featureContext->getBaseUrl(),
|
$this->featureContext->getBaseUrl(),
|
||||||
@@ -287,6 +295,8 @@ class SpacesContext implements Context {
|
|||||||
* @param int $quota
|
* @param int $quota
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws GuzzleException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function theUserCreatesASpaceWithQuotaUsingTheGraphApi(
|
public function theUserCreatesASpaceWithQuotaUsingTheGraphApi(
|
||||||
string $user,
|
string $user,
|
||||||
@@ -314,6 +324,8 @@ class SpacesContext implements Context {
|
|||||||
* @param string $role
|
* @param string $role
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws GuzzleException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function theAdministratorGivesUserTheRole(string $user, string $role): void
|
public function theAdministratorGivesUserTheRole(string $user, string $role): void
|
||||||
{
|
{
|
||||||
@@ -333,8 +345,8 @@ class SpacesContext implements Context {
|
|||||||
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}"));
|
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}"));
|
||||||
if ($this->featureContext->getResponse()) {
|
if ($this->featureContext->getResponse()) {
|
||||||
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
||||||
if (isset(\json_decode($rawBody, true)["bundles"])) {
|
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["bundles"])) {
|
||||||
$bundles = \json_decode($rawBody, true)["bundles"];
|
$bundles = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["bundles"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$roleToAssign = "";
|
$roleToAssign = "";
|
||||||
@@ -351,8 +363,8 @@ class SpacesContext implements Context {
|
|||||||
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}"));
|
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}"));
|
||||||
if ($this->featureContext->getResponse()) {
|
if ($this->featureContext->getResponse()) {
|
||||||
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
||||||
if (isset(\json_decode($rawBody, true)["accounts"])) {
|
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["accounts"])) {
|
||||||
$accounts = \json_decode($rawBody, true)["accounts"];
|
$accounts = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["accounts"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$accountToChange = "";
|
$accountToChange = "";
|
||||||
@@ -366,13 +378,13 @@ class SpacesContext implements Context {
|
|||||||
|
|
||||||
// set the new role
|
// set the new role
|
||||||
$fullUrl = $baseUrl . "api/v0/settings/assignments-add";
|
$fullUrl = $baseUrl . "api/v0/settings/assignments-add";
|
||||||
$body = json_encode(["account_uuid" => $accountToChange["id"], "role_id" => $roleToAssign["id"]]);
|
$body = json_encode(["account_uuid" => $accountToChange["id"], "role_id" => $roleToAssign["id"]], JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, $body));
|
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, $body));
|
||||||
if ($this->featureContext->getResponse()) {
|
if ($this->featureContext->getResponse()) {
|
||||||
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
||||||
if (isset(\json_decode($rawBody, true)["assignment"])) {
|
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["assignment"])) {
|
||||||
$assignment = \json_decode($rawBody, true)["assignment"];
|
$assignment = \json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["assignment"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,11 +397,13 @@ class SpacesContext implements Context {
|
|||||||
* Remember the available Spaces
|
* Remember the available Spaces
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function rememberTheAvailableSpaces(): void
|
public function rememberTheAvailableSpaces(): void
|
||||||
{
|
{
|
||||||
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
||||||
$drives = json_decode($rawBody, true);
|
$drives = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
|
||||||
if (isset($drives["value"])) {
|
if (isset($drives["value"])) {
|
||||||
$drives = $drives["value"];
|
$drives = $drives["value"];
|
||||||
}
|
}
|
||||||
@@ -409,6 +423,7 @@ class SpacesContext implements Context {
|
|||||||
* @param string $user
|
* @param string $user
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi(
|
public function theUserListsTheContentOfAPersonalSpaceRootUsingTheWebDAvApi(
|
||||||
string $user,
|
string $user,
|
||||||
@@ -457,6 +472,7 @@ class SpacesContext implements Context {
|
|||||||
* @param TableNode $table
|
* @param TableNode $table
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function jsonRespondedShouldContain(
|
public function jsonRespondedShouldContain(
|
||||||
string $spaceName,
|
string $spaceName,
|
||||||
@@ -476,7 +492,7 @@ class SpacesContext implements Context {
|
|||||||
"code" => "%space_id%",
|
"code" => "%space_id%",
|
||||||
"function" =>
|
"function" =>
|
||||||
[$this, "getSpaceIdByName"],
|
[$this, "getSpaceIdByName"],
|
||||||
"parameter" => ["$spaceName"]
|
"parameter" => [$spaceName]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -556,14 +572,14 @@ class SpacesContext implements Context {
|
|||||||
* and returns found search results if found else returns false
|
* and returns found search results if found else returns false
|
||||||
*
|
*
|
||||||
* @param string|null $entryNameToSearch
|
* @param string|null $entryNameToSearch
|
||||||
* @return string|array|boolean
|
* @return array
|
||||||
* string if $entryNameToSearch is given and is found
|
* string if $entryNameToSearch is given and is found
|
||||||
* array if $entryNameToSearch is not given
|
* array if $entryNameToSearch is not given
|
||||||
* boolean false if $entryNameToSearch is given and is not found
|
* boolean false if $entryNameToSearch is given and is not found
|
||||||
*/
|
*/
|
||||||
public function findEntryFromPropfindResponse(
|
public function findEntryFromPropfindResponse(
|
||||||
string $entryNameToSearch = null
|
string $entryNameToSearch = null
|
||||||
) {
|
): array {
|
||||||
$spaceId = $this->getResponseSpaceId();
|
$spaceId = $this->getResponseSpaceId();
|
||||||
//if we are using that step the second time in a scenario e.g. 'But ... should not'
|
//if we are using that step the second time in a scenario e.g. 'But ... should not'
|
||||||
//then don't parse the result again, because the result in a ResponseInterface
|
//then don't parse the result again, because the result in a ResponseInterface
|
||||||
@@ -608,7 +624,7 @@ class SpacesContext implements Context {
|
|||||||
if ($entryNameToSearch === null) {
|
if ($entryNameToSearch === null) {
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
return false;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -619,6 +635,7 @@ class SpacesContext implements Context {
|
|||||||
* @param string $spaceName
|
* @param string $spaceName
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function theUserCreatesAFolderUsingTheGraphApi(
|
public function theUserCreatesAFolderUsingTheGraphApi(
|
||||||
string $user,
|
string $user,
|
||||||
@@ -650,6 +667,7 @@ class SpacesContext implements Context {
|
|||||||
* @param string $xRequestId
|
* @param string $xRequestId
|
||||||
* @param array $headers
|
* @param array $headers
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
public function sendCreateFolderRequest(
|
public function sendCreateFolderRequest(
|
||||||
string $baseUrl,
|
string $baseUrl,
|
||||||
|
|||||||
Reference in new issue
Block a user