Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] backport removing the setresponse in given/then step in CheckSumContext and FavoritesContext #7268

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 83 additions & 37 deletions tests/acceptance/features/bootstrap/ChecksumContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use PHPUnit\Framework\Assert;
use TestHelpers\WebDavHelper;
use Psr\Http\Message\ResponseInterface;

require_once 'bootstrap.php';

Expand All @@ -33,32 +34,48 @@ class ChecksumContext implements Context {
private FeatureContext $featureContext;

/**
* @When user :user uploads file :source to :destination with checksum :checksum using the WebDAV API
*
* @param string $user
* @param string $source
* @param string $destination
* @param string $checksum
*
* @return void
* @return ResponseInterface
*/
public function userUploadsFileToWithChecksumUsingTheAPI(
public function uploadFileToWithChecksumUsingTheAPI(
string $user,
string $source,
string $destination,
string $checksum
):void {
):ResponseInterface {
$file = \file_get_contents(
$this->featureContext->acceptanceTestsDirLocation() . $source
);
$response = $this->featureContext->makeDavRequest(
return $this->featureContext->makeDavRequest(
$user,
'PUT',
$destination,
['OC-Checksum' => $checksum],
$file
);
$this->featureContext->setResponse($response);
}

/**
* @When user :user uploads file :source to :destination with checksum :checksum using the WebDAV API
*
* @param string $user
* @param string $source
* @param string $destination
* @param string $checksum
*
* @return void
*/
public function userUploadsFileToWithChecksumUsingTheAPI(
string $user,
string $source,
string $destination,
string $checksum
):void {
$this->featureContext->setResponse($this->uploadFileToWithChecksumUsingTheAPI($user, $source, $destination, $checksum));
}

/**
Expand All @@ -78,39 +95,55 @@ public function userHasUploadedFileToWithChecksumUsingTheAPI(
string $checksum
):void {
$user = $this->featureContext->getActualUsername($user);
$this->userUploadsFileToWithChecksumUsingTheAPI(
$response = $this->uploadFileToWithChecksumUsingTheAPI(
$user,
$source,
$destination,
$checksum
);
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
$this->featureContext->theHTTPStatusCodeShouldBe([201,204], '', $response);
}

/**
* @When user :user uploads file with content :content and checksum :checksum to :destination using the WebDAV API
*
* @param string $user
* @param string $content
* @param string $checksum
* @param string $destination
*
* @return void
* @return ResponseInterface
*/
public function userUploadsFileWithContentAndChecksumToUsingTheAPI(
public function uploadFileWithContentAndChecksumToUsingTheAPI(
string $user,
string $content,
string $checksum,
string $destination
):void {
$response = $this->featureContext->makeDavRequest(
):ResponseInterface {
return $this->featureContext->makeDavRequest(
$user,
'PUT',
$destination,
['OC-Checksum' => $checksum],
$content
);
$this->featureContext->setResponse($response);
}

/**
* @When user :user uploads file with content :content and checksum :checksum to :destination using the WebDAV API
*
* @param string $user
* @param string $content
* @param string $checksum
* @param string $destination
*
* @return void
*/
public function userUploadsFileWithContentAndChecksumToUsingTheAPI(
string $user,
string $content,
string $checksum,
string $destination
):void {
$this->featureContext->setResponse($this->uploadFileWithContentAndChecksumToUsingTheAPI($user, $content, $checksum, $destination));
}

/**
Expand All @@ -130,13 +163,8 @@ public function userHasUploadedFileWithContentAndChecksumToUsingTheAPI(
string $destination
):void {
$user = $this->featureContext->getActualUsername($user);
$this->userUploadsFileWithContentAndChecksumToUsingTheAPI(
$user,
$content,
$checksum,
$destination
);
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
$response = $this->uploadFileWithContentAndChecksumToUsingTheAPI($user, $content, $checksum, $destination);
$this->featureContext->theHTTPStatusCodeShouldBe(201, '', $response);
}

/**
Expand Down Expand Up @@ -375,35 +403,56 @@ public function theOcChecksumHeaderShouldNotBeThere():void {
}

/**
* @When user :user uploads chunk file :num of :total with :data to :destination with checksum :expectedChecksum using the WebDAV API
*
* @param string $user
* @param int $num
* @param int $total
* @param string $data
* @param string $destination
* @param string $expectedChecksum
*
* @return void
* @return ResponseInterface
*/
public function userUploadsChunkFileOfWithToWithChecksum(
public function uploadChunkFileOfWithToWithChecksum(
string $user,
int $num,
int $total,
string $data,
string $destination,
string $expectedChecksum
):void {
):ResponseInterface {
$user = $this->featureContext->getActualUsername($user);
$num -= 1;
$file = "$destination-chunking-42-$total-$num";
$response = $this->featureContext->makeDavRequest(
return $this->featureContext->makeDavRequest(
$user,
'PUT',
$file,
['OC-Checksum' => $expectedChecksum, 'OC-Chunked' => '1'],
$data
);
}

/**
* @When user :user uploads chunk file :num of :total with :data to :destination with checksum :expectedChecksum using the WebDAV API
*
* @param string $user
* @param int $num
* @param int $total
* @param string $data
* @param string $destination
* @param string $expectedChecksum
*
* @return void
*/
public function userUploadsChunkFileOfWithToWithChecksum(
string $user,
int $num,
int $total,
string $data,
string $destination,
string $expectedChecksum
):void {
$response = $this->uploadChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination, $expectedChecksum);
$this->featureContext->setResponse($response);
}

Expand All @@ -427,15 +476,12 @@ public function userHasUploadedChunkFileOfWithToWithChecksum(
string $destination,
string $expectedChecksum
):void {
$this->userUploadsChunkFileOfWithToWithChecksum(
$user,
$num,
$total,
$data,
$destination,
$expectedChecksum
$response = $this->uploadChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination, $expectedChecksum);
$this->featureContext->theHTTPStatusCodeShouldBe(
[201, 206],
'',
$response
);
$this->featureContext->theHTTPStatusCodeShouldBeOr(201, 206);
}

/**
Expand Down
43 changes: 20 additions & 23 deletions tests/acceptance/features/bootstrap/FavoritesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ class FavoritesContext implements Context {
* @param string$user
* @param string $path
*
* @return void
* @return ResponseInterface
*/
public function userFavoritesElement(string $user, string $path):void {
$response = $this->changeFavStateOfAnElement(
public function userFavoritesElement(string $user, string $path):ResponseInterface {
return $this->changeFavStateOfAnElement(
$user,
$path,
1
);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -59,7 +58,7 @@ public function userFavoritesElement(string $user, string $path):void {
* @return void
*/
public function userFavoritesElementUsingWebDavApi(string $user, string $path):void {
$this->userFavoritesElement($user, $path);
$this->featureContext->setResponse($this->userFavoritesElement($user, $path));
}

/**
Expand All @@ -71,8 +70,7 @@ public function userFavoritesElementUsingWebDavApi(string $user, string $path):v
* @return void
*/
public function userHasFavoritedElementUsingWebDavApi(string $user, string $path):void {
$this->userFavoritesElement($user, $path);
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
$this->featureContext->theHTTPStatusCodeShouldBe(207, '', $this->userFavoritesElement($user, $path));
}

/**
Expand All @@ -83,10 +81,11 @@ public function userHasFavoritedElementUsingWebDavApi(string $user, string $path
* @return void
*/
public function theUserFavoritesElement(string $path):void {
$this->userFavoritesElement(
$response = $this->userFavoritesElement(
$this->featureContext->getCurrentUser(),
$path
);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -97,29 +96,29 @@ public function theUserFavoritesElement(string $path):void {
* @return void
*/
public function theUserHasFavoritedElement(string $path):void {
$this->userFavoritesElement(
$response = $this->userFavoritesElement(
$this->featureContext->getCurrentUser(),
$path
);
$this->featureContext->theHTTPStatusCodeShouldBe(
207,
"Expected response status code to be 207 (Multi-status), but not found! "
"Expected response status code to be 207 (Multi-status), but not found! ",
$response
);
}

/**
* @param string $user
* @param string $path
*
* @return void
* @return ResponseInterface
*/
public function userUnfavoritesElement(string $user, string $path):void {
$response = $this->changeFavStateOfAnElement(
public function userUnfavoritesElement(string $user, string $path):ResponseInterface {
return $this->changeFavStateOfAnElement(
$user,
$path,
0
);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -131,7 +130,7 @@ public function userUnfavoritesElement(string $user, string $path):void {
* @return void
*/
public function userUnfavoritesElementUsingWebDavApi(string $user, string $path):void {
$this->userUnfavoritesElement($user, $path);
$this->featureContext->setResponse($this->userUnfavoritesElement($user, $path));
}

/**
Expand All @@ -143,8 +142,7 @@ public function userUnfavoritesElementUsingWebDavApi(string $user, string $path)
* @return void
*/
public function userHasUnfavoritedElementUsingWebDavApi(string $user, string $path):void {
$this->userUnfavoritesElement($user, $path);
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
$this->featureContext->theHTTPStatusCodeShouldBe(207, '', $this->userUnfavoritesElement($user, $path));
}

/**
Expand Down Expand Up @@ -212,10 +210,10 @@ public function userListsFavorites(string $user, ?int $limit = null):void {
/**
* @param string $path
*
* @return void
* @return ResponseInterface
*/
public function theUserUnfavoritesElement(string $path):void {
$this->userUnfavoritesElement(
public function theUserUnfavoritesElement(string $path):ResponseInterface {
return $this->userUnfavoritesElement(
$this->featureContext->getCurrentUser(),
$path
);
Expand All @@ -229,7 +227,7 @@ public function theUserUnfavoritesElement(string $path):void {
* @return void
*/
public function theUserUnfavoritesElementUsingWebDavApi(string $path):void {
$this->theUserUnfavoritesElement($path);
$this->featureContext->setResponse($this->theUserUnfavoritesElement($path));
}

/**
Expand All @@ -240,8 +238,7 @@ public function theUserUnfavoritesElementUsingWebDavApi(string $path):void {
* @return void
*/
public function theUserHasUnfavoritedElementUsingWebDavApi(string $path):void {
$this->theUserUnfavoritesElement($path);
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
$this->featureContext->theHTTPStatusCodeShouldBe(207, '', $this->theUserUnfavoritesElement($path));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3038,7 +3038,7 @@ public function asUserFileOrFolderInsideSpaceShouldOrNotBeFavorited(string $user
*/
public function userFavoritesElementInSpaceUsingTheWebdavApi(string $user, string $path, string $spaceName): void {
$this->setSpaceIDByName($user, $spaceName);
$this->favoritesContext->userFavoritesElement($user, $path);
$this->featureContext->setResponse($this->favoritesContext->userFavoritesElement($user, $path));
}

/**
Expand Down