mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-24 05:51:33 -05:00
refactor given when then steps in settings and tus contexts (#7357)
set resource location from response addressed the reviews reset spaceidfromocis reset after scenario using after hook
This commit is contained in:
@@ -3391,6 +3391,7 @@ class FeatureContext extends BehatVariablesContext {
|
||||
if (\count(WebDavHelper::$spacesIdRef) > 0) {
|
||||
WebDavHelper::$spacesIdRef = [];
|
||||
}
|
||||
WebDavHelper::$SPACE_ID_FROM_OCIS = '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -349,12 +349,12 @@ class SettingsContext implements Context {
|
||||
* @param string $user
|
||||
* @param string $language
|
||||
*
|
||||
* @return void
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function sendRequestToSwitchSystemLanguage(string $user, string $language): void {
|
||||
public function sendRequestToSwitchSystemLanguage(string $user, string $language): ResponseInterface {
|
||||
$profileBundlesList = $this->getBundlesList($user, "Profile");
|
||||
Assert::assertNotEmpty($profileBundlesList, "bundles list is empty");
|
||||
|
||||
@@ -390,9 +390,12 @@ class SettingsContext implements Context {
|
||||
],
|
||||
JSON_THROW_ON_ERROR
|
||||
);
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->spacesContext->sendPostRequestToUrl($fullUrl, $user, $this->featureContext->getPasswordForUser($user), $body, $this->featureContext->getStepLineRef())
|
||||
return $this->spacesContext->sendPostRequestToUrl(
|
||||
$fullUrl,
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
$this->featureContext->getStepLineRef()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -405,12 +408,14 @@ class SettingsContext implements Context {
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function theUserHasSwitchedSysemLanguage(string $user, string $language): void {
|
||||
$this->sendRequestToSwitchSystemLanguage($user, $language);
|
||||
public function theUserHasSwitchedSystemLanguage(string $user, string $language): void {
|
||||
$response = $this->sendRequestToSwitchSystemLanguage($user, $language);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(
|
||||
201,
|
||||
"Expected response status code should be 201"
|
||||
"Expected response status code should be 201",
|
||||
$response
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,8 @@ class SpacesTUSContext implements Context {
|
||||
TableNode $headers
|
||||
): void {
|
||||
$this->spacesContext->setSpaceIDByName($user, $spaceName);
|
||||
$this->tusContext->createNewTUSResourceWithHeaders($user, $headers, $content);
|
||||
$response = $this->tusContext->createNewTUSResourceWithHeaders($user, $headers, $content);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@ use TusPhp\Exception\ConnectionException;
|
||||
use TusPhp\Exception\TusException;
|
||||
use TusPhp\Tus\Client;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
require_once 'bootstrap.php';
|
||||
|
||||
@@ -41,6 +42,40 @@ class TUSContext implements Context {
|
||||
|
||||
private ?string $resourceLocation = null;
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param TableNode $headers
|
||||
* @param string $content
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function createNewTUSResourceWithHeaders(string $user, TableNode $headers, string $content = ''): ResponseInterface {
|
||||
$this->featureContext->verifyTableNodeColumnsCount($headers, 2);
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$password = $this->featureContext->getUserPassword($user);
|
||||
$this->resourceLocation = null;
|
||||
|
||||
$response = $this->featureContext->makeDavRequest(
|
||||
$user,
|
||||
"POST",
|
||||
null,
|
||||
$headers->getRowsHash(),
|
||||
$content,
|
||||
"files",
|
||||
null,
|
||||
false,
|
||||
$password
|
||||
);
|
||||
$locationHeader = $response->getHeader('Location');
|
||||
if (\sizeof($locationHeader) > 0) {
|
||||
$this->resourceLocation = $locationHeader[0];
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user creates a new TUS resource on the WebDAV API with these headers:
|
||||
*
|
||||
@@ -53,29 +88,9 @@ class TUSContext implements Context {
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function createNewTUSResourceWithHeaders(string $user, TableNode $headers, string $content = ''): void {
|
||||
$this->featureContext->verifyTableNodeColumnsCount($headers, 2);
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$password = $this->featureContext->getUserPassword($user);
|
||||
$this->resourceLocation = null;
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->featureContext->makeDavRequest(
|
||||
$user,
|
||||
"POST",
|
||||
null,
|
||||
$headers->getRowsHash(),
|
||||
$content,
|
||||
"files",
|
||||
null,
|
||||
false,
|
||||
$password
|
||||
)
|
||||
);
|
||||
$locationHeader = $this->featureContext->getResponse()->getHeader('Location');
|
||||
if (\sizeof($locationHeader) > 0) {
|
||||
$this->resourceLocation = $locationHeader[0];
|
||||
}
|
||||
public function userCreateNewTUSResourceWithHeaders(string $user, TableNode $headers, string $content = ''): void {
|
||||
$response = $this->createNewTUSResourceWithHeaders($user, $headers, $content);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,46 +104,58 @@ class TUSContext implements Context {
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function createNewTUSResource(string $user, TableNode $headers): void {
|
||||
public function userHasCreatedNewTUSResourceWithHeaders(string $user, TableNode $headers): void {
|
||||
$rows = $headers->getRows();
|
||||
$rows[] = ['Tus-Resumable', '1.0.0'];
|
||||
$this->createNewTUSResourceWithHeaders($user, new TableNode($rows));
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(201);
|
||||
$response = $this->createNewTUSResourceWithHeaders($user, new TableNode($rows));
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(201, "", $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" sends a chunk to the last created TUS Location with offset "([^"]*)" and data "([^"]*)" using the WebDAV API$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $offset
|
||||
* @param string $data
|
||||
* @param string $checksum
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function sendsAChunkToTUSLocationWithOffsetAndData(string $user, string $offset, string $data, string $checksum = ''): ResponseInterface {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$password = $this->featureContext->getUserPassword($user);
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$this->resourceLocation,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
'PATCH',
|
||||
$user,
|
||||
$password,
|
||||
[
|
||||
'Content-Type' => 'application/offset+octet-stream',
|
||||
'Tus-Resumable' => '1.0.0',
|
||||
'Upload-Checksum' => $checksum,
|
||||
'Upload-Offset' => $offset
|
||||
],
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When user :user sends a chunk to the last created TUS Location with offset :offset and data :data using the WebDAV API
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $offset
|
||||
* @param string $data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws GuzzleException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function sendsAChunkToTUSLocationWithOffsetAndData(string $user, string $offset, string $data, string $checksum = ''): void {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$password = $this->featureContext->getUserPassword($user);
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$this->resourceLocation,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
'PATCH',
|
||||
$user,
|
||||
$password,
|
||||
[
|
||||
'Content-Type' => 'application/offset+octet-stream',
|
||||
'Tus-Resumable' => '1.0.0',
|
||||
'Upload-Checksum' => $checksum,
|
||||
'Upload-Offset' => $offset
|
||||
],
|
||||
$data
|
||||
)
|
||||
);
|
||||
WebDavHelper::$SPACE_ID_FROM_OCIS = '';
|
||||
public function userSendsAChunkToTUSLocationWithOffsetAndData(string $user, string $offset, string $data): void {
|
||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,7 +386,8 @@ class TUSContext implements Context {
|
||||
string $content,
|
||||
TableNode $headers
|
||||
): void {
|
||||
$this->createNewTUSResourceWithHeaders($user, $headers, $content);
|
||||
$response = $this->createNewTUSResourceWithHeaders($user, $headers, $content);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -407,7 +435,8 @@ class TUSContext implements Context {
|
||||
string $offset,
|
||||
string $content
|
||||
): void {
|
||||
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
|
||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -427,8 +456,8 @@ class TUSContext implements Context {
|
||||
string $offset,
|
||||
string $content
|
||||
): void {
|
||||
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(204);
|
||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $content, $checksum);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,7 +472,8 @@ class TUSContext implements Context {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userUploadsChunkFileWithChecksum(string $user, string $offset, string $data, string $checksum): void {
|
||||
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,8 +488,8 @@ class TUSContext implements Context {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userHasUploadedChunkFileWithChecksum(string $user, string $offset, string $data, string $checksum): void {
|
||||
$this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(204);
|
||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -478,7 +508,8 @@ class TUSContext implements Context {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userOverwritesFileWithChecksum(string $user, string $offset, string $data, string $checksum, TableNode $headers): void {
|
||||
$this->createNewTUSResource($user, $headers);
|
||||
$this->userHasUploadedChunkFileWithChecksum($user, $offset, $data, $checksum);
|
||||
$this->userHasCreatedNewTUSResourceWithHeaders($user, $headers);
|
||||
$response = $this->sendsAChunkToTUSLocationWithOffsetAndData($user, $offset, $data, $checksum);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user