Refactor theResponseShouldContain test step

This commit is contained in:
Phil Davis
2022-12-29 12:34:11 +05:45
committed by sagargurung1001@gmail.com
parent 4bb0472d83
commit 07d3ff7dfb
3 changed files with 43 additions and 12 deletions
@@ -1505,6 +1505,7 @@ class SpacesContext implements Context {
$body
)
);
$this->setSpaceCreator($spaceName, $user);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201 (Created)"
@@ -2965,9 +2966,8 @@ class SpacesContext implements Context {
}
/**
* @Then /^for user "([^"]*)" the "([^"]*)" response should contain a (?:space|mountpoint) "([^"]*)" with these key and value pairs:$/
* @Then /^the "([^"]*)" response should contain a space "([^"]*)" with these key and value pairs:$/
*
* @param string $user
* @param string $method # method should be either PROPFIND or REPORT
* @param string $space
* @param TableNode $table
@@ -2976,8 +2976,39 @@ class SpacesContext implements Context {
* @throws GuzzleException
* @throws JsonException
*/
public function theResponseShouldContain(string $user, string $method, string $space, TableNode $table): void {
public function theResponseShouldContainSpace(string $method, string $space, TableNode $table): void {
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
$this->theResponseShouldContain($method, $this->getSpaceCreator($space), $space, $table);
}
/**
* @Then /^the "([^"]*)" response to user "([^"]*)" should contain a mountpoint "([^"]*)" with these key and value pairs:$/
*
* @param string $method # method should be either PROPFIND or REPORT
* @param string $user
* @param string $mountPoint
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function theResponseShouldContainMountPoint(string $method, string $user, string $mountPoint, TableNode $table): void {
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
$this->theResponseShouldContain($method, $user, $mountPoint, $table);
}
/**
* @param string $method # method should be either PROPFIND or REPORT
* @param string $user
* @param string $mountPoint # an entity inside a space, or the space itself
* @param TableNode $table
*
* @return void
* @throws GuzzleException
* @throws JsonException
*/
public function theResponseShouldContain(string $method, string $user, string $mountPoint, TableNode $table): void {
$xmlRes = $this->featureContext->getResponseXml();
foreach ($table->getHash() as $row) {
$findItem = $row['key'];
@@ -2989,23 +3020,23 @@ class SpacesContext implements Context {
$resourceType = $xmlRes->xpath("//d:response/d:propstat/d:prop/d:getcontenttype")[0]->__toString();
if ($method === 'PROPFIND') {
if (!$resourceType) {
Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong fileId in the response');
Assert::assertEquals($this->getFolderId($user, $mountPoint, $value), $responseValue, 'wrong fileId in the response');
} else {
Assert::assertEquals($this->getFileId($user, $space, $value), $responseValue, 'wrong fileId in the response');
Assert::assertEquals($this->getFileId($user, $mountPoint, $value), $responseValue, 'wrong fileId in the response');
}
} else {
if ($resourceType === 'httpd/unix-directory') {
Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong fileId in the response');
Assert::assertEquals($this->getFolderId($user, $mountPoint, $value), $responseValue, 'wrong fileId in the response');
} else {
Assert::assertEquals($this->getFileId($user, $space, $value), $responseValue, 'wrong fileId in the response');
Assert::assertEquals($this->getFileId($user, $mountPoint, $value), $responseValue, 'wrong fileId in the response');
}
}
break;
case "oc:file-parent":
Assert::assertEquals($this->getFolderId($user, $space, $value), $responseValue, 'wrong file-parentId in the response');
Assert::assertEquals($this->getFolderId($user, $mountPoint, $value), $responseValue, 'wrong file-parentId in the response');
break;
case "oc:privatelink":
Assert::assertEquals($this->getPrivateLink($user, $space), $responseValue, 'cannot find private link for space or resource in the response');
Assert::assertEquals($this->getPrivateLink($user, $mountPoint), $responseValue, 'cannot find private link for space or resource in the response');
break;
default:
Assert::assertEquals($value, $responseValue, "wrong $findItem in the response");