add method to create folder

This commit is contained in:
Saw-jan
2023-10-06 14:55:38 +05:45
committed by Sawjan Gurung
parent b0ef3aad5f
commit 18ac0425cb
2 changed files with 44 additions and 61 deletions
@@ -1156,7 +1156,8 @@ class SpacesContext implements Context {
$ownerUser = $user; $ownerUser = $user;
} }
$this->setSpaceIDByName($ownerUser, $spaceName); $this->setSpaceIDByName($ownerUser, $spaceName);
$this->featureContext->userCreatesFolder($user, $folder); $response = $this->featureContext->createFolder($user, $folder);
$this->featureContext->setResponse($response);
} }
/** /**
+42 -60
View File
@@ -446,6 +446,34 @@ trait WebDav {
); );
} }
/**
*
* @param string $user
* @param string $folder
* @param bool|null $isGivenStep
*
* @return ResponseInterface
* @throws JsonException | GuzzleException
* @throws GuzzleException | JsonException
*/
public function createFolder(string $user, string $folder, ?bool $isGivenStep = false): ResponseInterface {
$folder = '/' . \ltrim($folder, '/');
return $this->makeDavRequest(
$user,
"MKCOL",
$folder,
[],
null,
"files",
null,
false,
null,
[],
null,
$isGivenStep
);
}
/** /**
* @param string $user * @param string $user
* @param string|null $path * @param string|null $path
@@ -3628,32 +3656,14 @@ trait WebDav {
* *
* @param string $user * @param string $user
* @param string $destination * @param string $destination
* @param bool|null $isGivenStep
* *
* @return void * @return void
* @throws JsonException | GuzzleException * @throws JsonException | GuzzleException
* @throws GuzzleException | JsonException * @throws GuzzleException | JsonException
*/ */
public function userCreatesFolder(string $user, string $destination, ?bool $isGivenStep = false):void { public function userCreatesFolder(string $user, string $destination):void {
$user = $this->getActualUsername($user); $response = $this->createFolder($user, $destination);
$destination = '/' . \ltrim($destination, '/'); $this->setResponse($response);
$this->response = $this->makeDavRequest(
$user,
"MKCOL",
$destination,
[],
null,
"files",
null,
false,
null,
[],
null,
$isGivenStep
);
$this->setResponseXml(
HttpRequestHelper::parseResponseAsXml($this->response)
);
$this->pushToLastHttpStatusCodesArray(); $this->pushToLastHttpStatusCodesArray();
} }
@@ -3668,13 +3678,12 @@ trait WebDav {
* @throws GuzzleException * @throws GuzzleException
*/ */
public function userHasCreatedFolder(string $user, string $destination):void { public function userHasCreatedFolder(string $user, string $destination):void {
$user = $this->getActualUsername($user); $response = $this->createFolder($user, $destination, true);
$this->userCreatesFolder($user, $destination, true);
$this->theHTTPStatusCodeShouldBe( $this->theHTTPStatusCodeShouldBe(
["201", "204"], ["201", "204"],
"HTTP status code was not 201 or 204 while trying to create folder '$destination' for user '$user'" "HTTP status code was not 201 or 204 while trying to create folder '$destination' for user '$user'",
$response
); );
$this->emptyLastHTTPStatusCodesArray();
} }
/** /**
@@ -3693,13 +3702,13 @@ trait WebDav {
$admin, $admin,
__METHOD__ . "The provided user is not admin but '" . $admin . "'" __METHOD__ . "The provided user is not admin but '" . $admin . "'"
); );
$this->userCreatesFolder($admin, $destination, true); $response = $this->createFolder($user, $destination, true);
$this->theHTTPStatusCodeShouldBe( $this->theHTTPStatusCodeShouldBe(
["201", "204"], ["201", "204"],
"HTTP status code was not 201 or 204 while trying to create folder '$destination' for admin '$admin'" "HTTP status code was not 201 or 204 while trying to create folder '$destination' for admin '$admin'",
$response
); );
$this->adminResources[] = $destination; $this->adminResources[] = $destination;
$this->emptyLastHTTPStatusCodesArray();
} }
/** /**
@@ -3720,32 +3729,6 @@ trait WebDav {
} }
} }
/**
* @When the user creates folder :destination using the WebDAV API
*
* @param string $destination
*
* @return void
*/
public function theUserCreatesFolder(string $destination):void {
$this->userCreatesFolder($this->getCurrentUser(), $destination);
}
/**
* @Given the user has created folder :destination
*
* @param string $destination
*
* @return void
*/
public function theUserHasCreatedFolder(string $destination):void {
$this->theUserCreatesFolder($destination);
$this->theHTTPStatusCodeShouldBe(
["201", "204"],
"HTTP status code was not 201 or 204 while trying to create folder '$destination'"
);
}
/** /**
* @Then user :user should be able to create folder :destination * @Then user :user should be able to create folder :destination
* *
@@ -3775,12 +3758,11 @@ trait WebDav {
*/ */
public function userShouldNotBeAbleToCreateFolder(string $user, string $destination):void { public function userShouldNotBeAbleToCreateFolder(string $user, string $destination):void {
$user = $this->getActualUsername($user); $user = $this->getActualUsername($user);
$this->userCreatesFolder($user, $destination); $response = $this->createFolder($user, $destination);
$this->theHTTPStatusCodeShouldBeFailure(); Assert::assertNotEquals(
$this->asFileOrFolderShouldNotExist( 201,
$user, $response->getStatusCode(),
"folder", "User '$user' should not be able to create folder '$destination' but was successful"
$destination
); );
} }