From 72fd765b93dc9abe65e4143e6293a2dfd58bb889 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Wed, 5 Feb 2025 19:43:12 +0100 Subject: [PATCH] delete unnecessary steps from context files --- .../acceptance/bootstrap/ArchiverContext.php | 1 - tests/acceptance/bootstrap/FeatureContext.php | 35 - .../bootstrap/FilesVersionsContext.php | 32 - .../bootstrap/NotificationContext.php | 2 - tests/acceptance/bootstrap/OCSContext.php | 578 ++++----- .../bootstrap/PublicWebDavContext.php | 74 +- .../acceptance/bootstrap/SettingsContext.php | 1 - tests/acceptance/bootstrap/ShareesContext.php | 15 - tests/acceptance/bootstrap/Sharing.php | 1073 ----------------- .../acceptance/bootstrap/SharingNgContext.php | 1 - tests/acceptance/bootstrap/SpacesContext.php | 1 - .../acceptance/bootstrap/SpacesTUSContext.php | 2 - .../acceptance/bootstrap/TrashbinContext.php | 65 - tests/acceptance/bootstrap/WebDav.php | 1 - 14 files changed, 295 insertions(+), 1586 deletions(-) diff --git a/tests/acceptance/bootstrap/ArchiverContext.php b/tests/acceptance/bootstrap/ArchiverContext.php index aedd32afa..17fbb31b4 100644 --- a/tests/acceptance/bootstrap/ArchiverContext.php +++ b/tests/acceptance/bootstrap/ArchiverContext.php @@ -23,7 +23,6 @@ use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Gherkin\Node\TableNode; use GuzzleHttp\Exception\GuzzleException; use TestHelpers\HttpRequestHelper; -use TestHelpers\SetupHelper; use TestHelpers\BehatHelper; use PHPUnit\Framework\Assert; use Psr\Http\Message\ResponseInterface; diff --git a/tests/acceptance/bootstrap/FeatureContext.php b/tests/acceptance/bootstrap/FeatureContext.php index 766611da0..5f6d51180 100644 --- a/tests/acceptance/bootstrap/FeatureContext.php +++ b/tests/acceptance/bootstrap/FeatureContext.php @@ -932,26 +932,6 @@ class FeatureContext extends BehatVariablesContext { $this->ocsApiVersion = (int)$version; } - /** - * @Given /^as user "([^"]*)"$/ - * - * @param string $user - * - * @return void - */ - public function asUser(string $user): void { - $this->currentUser = $this->getActualUsername($user); - } - - /** - * @Given as the administrator - * - * @return void - */ - public function asTheAdministrator(): void { - $this->currentUser = $this->getAdminUsername(); - } - /** * @return string */ @@ -1690,21 +1670,6 @@ class FeatureContext extends BehatVariablesContext { ); } - /** - * @Then the HTTP status code should be failure - * - * @return void - */ - public function theHTTPStatusCodeShouldBeFailure(): void { - $statusCode = $this->response->getStatusCode(); - $message = "The HTTP status code $statusCode is not greater than or equals to 400"; - Assert::assertGreaterThanOrEqual( - 400, - $statusCode, - $message - ); - } - /** * @param string $path * @param string $filename diff --git a/tests/acceptance/bootstrap/FilesVersionsContext.php b/tests/acceptance/bootstrap/FilesVersionsContext.php index 9c5915f3a..8f7ad0c82 100644 --- a/tests/acceptance/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/bootstrap/FilesVersionsContext.php @@ -170,20 +170,6 @@ class FilesVersionsContext implements Context { ); } - /** - * @When user :user gets the version metadata of file :file - * - * @param string $user - * @param string $file - * - * @return void - * @throws Exception - */ - public function userGetsVersionMetadataOfFile(string $user, string $file): void { - $response = $this->getFileVersionMetadata($user, $file); - $this->featureContext->setResponse($response, $user); - } - /** * @param string $user * @param string $file @@ -335,24 +321,6 @@ class FilesVersionsContext implements Context { $this->assertFileVersionsCount($user, $fileId, $count); } - /** - * @Then the version folder of fileId :fileId for user :user should contain :count element(s) - * - * @param string $fileId - * @param string $user - * @param int $count - * - * @return void - * @throws Exception - */ - public function theVersionFolderOfFileIdShouldContainElements( - string $fileId, - string $user, - int $count - ): void { - $this->assertFileVersionsCount($user, $fileId, $count); - } - /** * @Then the content length of file :path with version index :index for user :user in versions folder should be :length * diff --git a/tests/acceptance/bootstrap/NotificationContext.php b/tests/acceptance/bootstrap/NotificationContext.php index 25c1a1afb..6caf1e87b 100644 --- a/tests/acceptance/bootstrap/NotificationContext.php +++ b/tests/acceptance/bootstrap/NotificationContext.php @@ -25,7 +25,6 @@ require_once 'bootstrap.php'; class NotificationContext implements Context { private FeatureContext $featureContext; private SpacesContext $spacesContext; - private SettingsContext $settingsContext; private string $notificationEndpointPath = '/apps/notifications/api/v1/notifications?format=json'; private string $globalNotificationEndpointPath = '/apps/notifications/api/v1/notifications/global'; @@ -99,7 +98,6 @@ class NotificationContext implements Context { // Get all the contexts you need in this context $this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext'); $this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext'); - $this->settingsContext = BehatHelper::getContext($scope, $environment, 'SettingsContext'); } /** diff --git a/tests/acceptance/bootstrap/OCSContext.php b/tests/acceptance/bootstrap/OCSContext.php index 641fe9d9d..8a4f3f166 100644 --- a/tests/acceptance/bootstrap/OCSContext.php +++ b/tests/acceptance/bootstrap/OCSContext.php @@ -37,40 +37,40 @@ require_once 'bootstrap.php'; class OCSContext implements Context { private FeatureContext $featureContext; - /** - * @When /^the user sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)"$/ - * - * @param string $verb - * @param string $url - * - * @return void - */ - public function theUserSendsToOcsApiEndpoint(string $verb, string $url): void { - $response = $this->theUserSendsToOcsApiEndpointWithBody($verb, $url); - $this->featureContext->setResponse($response); - } + // /** + // * @When /^the user sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)"$/ + // * + // * @param string $verb + // * @param string $url + // * + // * @return void + // */ + // public function theUserSendsToOcsApiEndpoint(string $verb, string $url): void { + // $response = $this->theUserSendsToOcsApiEndpointWithBody($verb, $url); + // $this->featureContext->setResponse($response); + // } - /** - * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)"$/ - * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" using password "([^"]*)"$/ - * - * @param string $user - * @param string $verb - * @param string $url - * @param string|null $password - * - * @return void - */ - public function userSendsToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null): void { - $response = $this->sendRequestToOcsEndpoint( - $user, - $verb, - $url, - null, - $password - ); - $this->featureContext->setResponse($response); - } + // /** + // * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)"$/ + // * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" using password "([^"]*)"$/ + // * + // * @param string $user + // * @param string $verb + // * @param string $url + // * @param string|null $password + // * + // * @return void + // */ + // public function userSendsToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null): void { + // $response = $this->sendRequestToOcsEndpoint( + // $user, + // $verb, + // $url, + // null, + // $password + // ); + // $this->featureContext->setResponse($response); + // } /** * @param string $user @@ -162,59 +162,59 @@ class OCSContext implements Context { ); } - /** - * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body$/ - * - * @param string $user - * @param string $verb - * @param string $url - * @param TableNode|null $body - * @param string|null $password - * - * @return void - */ - public function userSendHTTPMethodToOcsApiEndpointWithBody( - string $user, - string $verb, - string $url, - ?TableNode $body = null, - ?string $password = null - ): void { - $response = $this->sendRequestToOcsEndpoint( - $user, - $verb, - $url, - $body, - $password - ); - $this->featureContext->setResponse($response); - } + // /** + // * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body$/ + // * + // * @param string $user + // * @param string $verb + // * @param string $url + // * @param TableNode|null $body + // * @param string|null $password + // * + // * @return void + // */ + // public function userSendHTTPMethodToOcsApiEndpointWithBody( + // string $user, + // string $verb, + // string $url, + // ?TableNode $body = null, + // ?string $password = null + // ): void { + // $response = $this->sendRequestToOcsEndpoint( + // $user, + // $verb, + // $url, + // $body, + // $password + // ); + // $this->featureContext->setResponse($response); + // } - /** - * @When the administrator sends HTTP method :verb to OCS API endpoint :url - * @When the administrator sends HTTP method :verb to OCS API endpoint :url using password :password - * - * @param string $verb - * @param string $url - * @param string|null $password - * - * @return void - */ - public function theAdministratorSendsHttpMethodToOcsApiEndpoint( - string $verb, - string $url, - ?string $password = null - ): void { - $this->featureContext->setResponse( - $this->sendRequestToOcsEndpoint( - $this->featureContext->getAdminUsername(), - $verb, - $url, - null, - $password - ) - ); - } + // /** + // * @When the administrator sends HTTP method :verb to OCS API endpoint :url + // * @When the administrator sends HTTP method :verb to OCS API endpoint :url using password :password + // * + // * @param string $verb + // * @param string $url + // * @param string|null $password + // * + // * @return void + // */ + // public function theAdministratorSendsHttpMethodToOcsApiEndpoint( + // string $verb, + // string $url, + // ?string $password = null + // ): void { + // $this->featureContext->setResponse( + // $this->sendRequestToOcsEndpoint( + // $this->featureContext->getAdminUsername(), + // $verb, + // $url, + // null, + // $password + // ) + // ); + // } /** * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers$/ @@ -247,158 +247,158 @@ class OCSContext implements Context { ); } - /** - * @When /^the administrator sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers$/ - * - * @param string $verb - * @param string $url - * @param TableNode $headersTable - * - * @return void - * @throws Exception - */ - public function administratorSendsToOcsApiEndpointWithHeaders( - string $verb, - string $url, - TableNode $headersTable - ): void { - $user = $this->featureContext->getAdminUsername(); - $password = $this->featureContext->getPasswordForUser($user); - $this->featureContext->setResponse( - $this->sendRequestToOcsEndpoint( - $user, - $verb, - $url, - null, - $password, - $headersTable->getRowsHash() - ) - ); - } + // /** + // * @When /^the administrator sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers$/ + // * + // * @param string $verb + // * @param string $url + // * @param TableNode $headersTable + // * + // * @return void + // * @throws Exception + // */ + // public function administratorSendsToOcsApiEndpointWithHeaders( + // string $verb, + // string $url, + // TableNode $headersTable + // ): void { + // $user = $this->featureContext->getAdminUsername(); + // $password = $this->featureContext->getPasswordForUser($user); + // $this->featureContext->setResponse( + // $this->sendRequestToOcsEndpoint( + // $user, + // $verb, + // $url, + // null, + // $password, + // $headersTable->getRowsHash() + // ) + // ); + // } - /** - * @When /^the administrator sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers using password "([^"]*)"$/ - * - * @param string $verb - * @param string $url - * @param string $password - * @param TableNode $headersTable - * - * @return void - * @throws Exception - */ - public function administratorSendsToOcsApiEndpointWithHeadersAndPassword( - string $verb, - string $url, - string $password, - TableNode $headersTable - ): void { - $this->featureContext->setResponse( - $this->sendRequestToOcsEndpoint( - $this->featureContext->getAdminUsername(), - $verb, - $url, - null, - $password, - $headersTable->getRowsHash() - ) - ); - } + // /** + // * @When /^the administrator sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers using password "([^"]*)"$/ + // * + // * @param string $verb + // * @param string $url + // * @param string $password + // * @param TableNode $headersTable + // * + // * @return void + // * @throws Exception + // */ + // public function administratorSendsToOcsApiEndpointWithHeadersAndPassword( + // string $verb, + // string $url, + // string $password, + // TableNode $headersTable + // ): void { + // $this->featureContext->setResponse( + // $this->sendRequestToOcsEndpoint( + // $this->featureContext->getAdminUsername(), + // $verb, + // $url, + // null, + // $password, + // $headersTable->getRowsHash() + // ) + // ); + // } - /** - * @When the administrator sends HTTP method :verb to OCS API endpoint :url with body - * - * @param string $verb - * @param string $url - * @param TableNode|null $body - * - * @return void - */ - public function theAdministratorSendsHttpMethodToOcsApiEndpointWithBody( - string $verb, - string $url, - ?TableNode $body - ): void { - $response = $this->adminSendsHttpMethodToOcsApiEndpointWithBody( - $verb, - $url, - $body - ); - $this->featureContext->setResponse($response); - } + // /** + // * @When the administrator sends HTTP method :verb to OCS API endpoint :url with body + // * + // * @param string $verb + // * @param string $url + // * @param TableNode|null $body + // * + // * @return void + // */ + // public function theAdministratorSendsHttpMethodToOcsApiEndpointWithBody( + // string $verb, + // string $url, + // ?TableNode $body + // ): void { + // $response = $this->adminSendsHttpMethodToOcsApiEndpointWithBody( + // $verb, + // $url, + // $body + // ); + // $this->featureContext->setResponse($response); + // } - /** - * @When /^the user sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body$/ - * - * @param string $verb - * @param string $url - * @param TableNode $body - * - * @return void - */ - public function theUserSendsHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body): void { - $response = $this->theUserSendsToOcsApiEndpointWithBody( - $verb, - $url, - $body - ); - $this->featureContext->setResponse($response); - } + // /** + // * @When /^the user sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body$/ + // * + // * @param string $verb + // * @param string $url + // * @param TableNode $body + // * + // * @return void + // */ + // public function theUserSendsHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body): void { + // $response = $this->theUserSendsToOcsApiEndpointWithBody( + // $verb, + // $url, + // $body + // ); + // $this->featureContext->setResponse($response); + // } - /** - * @When the administrator sends HTTP method :verb to OCS API endpoint :url with body using password :password - * - * @param string $verb - * @param string $url - * @param string $password - * @param TableNode $body - * - * @return void - */ - public function theAdministratorSendsHttpMethodToOcsApiWithBodyAndPassword( - string $verb, - string $url, - string $password, - TableNode $body - ): void { - $admin = $this->featureContext->getAdminUsername(); - $response = $this->sendRequestToOcsEndpoint( - $admin, - $verb, - $url, - $body, - $password - ); - $this->featureContext->setResponse($response); - } + // /** + // * @When the administrator sends HTTP method :verb to OCS API endpoint :url with body using password :password + // * + // * @param string $verb + // * @param string $url + // * @param string $password + // * @param TableNode $body + // * + // * @return void + // */ + // public function theAdministratorSendsHttpMethodToOcsApiWithBodyAndPassword( + // string $verb, + // string $url, + // string $password, + // TableNode $body + // ): void { + // $admin = $this->featureContext->getAdminUsername(); + // $response = $this->sendRequestToOcsEndpoint( + // $admin, + // $verb, + // $url, + // $body, + // $password + // ); + // $this->featureContext->setResponse($response); + // } - /** - * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body using password "([^"]*)"$/ - * - * @param string $user - * @param string $verb - * @param string $url - * @param string $password - * @param TableNode $body - * - * @return void - */ - public function userSendsHTTPMethodToOcsApiEndpointWithBodyAndPassword( - string $user, - string $verb, - string $url, - string $password, - TableNode $body - ): void { - $response = $this->sendRequestToOcsEndpoint( - $user, - $verb, - $url, - $body, - $password - ); - $this->featureContext->setResponse($response); - } + // /** + // * @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body using password "([^"]*)"$/ + // * + // * @param string $user + // * @param string $verb + // * @param string $url + // * @param string $password + // * @param TableNode $body + // * + // * @return void + // */ + // public function userSendsHTTPMethodToOcsApiEndpointWithBodyAndPassword( + // string $user, + // string $verb, + // string $url, + // string $password, + // TableNode $body + // ): void { + // $response = $this->sendRequestToOcsEndpoint( + // $user, + // $verb, + // $url, + // $body, + // $password + // ); + // $this->featureContext->setResponse($response); + // } /** * @Then /^the OCS status code should be "([^"]*)"$/ @@ -494,64 +494,64 @@ class OCSContext implements Context { ); } - /** - * Check the text in an OCS status message - * - * @Then /^the OCS status message about user "([^"]*)" should be "([^"]*)"$/ - * - * @param string $user - * @param string $statusMessage - * - * @return void - */ - public function theOCSStatusMessageAboutUserShouldBe(string $user, string $statusMessage): void { - $user = \strtolower($this->featureContext->getActualUsername($user)); - $statusMessage = $this->featureContext->substituteInLineCodes( - $statusMessage, - $user - ); - Assert::assertEquals( - $statusMessage, - $this->getOCSResponseStatusMessage( - $this->featureContext->getResponse() - ), - 'Unexpected OCS status message :"' . $this->getOCSResponseStatusMessage( - $this->featureContext->getResponse() - ) . '" in response' - ); - } + // /** + // * Check the text in an OCS status message + // * + // * @Then /^the OCS status message about user "([^"]*)" should be "([^"]*)"$/ + // * + // * @param string $user + // * @param string $statusMessage + // * + // * @return void + // */ + // public function theOCSStatusMessageAboutUserShouldBe(string $user, string $statusMessage): void { + // $user = \strtolower($this->featureContext->getActualUsername($user)); + // $statusMessage = $this->featureContext->substituteInLineCodes( + // $statusMessage, + // $user + // ); + // Assert::assertEquals( + // $statusMessage, + // $this->getOCSResponseStatusMessage( + // $this->featureContext->getResponse() + // ), + // 'Unexpected OCS status message :"' . $this->getOCSResponseStatusMessage( + // $this->featureContext->getResponse() + // ) . '" in response' + // ); + // } - /** - * Check the text in an OCS status message. - * Use this step form if the expected text contains double quotes, - * single quotes and other content that theOCSStatusMessageShouldBe() - * cannot handle. - * - * After the step, write the expected text in PyString form like: - * - * """ - * File "abc.txt" can't be shared due to reason "xyz" - * """ - * - * @Then /^the OCS status message should be:$/ - * - * @param PyStringNode $statusMessage - * - * @return void - */ - public function theOCSStatusMessageShouldBePyString( - PyStringNode $statusMessage - ): void { - Assert::assertEquals( - $statusMessage->getRaw(), - $this->getOCSResponseStatusMessage( - $this->featureContext->getResponse() - ), - 'Unexpected OCS status message: "' . $this->getOCSResponseStatusMessage( - $this->featureContext->getResponse() - ) . '" in response' - ); - } + // /** + // * Check the text in an OCS status message. + // * Use this step form if the expected text contains double quotes, + // * single quotes and other content that theOCSStatusMessageShouldBe() + // * cannot handle. + // * + // * After the step, write the expected text in PyString form like: + // * + // * """ + // * File "abc.txt" can't be shared due to reason "xyz" + // * """ + // * + // * @Then /^the OCS status message should be:$/ + // * + // * @param PyStringNode $statusMessage + // * + // * @return void + // */ + // public function theOCSStatusMessageShouldBePyString( + // PyStringNode $statusMessage + // ): void { + // Assert::assertEquals( + // $statusMessage->getRaw(), + // $this->getOCSResponseStatusMessage( + // $this->featureContext->getResponse() + // ), + // 'Unexpected OCS status message: "' . $this->getOCSResponseStatusMessage( + // $this->featureContext->getResponse() + // ) . '" in response' + // ); + // } /** * Parses the xml answer to get ocs response which doesn't match with diff --git a/tests/acceptance/bootstrap/PublicWebDavContext.php b/tests/acceptance/bootstrap/PublicWebDavContext.php index 4ea3e29df..b6fc3583c 100644 --- a/tests/acceptance/bootstrap/PublicWebDavContext.php +++ b/tests/acceptance/bootstrap/PublicWebDavContext.php @@ -132,10 +132,7 @@ class PublicWebDavContext implements Context { ); $password = $this->featureContext->getActualPassword($password); $fullUrl = $this->featureContext->getBaseUrl() . "/$davPath/$fileName"; - $userName = $this->getUsernameForPublicWebdavApi( - $token, - $password - ); + $userName = $this->getUsernameForPublicWebdavApi($password); $headers = [ 'X-Requested-With' => 'XMLHttpRequest' ]; @@ -205,10 +202,7 @@ class PublicWebDavContext implements Context { $fullUrl = $this->featureContext->getBaseUrl() . "/$davPath/$fileName"; $password = $this->featureContext->getActualPassword($password); $destination = $this->featureContext->getBaseUrl() . "/$davPath/$toFileName"; - $userName = $this->getUsernameForPublicWebdavApi( - $token, - $password - ); + $userName = $this->getUsernameForPublicWebdavApi($password); $headers = [ 'X-Requested-With' => 'XMLHttpRequest', 'Destination' => $destination @@ -321,10 +315,7 @@ class PublicWebDavContext implements Context { "public-files" ); $fullUrl = $this->featureContext->getBaseUrl() . "/$davPath/$path"; - $userName = $this->getUsernameForPublicWebdavApi( - $token, - $password - ); + $userName = $this->getUsernameForPublicWebdavApi($password); $headers = [ 'X-Requested-With' => 'XMLHttpRequest' @@ -410,48 +401,6 @@ class PublicWebDavContext implements Context { $this->featureContext->setResponse($response); } - /** - * This only works with the old API, auto-rename is not supported in the new API - * auto renaming is handled on files drop folders implicitly - * - * @param string $filename target file name - * @param string $body content to upload - * - * @return ResponseInterface - */ - public function publiclyUploadingContentAutoRename(string $filename, string $body = 'test'): ResponseInterface { - return $this->publicUploadContent($filename, '', $body, true); - } - - /** - * @When the public uploads file :filename with content :body with auto-rename mode using the old public WebDAV API - * - * @param string $filename target file name - * @param string $body content to upload - * - * @return void - */ - public function thePublicUploadsFileWithContentWithAutoRenameMode(string $filename, string $body = 'test'): void { - $response = $this->publiclyUploadingContentAutoRename($filename, $body); - $this->featureContext->setResponse($response); - } - - /** - * @Given the public has uploaded file :filename with content :body with auto-rename mode - * - * @param string $filename target file name - * @param string $body content to upload - * - * @return void - */ - public function thePublicHasUploadedFileWithContentWithAutoRenameMode( - string $filename, - string $body = 'test' - ): void { - $response = $this->publiclyUploadingContentAutoRename($filename, $body); - $this->featureContext->theHTTPStatusCodeShouldBe([201, 204], "", $response); - } - /** * @param string $filename target file name * @param string $password @@ -997,10 +946,7 @@ class PublicWebDavContext implements Context { ); $url = $this->featureContext->getBaseUrl() . "/$davPath/"; $password = $this->featureContext->getActualPassword($password); - $userName = $this->getUsernameForPublicWebdavApi( - $token, - $password - ); + $userName = $this->getUsernameForPublicWebdavApi($password); $foldername = \implode( '/', \array_map('rawurlencode', \explode('/', $destination)) @@ -1152,10 +1098,7 @@ class PublicWebDavContext implements Context { $token, "public-files" ); - $userName = $this->getUsernameForPublicWebdavApi( - $token, - $password - ); + $userName = $this->getUsernameForPublicWebdavApi($password); $filename = \implode( '/', @@ -1184,13 +1127,11 @@ class PublicWebDavContext implements Context { } /** - * @param string $token * @param string $password * * @return string|null */ private function getUsernameForPublicWebdavApi( - string $token, string $password ): ?string { if ($password !== '') { @@ -1249,10 +1190,7 @@ class PublicWebDavContext implements Context { "public-files" ); $password = $this->featureContext->getActualPassword($password); - $username = $this->getUsernameForPublicWebdavApi( - $token, - $password - ); + $username = $this->getUsernameForPublicWebdavApi($password); $fullUrl = $this->featureContext->getBaseUrl() . "/$davPath"; $response = HttpRequestHelper::sendRequest( $fullUrl, diff --git a/tests/acceptance/bootstrap/SettingsContext.php b/tests/acceptance/bootstrap/SettingsContext.php index cbeed86f0..1ddaccb86 100644 --- a/tests/acceptance/bootstrap/SettingsContext.php +++ b/tests/acceptance/bootstrap/SettingsContext.php @@ -24,7 +24,6 @@ require_once 'bootstrap.php'; */ class SettingsContext implements Context { private FeatureContext $featureContext; - private string $settingsUrl = '/api/v0/settings/'; /** * This will run before EVERY scenario. diff --git a/tests/acceptance/bootstrap/ShareesContext.php b/tests/acceptance/bootstrap/ShareesContext.php index 4e05825ca..c8ba94025 100644 --- a/tests/acceptance/bootstrap/ShareesContext.php +++ b/tests/acceptance/bootstrap/ShareesContext.php @@ -37,21 +37,6 @@ class ShareesContext implements Context { private FeatureContext $featureContext; private OCSContext $ocsContext; - /** - * @When /^the user gets the sharees using the sharing API with parameters$/ - * - * @param TableNode $body - * - * @return void - */ - public function theUserGetsTheShareesWithParameters(TableNode $body): void { - $this->featureContext->setResponse( - $this->getShareesWithParameters( - $this->featureContext->getCurrentUser(), - $body - ) - ); - } /** * @When /^user "([^"]*)" gets the sharees using the sharing API with parameters$/ diff --git a/tests/acceptance/bootstrap/Sharing.php b/tests/acceptance/bootstrap/Sharing.php index 037adeef1..a7868ad90 100755 --- a/tests/acceptance/bootstrap/Sharing.php +++ b/tests/acceptance/bootstrap/Sharing.php @@ -20,7 +20,6 @@ * */ -use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; use Psr\Http\Message\ResponseInterface; use PHPUnit\Framework\Assert; @@ -408,24 +407,6 @@ trait Sharing { $this->pushToLastStatusCodesArrays(); } - /** - * @Given /^user "([^"]*)" has created a share with settings$/ - * - * @param string $user - * @param TableNode|null $body {@link createShareWithSettings} - * - * @return void - * @throws Exception - */ - public function userHasCreatedAShareWithSettings(string $user, ?TableNode $body) { - $response = $this->createShareWithSettings( - $user, - $body - ); - $this->theHTTPStatusCodeShouldBe(200, "", $response); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - } - /** * @param string $user * @param TableNode $body @@ -454,49 +435,6 @@ trait Sharing { $this->pushToLastStatusCodesArrays(); } - /** - * @Given /^user "([^"]*)" has created a public link share with settings$/ - * - * @param string $user - * @param TableNode $body - * - * @return void - * @throws Exception - */ - public function userHasCreatedAPublicLinkShareWithSettings(string $user, TableNode $body): void { - $response = $this->createPublicLinkShare($user, $body); - $this->theHTTPStatusCodeShouldBe(200, "", $response); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - $this->clearStatusCodeArrays(); - } - - /** - * @When /^the user creates a public link share using the sharing API with settings$/ - * - * @param TableNode $body - * - * @return void - * @throws Exception - */ - public function theUserCreatesAPublicLinkShareWithSettings(TableNode $body): void { - $this->setResponse($this->createPublicLinkShare($this->currentUser, $body)); - $this->pushToLastStatusCodesArrays(); - } - - /** - * @Given /^the user has created a public link share with settings$/ - * - * @param TableNode $body - * - * @return void - * @throws Exception - */ - public function theUserHasCreatedAPublicLinkShareWithSettings(TableNode $body): void { - $response = $this->createPublicLinkShare($this->currentUser, $body); - $this->theHTTPStatusCodeShouldBe(200, "", $response); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - } - /** * @param string $user * @param string $path @@ -530,70 +468,6 @@ trait Sharing { ); } - /** - * @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API$/ - * - * @param string $user - * @param string $path - * - * @return void - */ - public function userCreatesAPublicLinkShareOf(string $user, string $path): void { - $response = $this->createAPublicShare($user, $path); - $this->setResponse($response); - } - - /** - * @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)"$/ - * - * @param string $user - * @param string $path - * - * @return void - */ - public function userHasCreatedAPublicLinkShareOf(string $user, string $path): void { - $response = $this->createAPublicShare($user, $path); - $this->theHTTPStatusCodeShouldBe(200, "", $response); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - } - - /** - * @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API with (read|update|create|delete|change|uploadwriteonly|share|all) permission(?:s|)$/ - * - * @param string $user - * @param string $path - * @param string|int|string[]|int[]|null $permissions - * - * @return void - */ - public function userCreatesAPublicLinkShareOfWithPermission( - string $user, - string $path, - $permissions - ): void { - $response = $this->createAPublicShare($user, $path, true, null, $permissions); - $this->setResponse($response); - } - - /** - * @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)" with (read|update|create|delete|change|uploadwriteonly|share|all) permission(?:s|)$/ - * - * @param string $user - * @param string $path - * @param string|int|string[]|int[]|null $permissions - * - * @return void - */ - public function userHasCreatedAPublicLinkShareOfWithPermission( - string $user, - string $path, - $permissions - ): void { - $response = $this->createAPublicShare($user, $path, true, null, $permissions); - $this->theHTTPStatusCodeShouldBe(200, "", $response); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - } - /** * @param string $user * @param string $path @@ -617,105 +491,6 @@ trait Sharing { ); } - /** - * @When /^user "([^"]*)" creates a public link share of (?:file|folder) "([^"]*)" using the sharing API with expiry "([^"]*)"$/ - * - * @param string $user - * @param string $path - * @param string $expiryDate in a valid date format, e.g. "+30 days" - * - * @return void - */ - public function userCreatesAPublicLinkShareOfWithExpiry( - string $user, - string $path, - string $expiryDate - ): void { - $this->createPublicLinkShareOfResourceWithExpiry( - $user, - $path, - $expiryDate - ); - } - - /** - * @Given /^user "([^"]*)" has created a public link share of (?:file|folder) "([^"]*)" with expiry "([^"]*)"$/ - * - * @param string $user - * @param string $path - * @param string $expiryDate in a valid date format, e.g. "+30 days" - * - * @return void - */ - public function userHasCreatedAPublicLinkShareOfWithExpiry( - string $user, - string $path, - string $expiryDate - ): void { - $this->createPublicLinkShareOfResourceWithExpiry( - $user, - $path, - $expiryDate - ); - $this->theHTTPStatusCodeShouldBeSuccess(); - } - - /** - * @Then /^user "([^"]*)" should not be able to create a public link share of (?:file|folder) "([^"]*)" using the sharing API$/ - * - * @param string $sharer - * @param string $filepath - * - * @return void - * @throws Exception - */ - public function shouldNotBeAbleToCreatePublicLinkShare(string $sharer, string $filepath): void { - $this->createAPublicShare($sharer, $filepath); - Assert::assertEquals( - 404, - $this->ocsContext->getOCSResponseStatusCode($this->response), - __METHOD__ - . " Expected response status code is '404' but got '" - . $this->ocsContext->getOCSResponseStatusCode($this->response) - . "'" - ); - } - - /** - * @param TableNode|null $body - * - * @return ResponseInterface - * @throws Exception - */ - public function updateLastShareByCurrentUser(?TableNode $body): ResponseInterface { - return $this->updateLastShareWithSettings($this->currentUser, $body); - } - - /** - * @When /^the user updates the last share using the sharing API with$/ - * - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function theUserUpdatesTheLastShareWith(?TableNode $body): void { - $this->setResponse($this->updateLastShareByCurrentUser($body)); - } - - /** - * @Given /^the user has updated the last share with$/ - * - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function theUserHasUpdatedTheLastShareWith(?TableNode $body): void { - $response = $this->updateLastShareByCurrentUser($body); - $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); - } - /** * Gets the last user share id using the sharer's name * @@ -838,42 +613,6 @@ trait Sharing { $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } - /** - * @Given /^user "([^"]*)" has updated the last public link share with$/ - * - * @param string $user - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function userHasUpdatedTheLastPublicLinkShareWith(string $user, ?TableNode $body): void { - $response = $this->updateLastShareWithSettings($user, $body, null, true); - $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); - } - - /** - * @Given /^user "([^"]*)" has updated the last share of "([^"]*)" with$/ - * - * @param string $user - * @param string $shareOwner - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function userHasUpdatedTheLastShareOfWith(string $user, string $shareOwner, ?TableNode $body): void { - $response = $this->updateLastShareWithSettings($user, $body, $shareOwner); - $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); - if ($this->ocsApiVersion == 1) { - $this->ocsContext->theOCSStatusCodeShouldBe("100", "", $response); - } elseif ($this->ocsApiVersion === 2) { - $this->ocsContext->theOCSStatusCodeShouldBe("200", "", $response); - } else { - throw new Exception('Invalid ocs api version used'); - } - } - /** * @param string $user * @param string|null $path @@ -1352,82 +1091,6 @@ trait Sharing { $this->pushToLastStatusCodesArrays(); } - /** - * @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)"(?: with permissions (\d+))?$/ - * @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with user "([^"]*)" with permissions "([^"]*)"$/ - * - * @param string $filepath - * @param string $user2 - * @param string|int|string[]|int[] $permissions - * - * @return void - */ - public function theUserHasSharedFileWithUserUsingTheSharingApi( - string $filepath, - string $user2, - $permissions = null - ): void { - $user2 = $this->getActualUsername($user2); - $response = $this->createAUserShare( - $this->getCurrentUser(), - $filepath, - $this->getActualUsername($user2), - $permissions - ); - $this->theHTTPStatusCodeShouldBe(200, "", $response); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - } - - /** - * @When /^the user shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))? using the sharing API$/ - * @When /^the user shares (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)" using the sharing API$/ - * - * @param string $filepath - * @param string $group - * @param string|int|string[]|int[] $permissions - * - * @return void - */ - public function theUserSharesFileWithGroupUsingTheSharingApi( - string $filepath, - string $group, - $permissions = null - ): void { - $response = $this->createAGroupShare( - $this->currentUser, - $filepath, - $group, - $permissions - ); - $this->setResponse($response); - $this->pushToLastStatusCodesArrays(); - } - - /** - * @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)"(?: with permissions (\d+))?$/ - * @Given /^the user has shared (?:file|folder|entry) "([^"]*)" with group "([^"]*)" with permissions "([^"]*)"$/ - * - * @param string $filepath - * @param string $group - * @param string|int|string[]|int[] $permissions - * - * @return void - */ - public function theUserHasSharedFileWithGroupUsingTheSharingApi( - string $filepath, - string $group, - $permissions = null - ): void { - $response = $this->createAGroupShare( - $this->currentUser, - $filepath, - $group, - $permissions - ); - $this->theHTTPStatusCodeShouldBe(200, "", $response); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - } - /** * * @param string $user @@ -1541,35 +1204,6 @@ trait Sharing { $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); } - /** - * @When /^user "([^"]*)" tries to update the last share using the sharing API with$/ - * - * @param string $user - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function userTriesToUpdateTheLastShareUsingTheSharingApiWith(string $user, ?TableNode $body): void { - $this->response = $this->updateLastShareWithSettings($user, $body); - } - - /** - * @When /^user "([^"]*)" tries to update the last public link share using the sharing API with$/ - * - * @param string $user - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function userTriesToUpdateTheLastPublicLinkShareUsingTheSharingApiWith( - string $user, - ?TableNode $body - ): void { - $this->response = $this->updateLastShareWithSettings($user, $body, null, true); - } - /** * @Then /^user "([^"]*)" should not be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)"(?: with permissions (\d+))? using the sharing API$/ * @Then /^user "([^"]*)" should not be able to share (?:file|folder|entry) "([^"]*)" with (user|group) "([^"]*)" with permissions "([^"]*)" using the sharing API$/ @@ -1645,25 +1279,6 @@ trait Sharing { ); } - /** - * @When /^the user deletes the last share using the sharing API$/ - * - * @return void - */ - public function theUserDeletesLastShareUsingTheSharingAPI(): void { - $this->setResponse($this->deleteLastShareUsingSharingApiByCurrentUser()); - } - - /** - * @Given /^the user has deleted the last share$/ - * - * @return void - */ - public function theUserHasDeletedLastShareUsingTheSharingAPI(): void { - $response = $this->deleteLastShareUsingSharingApiByCurrentUser(); - $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); - } - /** * @param string $user the user who will do the delete request * @param string|null $sharer the specific user whose share will be deleted (if specified) @@ -1705,7 +1320,6 @@ trait Sharing { /** * @When /^user "([^"]*)" deletes the last share using the sharing API$/ - * @When /^user "([^"]*)" tries to delete the last share using the sharing API$/ * * @param string $user * @@ -1716,19 +1330,6 @@ trait Sharing { $this->pushToLastStatusCodesArrays(); } - /** - * @When /^user "([^"]*)" deletes the last public link share using the sharing API$/ - * @When /^user "([^"]*)" tries to delete the last public link share using the sharing API$/ - * - * @param string $user - * - * @return void - */ - public function userDeletesLastPublicLinkShareUsingTheSharingApi(string $user): void { - $this->setResponse($this->deleteLastShareUsingSharingApi($user, null, true)); - $this->pushToLastStatusCodesArrays(); - } - /** * @When /^user "([^"]*)" deletes the last share of user "([^"]*)" using the sharing API$/ * @When /^user "([^"]*)" tries to delete the last share of user "([^"]*)" using the sharing API$/ @@ -1780,7 +1381,6 @@ trait Sharing { } /** - * @When /^user "([^"]*)" gets the info of the last share in language "([^"]*)" using the sharing API$/ * @When /^user "([^"]*)" gets the info of the last share using the sharing API$/ * * @param string $user username that requests the information (might not be the user that has initiated the share) @@ -1795,7 +1395,6 @@ trait Sharing { } /** - * @When /^user "([^"]*)" gets the info of the last public link share in language "([^"]*)" using the sharing API$/ * @When /^user "([^"]*)" gets the info of the last public link share using the sharing API$/ * * @param string $user username that requests the information (might not be the user that has initiated the share) @@ -2055,145 +1654,6 @@ trait Sharing { $this->setResponse($this->getAllShares($user, "?path=$path")); } - /** - * @When user :user gets all the shares with reshares of the file :path using the sharing API - * - * @param string $user - * @param string $path - * - * @return void - */ - public function userGetsAllTheSharesWithResharesFromTheFileUsingTheSharingApi( - string $user, - string $path - ): void { - $this->setResponse($this->getAllShares($user, "?reshares=true&path=$path")); - } - - /** - * @When user :user gets all the shares inside the folder :path using the sharing API - * - * @param string $user - * @param string $path - * - * @return void - */ - public function userGetsAllTheSharesInsideTheFolderUsingTheSharingApi(string $user, string $path): void { - $this->setResponse($this->getAllShares($user, "?path=$path&subfiles=true")); - } - - /** - * @Then /^the response when user "([^"]*)" gets the info of the last public link share should include$/ - * - * @param string $user - * @param TableNode|null $body - * - * @return void - * @throws Exception - */ - public function theResponseWhenUserGetsInfoOfLastPublicLinkShareShouldInclude( - string $user, - ?TableNode $body - ): void { - $user = $this->getActualUsername($user); - $this->verifyTableNodeRows($body, [], $this->shareResponseFields); - $this->getShareData($user, (string) $this->getLastCreatedPublicShare()->id); - $this->theHTTPStatusCodeShouldBe( - 200, - "Error getting info of last public link share for user $user" - ); - $this->ocsContext->assertOCSResponseIndicatesSuccess( - __METHOD__ . - ' Error getting info of last public link share for user $user\n' . - $this->ocsContext->getOCSResponseStatusMessage( - $this->getResponse() - ) . '"' - ); - $this->checkTheFields($user, $body); - } - - /** - * @Then the information of the last share of user :user should include - * - * @param string $user - * @param TableNode $body - * - * @return void - * @throws Exception - */ - public function informationOfLastShareShouldInclude( - string $user, - TableNode $body - ): void { - $user = $this->getActualUsername($user); - $shareId = $this->getLastCreatedUserGroupShareId($user); - $this->getShareData($user, $shareId); - $this->theHTTPStatusCodeShouldBe( - 200, - "Error getting info of last share for user $user with share id $shareId" - ); - $this->verifyTableNodeRows($body, [], $this->shareResponseFields); - $this->checkTheFields($user, $body); - } - - /** - * @Then /^the information for user "((?:[^']*)|(?:[^"]*))" about the received share of (file|folder) "((?:[^']*)|(?:[^"]*))" shared with a (user|group) should include$/ - * - * @param string $user - * @param string $fileOrFolder - * @param string $fileName - * @param string $type - * @param TableNode $body should provide share_type - * - * @return void - * @throws Exception - */ - public function theFieldsOfTheResponseForUserForResourceShouldInclude( - string $user, - string $fileOrFolder, - string $fileName, - string $type, - TableNode $body - ): void { - $user = $this->getActualUsername($user); - $this->verifyTableNodeColumnsCount($body, 2); - $fileName = $fileName[0] === "/" ? $fileName : '/' . $fileName; - $data = $this->getAllSharesSharedWithUser($user); - Assert::assertNotEmpty($data, 'No shares found for ' . $user); - - $bodyRows = $body->getRowsHash(); - Assert::assertArrayHasKey('share_type', $bodyRows, 'share_type is not provided'); - $share_id = null; - foreach ($data as $share) { - if ($share['file_target'] === $fileName && $share['item_type'] === $fileOrFolder) { - if (($share['share_type'] === SharingHelper::getShareType($bodyRows['share_type'])) - ) { - $share_id = $share['id']; - } - } - } - - Assert::assertNotNull($share_id, "Could not find share id for " . $user); - - if (\array_key_exists('expiration', $bodyRows) && $bodyRows['expiration'] !== '') { - $bodyRows['expiration'] = \date('d-m-Y', \strtotime($bodyRows['expiration'])); - } - - $this->getShareData($user, $share_id); - foreach ($bodyRows as $field => $value) { - if ($type === "user" && $field == "share_with") { - $value = $this->getActualUsername($value); - } - if ($field == "uid_owner") { - $value = $this->getActualUsername($value); - } - $value = $this->replaceValuesFromTable($field, $value); - Assert::assertTrue( - $this->isFieldInResponse($field, $value), - "$field doesn't have value '$value'" - ); - } - } /** * @Then /^the last share_id should be included in the response/ @@ -2227,21 +1687,6 @@ trait Sharing { } } - /** - * @Then /^the last public link share id should not be included in the response/ - * - * @return void - * @throws Exception - */ - public function checkLastPublicLinkShareIDIsNotIncluded(): void { - $shareId = (string) $this->getLastCreatedPublicShare()->id; - if ($this->isFieldInResponse('id', $shareId, false)) { - Assert::fail( - "Public link share id $shareId has been found in response" - ); - } - } - /** * * @param ResponseInterface $response @@ -2488,20 +1933,6 @@ trait Sharing { } } - /** - * @Then the last response should be empty - * - * @return void - */ - public function theFieldsOfTheLastResponseShouldBeEmpty(): void { - $data = HttpRequestHelper::getResponseXml($this->response, __METHOD__)->data[0]; - Assert::assertEquals( - \count($data->element), - 0, - "last response contains data but was expected to be empty" - ); - } - /** * * @return string @@ -2525,88 +1956,6 @@ trait Sharing { throw new Exception("No 'attributes' found inside the response of the last share."); } - /** - * @Then the additional sharing attributes for the response should include - * - * @param TableNode $attributes - * - * @return void - * @throws Exception - */ - public function checkingAttributesInLastShareResponse(TableNode $attributes): void { - $this->verifyTableNodeColumns($attributes, ['scope', 'key', 'enabled']); - $attributes = $attributes->getHash(); - - // change string "true"/"false" to boolean inside array - \array_walk_recursive( - $attributes, - function (&$value, $key) { - if ($key !== 'enabled') { - return; - } - if ($value === 'true') { - $value = true; - } - if ($value === 'false') { - $value = false; - } - } - ); - - $actualAttributes = $this->getSharingAttributesFromLastResponse(); - - // parse json to array - $actualAttributesArray = \json_decode($actualAttributes, true); - if (\json_last_error() !== JSON_ERROR_NONE) { - $errMsg = \strtolower(\json_last_error_msg()); - throw new Exception( - "JSON decoding failed because of $errMsg in json\n" . - 'Expected data to be json with array of objects. ' . - "\nReceived:\n $actualAttributes" - ); - } - - // check if the expected attributes received from table match actualAttributes - foreach ($attributes as $row) { - $foundRow = false; - foreach ($actualAttributesArray as $item) { - if (($item['scope'] === $row['scope']) - && ($item['key'] === $row['key']) - && ($item['enabled'] === $row['enabled']) - ) { - $foundRow = true; - } - } - Assert::assertTrue( - $foundRow, - "Could not find expected attribute with scope '" . $row['scope'] . "' and key '" . $row['key'] . "'" - ); - } - } - - /** - * @Then the downloading of file :fileName for user :user should fail with error message - * - * @param string $fileName - * @param string $user - * @param PyStringNode $errorMessage - * - * @return void - * @throws Exception - */ - public function userDownloadsFailWithMessage(string $fileName, string $user, PyStringNode $errorMessage): void { - $user = $this->getActualUsername($user); - $response = $this->downloadFileAsUserUsingPassword($user, $fileName); - $receivedErrorMessage = HttpRequestHelper::getResponseXml($response, __METHOD__)->xpath('//s:message'); - Assert::assertEquals( - $errorMessage, - (string) $receivedErrorMessage[0], - "Expected error message was '$errorMessage' but got '" - . $receivedErrorMessage[0] - . "'" - ); - } - /** * @Then the fields of the last response should not include * @@ -2791,28 +2140,6 @@ trait Sharing { $this->setResponse($response); } - /** - * @Given /^user "([^"]*)" has deleted public link share named "([^"]*)" in (?:file|folder) "([^"]*)"$/ - * - * @param string $user - * @param string $name - * @param string $path - * - * @return void - */ - public function userHasDeletedPublicLinkShareNamedUsingTheSharingApi( - string $user, - string $name, - string $path - ): void { - $response = $this->deletePublicLinkShareUsingTheSharingApi( - $user, - $name, - $path - ); - $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); - } - /** * @param string $user * @param string $action @@ -3038,42 +2365,6 @@ trait Sharing { $this->emptyLastOCSStatusCodesArray(); } - /** - * @When /^user "([^"]*)" accepts the (?:first|next|) pending share "([^"]*)" offered by user "([^"]*)" using the sharing API$/ - * - * @param string $user - * @param string $share - * @param string $offeredBy - * - * @return void - * @throws Exception - */ - public function userAcceptsThePendingShareOfferedBy(string $user, string $share, string $offeredBy): void { - $response = $this->reactToShareOfferedBy($user, 'accepts', $share, $offeredBy, 'pending'); - $this->setResponse($response); - $this->pushToLastStatusCodesArrays(); - } - - /** - * @Given /^user "([^"]*)" has accepted the (?:first|next|) pending share "([^"]*)" offered by user "([^"]*)"$/ - * - * @param string $user - * @param string $share - * @param string $offeredBy - * - * @return void - * @throws Exception - */ - public function userHasAcceptedThePendingShareOfferedBy(string $user, string $share, string $offeredBy) { - $response = $this->reactToShareOfferedBy($user, 'accepts', $share, $offeredBy, 'pending'); - $this->theHTTPStatusCodeShouldBe( - 200, - __METHOD__ . " could not accept the pending share $share to $user by $offeredBy", - $response - ); - $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - } - /** * @Then /^user "([^"]*)" should be able to (decline|accept) pending share "([^"]*)" offered by user "([^"]*)"$/ * @@ -3099,7 +2390,6 @@ trait Sharing { $response ); $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - // $this->ocsContext->assertOCSResponseIndicatesSuccess(); } elseif ($action === 'decline') { $response = $this->reactToShareOfferedBy($user, 'declined', $share, $offeredBy); $this->theHTTPStatusCodeShouldBe( @@ -3108,8 +2398,6 @@ trait Sharing { $response ); $this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response); - // $this->emptyLastHTTPStatusCodesArray(); - // $this->emptyLastOCSStatusCodesArray(); } } @@ -3415,41 +2703,6 @@ trait Sharing { return $response; } - /** - * @Given /^user "([^"]*)" has added the public share created from server "([^"]*)" using the sharing API$/ - * - * @param string $user - * @param string $shareServer - * - * @return void - */ - public function userHasAddedPublicShareCreatedByUser(string $user, string $shareServer): void { - $this->saveLastSharedPublicLinkShare($user, $shareServer); - - $resBody = json_decode($this->response->getBody()->getContents()); - $status = ''; - $message = ''; - if ($resBody) { - $status = $resBody->status; - $message = $resBody->data->message; - } - - Assert::assertEquals( - 200, - $this->response->getStatusCode(), - __METHOD__ - . " Expected status code is '200' but got '" - . $this->response->getStatusCode() - . "'" - ); - Assert::assertNotEquals( - 'error', - $status, - __METHOD__ - . "\nFailed to save public share.\n'$message'" - ); - } - /** * @param string $user * @param string $path @@ -3482,46 +2735,6 @@ trait Sharing { ]; } - /** - * @Given /^user "([^"]*)" has created a read only public link for (file|folder) "([^"]*)"$/ - * - * @param string $user - * @param string $type - * @param string $path - * - * @return void - * @throws Exception - */ - public function theUserHasCreatedAReadOnlyPublicLinkForFileFolder(string $user, string $type, string $path): void { - $user = $this->getActualUsername($user); - $userPassword = $this->getPasswordForUser($user); - - $requestPayload = $this->preparePublicQuickLinkPayload($user, $path, $type); - $url = $this->getBaseUrl() . "/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json"; - - $response = HttpRequestHelper::post( - $url, - $this->getStepLineRef(), - $user, - $userPassword, - null, - $requestPayload - ); - $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); - } - - /** - * @When /^user "([^"]*)" adds the public share created from server "([^"]*)" using the sharing API$/ - * - * @param string $user - * @param string $shareServer - * - * @return void - */ - public function userAddsPublicShareCreatedByUser(string $user, string $shareServer): void { - $this->setResponse($this->saveLastSharedPublicLinkShare($user, $shareServer)); - } - /** * Expires last created public link share using the testing API * @@ -3559,78 +2772,6 @@ trait Sharing { return $response; } - /** - * @Given the administrator has expired the last created share using the testing API - * - * @return void - * @throws GuzzleException - */ - public function theAdministratorHasExpiredTheLastCreatedShare(): void { - $this->expireShare(); - $httpStatus = $this->getResponse()->getStatusCode(); - Assert::assertSame( - 200, - $httpStatus, - "Request to expire last share failed. HTTP status was '$httpStatus'" - ); - $ocsStatusMessage = $this->ocsContext->getOCSResponseStatusMessage($this->getResponse()); - if ($this->getOcsApiVersion() === 1) { - $expectedOcsStatusCode = "100"; - } else { - $expectedOcsStatusCode = "200"; - } - $this->ocsContext->theOCSStatusCodeShouldBe( - $expectedOcsStatusCode, - "Request to expire last share failed: '$ocsStatusMessage'" - ); - } - - /** - * @Given the administrator has expired the last created public link share using the testing API - * - * @return void - * @throws GuzzleException - */ - public function theAdministratorHasExpiredTheLastCreatedPublicLinkShare(): void { - $this->expireLastCreatedPublicLinkShare(); - $httpStatus = $this->getResponse()->getStatusCode(); - Assert::assertSame( - 200, - $this->getResponse()->getStatusCode(), - "Request to expire last public link share failed. HTTP status was '$httpStatus'" - ); - $ocsStatusMessage = $this->ocsContext->getOCSResponseStatusMessage($this->getResponse()); - if ($this->getOcsApiVersion() === 1) { - $expectedOcsStatusCode = "100"; - } else { - $expectedOcsStatusCode = "200"; - } - $this->ocsContext->theOCSStatusCodeShouldBe( - $expectedOcsStatusCode, - "Request to expire last public link share failed: '$ocsStatusMessage'" - ); - } - - /** - * @When the administrator expires the last created share using the testing API - * - * @return void - * @throws GuzzleException - */ - public function theAdministratorExpiresTheLastCreatedShare(): void { - $this->setResponse($this->expireShare()); - } - - /** - * @When the administrator expires the last created public link share using the testing API - * - * @return void - * @throws GuzzleException - */ - public function theAdministratorExpiresTheLastCreatedPublicLinkShare(): void { - $this->setResponse($this->expireLastCreatedPublicLinkShare()); - } - /** * replace values from table * @@ -3675,218 +2816,4 @@ trait Sharing { } return $value; } - - /** - * @return array of common sharing capability settings for testing - */ - protected function getCommonSharingConfigs(): array { - return [ - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'auto_accept_share', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_auto_accept_share', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'api_enabled', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_enabled', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'public@@@enabled', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_allow_links', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'public@@@upload', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_allow_public_upload', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'group_sharing', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_allow_group_sharing', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'share_with_group_members_only', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_only_share_with_group_members', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'share_with_membership_groups_only', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_only_share_with_membership_groups', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'exclude_groups_from_sharing', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_exclude_groups', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'exclude_groups_from_sharing_list', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_exclude_groups_list', - 'testingState' => '' - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => - 'user_enumeration@@@enabled', - 'testingApp' => 'core', - 'testingParameter' => - 'shareapi_allow_share_dialog_user_enumeration', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => - 'user_enumeration@@@group_members_only', - 'testingApp' => 'core', - 'testingParameter' => - 'shareapi_share_dialog_user_enumeration_group_members', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'resharing', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_allow_resharing', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => - 'public@@@password@@@enforced_for@@@read_only', - 'testingApp' => 'core', - 'testingParameter' => - 'shareapi_enforce_links_password_read_only', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => - 'public@@@password@@@enforced_for@@@read_write', - 'testingApp' => 'core', - 'testingParameter' => - 'shareapi_enforce_links_password_read_write', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => - 'public@@@password@@@enforced_for@@@upload_only', - 'testingApp' => 'core', - 'testingParameter' => - 'shareapi_enforce_links_password_write_only', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'public@@@send_mail', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_allow_public_notification', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'public@@@social_share', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_allow_social_share', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'public@@@expire_date@@@enabled', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_default_expire_date', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'public@@@expire_date@@@enforced', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_enforce_expire_date', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'user@@@send_mail', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_allow_mail_notification', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'user@@@expire_date@@@enabled', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_default_expire_date_user_share', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'user@@@expire_date@@@enforced', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_enforce_expire_date_user_share', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'group@@@expire_date@@@enabled', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_default_expire_date_group_share', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'group@@@expire_date@@@enforced', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_enforce_expire_date_group_share', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'remote@@@expire_date@@@enabled', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_default_expire_date_remote_share', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'remote@@@expire_date@@@enforced', - 'testingApp' => 'core', - 'testingParameter' => 'shareapi_enforce_expire_date_remote_share', - 'testingState' => false - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'federation@@@outgoing', - 'testingApp' => 'files_sharing', - 'testingParameter' => 'outgoing_server2server_share_enabled', - 'testingState' => true - ], - [ - 'capabilitiesApp' => 'files_sharing', - 'capabilitiesParameter' => 'federation@@@incoming', - 'testingApp' => 'files_sharing', - 'testingParameter' => 'incoming_server2server_share_enabled', - 'testingState' => true - ] - ]; - } } diff --git a/tests/acceptance/bootstrap/SharingNgContext.php b/tests/acceptance/bootstrap/SharingNgContext.php index ea6d8a980..c6d4cf8f9 100644 --- a/tests/acceptance/bootstrap/SharingNgContext.php +++ b/tests/acceptance/bootstrap/SharingNgContext.php @@ -26,7 +26,6 @@ use GuzzleHttp\Exception\GuzzleException; use PHPUnit\Framework\Assert; use Psr\Http\Message\ResponseInterface; use TestHelpers\GraphHelper; -use TestHelpers\OcHelper; use TestHelpers\WebDavHelper; use TestHelpers\HttpRequestHelper; use TestHelpers\BehatHelper; diff --git a/tests/acceptance/bootstrap/SpacesContext.php b/tests/acceptance/bootstrap/SpacesContext.php index a77f27512..c21ffd2f0 100644 --- a/tests/acceptance/bootstrap/SpacesContext.php +++ b/tests/acceptance/bootstrap/SpacesContext.php @@ -29,7 +29,6 @@ use PHPUnit\Framework\Assert; use Psr\Http\Message\ResponseInterface; use TestHelpers\HttpRequestHelper; use TestHelpers\WebDavHelper; -use TestHelpers\SetupHelper; use TestHelpers\GraphHelper; use TestHelpers\OcHelper; use TestHelpers\BehatHelper; diff --git a/tests/acceptance/bootstrap/SpacesTUSContext.php b/tests/acceptance/bootstrap/SpacesTUSContext.php index 97b939894..0a2fe4156 100644 --- a/tests/acceptance/bootstrap/SpacesTUSContext.php +++ b/tests/acceptance/bootstrap/SpacesTUSContext.php @@ -14,8 +14,6 @@ use GuzzleHttp\Exception\GuzzleException; use PHPUnit\Framework\Assert; use TestHelpers\WebDavHelper; use TestHelpers\BehatHelper; -use TestHelpers\GraphHelper; -use TestHelpers\HttpRequestHelper; require_once 'bootstrap.php'; diff --git a/tests/acceptance/bootstrap/TrashbinContext.php b/tests/acceptance/bootstrap/TrashbinContext.php index c41b78a3c..31406e867 100644 --- a/tests/acceptance/bootstrap/TrashbinContext.php +++ b/tests/acceptance/bootstrap/TrashbinContext.php @@ -70,17 +70,6 @@ class TrashbinContext implements Context { public function userEmptiesTrashbin(string $user): void { $this->featureContext->setResponse($this->emptyTrashbin($user)); } - /** - * @Given user :user has emptied the trashbin - * - * @param string $user user - * - * @return void - */ - public function userHasEmptiedTrashbin(string $user): void { - $response = $this->emptyTrashbin($user); - $this->featureContext->theHTTPStatusCodeShouldBe(204, '', $response); - } /** * Get files list from the response from trashbin api @@ -473,29 +462,6 @@ class TrashbinContext implements Context { $this->featureContext->setResponse($response); } - /** - * @Then the last webdav response should contain the following elements - * - * @param TableNode $elements - * - * @return void - */ - public function theLastWebdavResponseShouldContainFollowingElements(TableNode $elements): void { - $files = $this->getTrashbinContentFromResponseXml(HttpRequestHelper::getResponseXml($response, __METHOD__)); - $elementRows = $elements->getHash(); - foreach ($elementRows as $expectedElement) { - $found = false; - $expectedPath = $expectedElement['path']; - foreach ($files as $file) { - if (\ltrim($expectedPath, "/") === \ltrim($file['original-location'], "/")) { - $found = true; - break; - } - } - Assert::assertTrue($found, "$expectedPath expected to be listed in response but not found"); - } - } - /** * @Then the last webdav response should not contain the following elements * @@ -950,37 +916,6 @@ class TrashbinContext implements Context { } } - /** - * @Then /^the content of file "([^"]*)" for user "([^"]*)" if the file is also in the trashbin should be "([^"]*)" otherwise "([^"]*)"$/ - * - * Note: this is a special step for an unusual bug combination. - * Delete it when the bug is fixed and the step is no longer needed. - * - * @param string|null $fileName - * @param string|null $user - * @param string|null $content - * @param string|null $alternativeContent - * - * @return void - * @throws JsonException - * @throws Exception - */ - public function contentOfFileForUserIfAlsoInTrashShouldBeOtherwise( - ?string $fileName, - ?string $user, - ?string $content, - ?string $alternativeContent - ): void { - $isInTrash = $this->isInTrash($user, $fileName); - $user = $this->featureContext->getActualUsername($user); - $response = $this->featureContext->downloadFileAsUserUsingPassword($user, $fileName); - if ($isInTrash) { - $this->featureContext->checkDownloadedContentMatches($content, '', $response); - } else { - $this->featureContext->checkDownloadedContentMatches($alternativeContent, '', $response); - } - } - /** * @When /^user "([^"]*)" restores the (?:file|folder|entry) with original path "([^"]*)" using the trashbin API$/ * diff --git a/tests/acceptance/bootstrap/WebDav.php b/tests/acceptance/bootstrap/WebDav.php index 25d817565..c3a9f73d4 100644 --- a/tests/acceptance/bootstrap/WebDav.php +++ b/tests/acceptance/bootstrap/WebDav.php @@ -21,7 +21,6 @@ use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; -use GuzzleHttp\Exception\BadResponseException; use GuzzleHttp\Exception\GuzzleException; use PHPUnit\Framework\Assert; use Psr\Http\Message\ResponseInterface;