From aac714be9a5bfb154bf8b6c0248cac6c7ba14cf4 Mon Sep 17 00:00:00 2001 From: Prarup Gurung Date: Tue, 14 Mar 2023 14:28:51 +0545 Subject: [PATCH] Removed method runOcc from FeatureContext, and refactored code --- .../features/bootstrap/FeatureContext.php | 61 -------------- .../features/bootstrap/Provisioning.php | 49 ----------- .../acceptance/features/bootstrap/Sharing.php | 69 --------------- .../features/bootstrap/TrashbinContext.php | 42 ---------- .../acceptance/features/bootstrap/WebDav.php | 57 ------------- ...pFromReceivingSharesToSharesFolder.feature | 83 ------------------- .../coreApiVersions/fileVersionAuthor.feature | 9 +- 7 files changed, 2 insertions(+), 368 deletions(-) delete mode 100644 tests/acceptance/features/coreApiShareManagementBasicToShares/excludeGroupFromReceivingSharesToSharesFolder.feature diff --git a/tests/acceptance/features/bootstrap/FeatureContext.php b/tests/acceptance/features/bootstrap/FeatureContext.php index 33bacf4408..61505bde59 100644 --- a/tests/acceptance/features/bootstrap/FeatureContext.php +++ b/tests/acceptance/features/bootstrap/FeatureContext.php @@ -3944,67 +3944,6 @@ class FeatureContext extends BehatVariablesContext { } } - /** - * Invokes an OCC command - * - * @param array|null $args of the occ command - * @param string|null $adminUsername - * @param string|null $adminPassword - * @param string|null $baseUrl - * @param string|null $ocPath - * - * @return int exit code - * @throws Exception if ocPath has not been set yet or the testing app is not enabled - */ - public function runOcc( - ?array $args = [], - ?string $adminUsername = null, - ?string $adminPassword = null, - ?string $baseUrl = null, - ?string $ocPath = null - ): int { - return $this->runOccWithEnvVariables( - $args, - null, - $adminUsername, - $adminPassword, - $baseUrl, - $ocPath - ); - } - - /** - * Invokes an OCC command with an optional array of environment variables - * - * @param array|null $args of the occ command - * @param array|null $envVariables to be defined before the command is run - * @param string|null $adminUsername - * @param string|null $adminPassword - * @param string|null $baseUrl - * @param string|null $ocPath - * - * @return int exit code - * @throws Exception if ocPath has not been set yet or the testing app is not enabled - */ - public function runOccWithEnvVariables( - ?array $args = [], - ?array $envVariables = null, - ?string $adminUsername = null, - ?string $adminPassword = null, - ?string $baseUrl = null, - ?string $ocPath = null - ): int { - $args[] = '--no-ansi'; - if ($baseUrl == null) { - $baseUrl = $this->getBaseUrl(); - } - $return = ['code' => '', 'stdOut' => '', 'stdErr' => '' ]; - $this->lastStdOut = $return['stdOut']; - $this->lastStdErr = $return['stdErr']; - $occStatusCode = (int)$return['code']; - return $occStatusCode; - } - /** * Find exception texts in stderr * diff --git a/tests/acceptance/features/bootstrap/Provisioning.php b/tests/acceptance/features/bootstrap/Provisioning.php index 0ef25449f8..396ca1d12b 100644 --- a/tests/acceptance/features/bootstrap/Provisioning.php +++ b/tests/acceptance/features/bootstrap/Provisioning.php @@ -532,20 +532,6 @@ trait Provisioning { $this->theseUsersHaveBeenCreated("", "", $doNotInitialize, $table); } - /** - * @Given the administrator has set the system language to :defaultLanguage - * - * @param string $defaultLanguage - * - * @return void - * @throws Exception - */ - public function theAdministratorHasSetTheSystemLanguageTo(string $defaultLanguage):void { - $this->runOcc( - ["config:system:set default_language --value $defaultLanguage"] - ); - } - /** * * @param string $path @@ -5733,41 +5719,6 @@ trait Provisioning { return ($this->getArrayOfAppsResponded($this->response)); } - /** - * Removes skeleton directory config from config.php and returns the config value - * - * @param string|null $baseUrl - * - * @return string - * @throws Exception - */ - public function popSkeletonDirectoryConfig(?string $baseUrl = null):string { - $path = $this->getSkeletonDirectory($baseUrl); - $this->runOcc( - ["config:system:delete skeletondirectory"], - null, - null, - $baseUrl - ); - return $path; - } - - /** - * @param string|null $baseUrl - * - * @return string - * @throws Exception - */ - private function getSkeletonDirectory(?string $baseUrl = null):string { - $this->runOcc( - ["config:system:get skeletondirectory"], - null, - null, - $baseUrl - ); - return \trim($this->getStdOutOfOccCommand()); - } - /** * Get the name of the smallest available skeleton, to "simulate" without skeleton. * diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 7c55831306..9bb0321847 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -3592,75 +3592,6 @@ trait Sharing { ); } - /** - * @When the administrator adds group :group to the exclude groups from receiving shares list using the occ command - * - * @param string $group - * - * @return int - * @throws Exception - */ - public function administratorAddsGroupToExcludeFromReceivingSharesList(string $group): int { - //get current groups - $occExitCode = $this->runOcc( - ['config:app:get files_sharing blacklisted_receiver_groups'] - ); - - $occStdOut = $this->getStdOutOfOccCommand(); - $occStdErr = $this->getStdErrOfOccCommand(); - - if (($occExitCode !== 0) && ($occExitCode !== 1)) { - throw new Exception( - "occ config:app:get files_sharing blacklisted_receiver_groups failed with exit code " . - $occExitCode . ", output " . - $occStdOut . ", error output " . - $occStdErr - ); - } - - //if the setting was never set before stdOut will be empty and return code will be 1 - if (\trim($occStdOut) === "") { - $occStdOut = "[]"; - } - - $currentGroups = \json_decode($occStdOut, true); - Assert::assertNotNull( - $currentGroups, - "could not json decode app setting 'blacklisted_receiver_groups' of 'files_sharing'\n" . - "stdOut: '" . $occStdOut . "'\n" . - "stdErr: '" . $occStdErr . "'" - ); - - $currentGroups[] = $group; - return $this->runOcc( - [ - 'config:app:set', - 'files_sharing blacklisted_receiver_groups', - '--value=' . \json_encode($currentGroups) - ] - ); - } - - /** - * @Given the administrator has added group :group to the exclude groups from receiving shares list - * - * @param string $group - * - * @return void - * @throws Exception - */ - public function administratorHasAddedGroupToExcludeFromReceivingSharesList(string $group):void { - $setSettingExitCode = $this->administratorAddsGroupToExcludeFromReceivingSharesList($group); - if ($setSettingExitCode !== 0) { - throw new Exception( - __METHOD__ . " could not set files_sharing blacklisted_receiver_groups " . - $setSettingExitCode . " " . - $this->getStdOutOfOccCommand() . " " . - $this->getStdErrOfOccCommand() - ); - } - } - /** * @When user :user gets share with id :share using the sharing API * diff --git a/tests/acceptance/features/bootstrap/TrashbinContext.php b/tests/acceptance/features/bootstrap/TrashbinContext.php index 1e983ff4d7..389672c429 100644 --- a/tests/acceptance/features/bootstrap/TrashbinContext.php +++ b/tests/acceptance/features/bootstrap/TrashbinContext.php @@ -1116,46 +1116,4 @@ class TrashbinContext implements Context { "$resource expected to be listed in response with mtime '$expectedMtime' but found '$responseMtime'" ); } - - /** - * @Given the administrator has set the following file extensions to be skipped from the trashbin - * - * @param TableNode $table - * - * @return void - * @throws Exception - */ - public function theAdministratorHasSetFollowingFileExtensionsToBeSkippedFromTrashbin(TableNode $table):void { - $this->featureContext->verifyTableNodeColumns($table, ['extension']); - foreach ($table->getHash() as $idx => $row) { - $this->featureContext->runOcc(['config:system:set', 'trashbin_skip_extensions', $idx, '--value=' . $row['extension']]); - } - } - - /** - * @Given the administrator has set the following directories to be skipped from the trashbin - * - * @param TableNode $table - * - * @return void - * @throws Exception - */ - public function theAdministratorHasSetFollowingDirectoriesToBeSkippedFromTrashbin(TableNode $table):void { - $this->featureContext->verifyTableNodeColumns($table, ['directory']); - foreach ($table->getHash() as $idx => $row) { - $this->featureContext->runOcc(['config:system:set', 'trashbin_skip_directories', $idx, '--value=' . $row['directory']]); - } - } - - /** - * @Given the administrator has set the trashbin skip size threshold to :threshold - * - * @param string $threshold - * - * @return void - * @throws Exception - */ - public function theAdministratorHasSetTrashbinSkipSizethreshold(string $threshold) { - $this->featureContext->runOcc(['config:system:set', 'trashbin_skip_size_threshold', '--value=' . $threshold]); - } } diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index b158055442..c31755a062 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -562,37 +562,6 @@ trait WebDav { ); } - /** - * @Given /^the administrator has (enabled|disabled) async operations$/ - * - * @param string $enabledOrDisabled - * - * @return void - * @throws Exception - */ - public function triggerAsyncUpload(string $enabledOrDisabled):void { - $switch = ($enabledOrDisabled !== "disabled"); - if ($switch) { - $value = 'true'; - } else { - $value = 'false'; - } - if ($this->previousAsyncSetting === null) { - $previousAsyncSetting = ['code' => '', 'stdOut' => '', 'stdErr' => '' ]['stdOut']; - $this->previousAsyncSetting = \trim($previousAsyncSetting); - } - $this->runOcc( - [ - 'config:system:set', - 'dav.enable.async', - '--type', - 'boolean', - '--value', - $value - ] - ); - } - /** * @Given the HTTP-Request-timeout is set to :seconds seconds * @@ -5393,32 +5362,6 @@ trait WebDav { } } - /** - * @Given /^the administrator has (enabled|disabled) the file version storage feature/ - * - * @param string $enabledOrDisabled - * - * @return void - * @throws Exception - */ - public function theAdministratorHasEnabledTheFileVersionStorage(string $enabledOrDisabled): void { - $switch = ($enabledOrDisabled !== "disabled"); - if ($switch) { - $value = 'true'; - } else { - $value = 'false'; - } - $this->runOcc( - [ - 'config:system:set', - 'file_storage.save_version_author', - '--type', - 'boolean', - '--value', - $value] - ); - } - /** * @Then the author of the created version with index :index should be :expectedUsername * diff --git a/tests/acceptance/features/coreApiShareManagementBasicToShares/excludeGroupFromReceivingSharesToSharesFolder.feature b/tests/acceptance/features/coreApiShareManagementBasicToShares/excludeGroupFromReceivingSharesToSharesFolder.feature deleted file mode 100644 index 2ff8c39e19..0000000000 --- a/tests/acceptance/features/coreApiShareManagementBasicToShares/excludeGroupFromReceivingSharesToSharesFolder.feature +++ /dev/null @@ -1,83 +0,0 @@ -@api @files_sharing-app-required -Feature: Exclude groups from receiving shares - As an admin - I want to exclude groups from receiving shares - So that users do not mistakenly share with groups they should not e.g. huge meta groups - - Background: - Given auto-accept shares has been disabled - And these users have been created with default attributes and without skeleton files: - | username | - | Alice | - | Brian | - | Carol | - | David | - And group "grp1" has been created - And group "grp2" has been created - And user "Brian" has been added to group "grp1" - And user "David" has been added to group "grp2" - - - Scenario Outline: sharing with a user that is part of a group that is excluded from receiving shares still works - Given using OCS API version "" - And user "Alice" has created folder "PARENT" - And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "fileToShare.txt" - And the administrator has added group "grp1" to the exclude groups from receiving shares list - When user "Alice" shares file "fileToShare.txt" with user "Brian" using the sharing API - Then the OCS status code should be "" - And the HTTP status code should be "200" - When user "Alice" shares folder "PARENT" with user "Brian" using the sharing API - Then the OCS status code should be "" - And the HTTP status code should be "200" - When user "Brian" accepts share "/fileToShare.txt" offered by user "Alice" using the sharing API - And user "Brian" accepts share "/PARENT" offered by user "Alice" using the sharing API - Then as "Brian" file "/Shares/fileToShare.txt" should exist - And as "Brian" folder "/Shares/PARENT" should exist - Examples: - | ocs_api_version | ocs_status_code | - | 1 | 100 | - | 2 | 200 | - - - Scenario Outline: sharing with a user that is part of a group that is excluded from receiving shares using an other group works - Given using OCS API version "" - And group "grp3" has been created - And user "Brian" has been added to group "grp3" - And user "Alice" has created folder "PARENT" - And user "Alice" has uploaded file "filesForUpload/textfile.txt" to "fileToShare.txt" - And the administrator has added group "grp1" to the exclude groups from receiving shares list - When user "Alice" shares file "fileToShare.txt" with group "grp3" using the sharing API - Then the OCS status code should be "" - And the HTTP status code should be "200" - When user "Alice" shares folder "PARENT" with group "grp3" using the sharing API - Then the OCS status code should be "" - And the HTTP status code should be "200" - When user "Brian" accepts share "/fileToShare.txt" offered by user "Alice" using the sharing API - And user "Brian" accepts share "/PARENT" offered by user "Alice" using the sharing API - Then as "Brian" file "/Shares/fileToShare.txt" should exist - And as "Brian" folder "/Shares/PARENT" should exist - Examples: - | ocs_api_version | ocs_status_code | - | 1 | 100 | - | 2 | 200 | - - - Scenario Outline: a user that is part of a group that is excluded from receiving shares still can initiate shares - Given using OCS API version "" - And user "Brian" has created folder "PARENT" - And user "Brian" has uploaded file "filesForUpload/textfile.txt" to "fileToShare.txt" - And the administrator has added group "grp1" to the exclude groups from receiving shares list - When user "Brian" shares file "fileToShare.txt" with user "Carol" using the sharing API - Then the OCS status code should be "" - And the HTTP status code should be "200" - And user "Brian" shares folder "PARENT" with user "Carol" using the sharing API - And the OCS status code should be "" - And the HTTP status code should be "200" - When user "Carol" accepts share "/fileToShare.txt" offered by user "Brian" using the sharing API - And user "Carol" accepts share "/PARENT" offered by user "Brian" using the sharing API - Then as "Carol" file "/Shares/fileToShare.txt" should exist - And as "Carol" folder "/Shares/PARENT" should exist - Examples: - | ocs_api_version | ocs_status_code | - | 1 | 100 | - | 2 | 200 | diff --git a/tests/acceptance/features/coreApiVersions/fileVersionAuthor.feature b/tests/acceptance/features/coreApiVersions/fileVersionAuthor.feature index d04ffcbf74..cce732c8a3 100644 --- a/tests/acceptance/features/coreApiVersions/fileVersionAuthor.feature +++ b/tests/acceptance/features/coreApiVersions/fileVersionAuthor.feature @@ -7,7 +7,6 @@ Feature: file versions remember the author of each version And user "Alice" has been created with default attributes and without skeleton files And user "Brian" has been created with default attributes and without skeleton files And user "Carol" has been created with default attributes and without skeleton files - And the administrator has enabled the file version storage feature Scenario: enable file versioning and check the history of changes from multiple users @@ -363,11 +362,9 @@ Feature: file versions remember the author of each version Scenario: check the author of the file version which was created before enabling the version storage - Given the administrator has disabled the file version storage feature - And user "Alice" has uploaded file with content "uploaded content alice" to "/textfile0.txt" + Given user "Alice" has uploaded file with content "uploaded content alice" to "/textfile0.txt" And user "Alice" has shared folder "/textfile0.txt" with user "Brian" And user "Brian" has accepted share "/textfile0.txt" offered by user "Alice" - And the administrator has enabled the file version storage feature And user "Brian" has uploaded file with content "uploaded content brian" to "/Shares/textfile0.txt" When user "Brian" restores version index "1" of file "/Shares/textfile0.txt" using the WebDAV API Then the HTTP status code should be "204" @@ -389,11 +386,9 @@ Feature: file versions remember the author of each version Scenario: check the author of the file version (inside a folder) which was created before enabling the version storage Given user "Alice" has created folder "/test" - And the administrator has disabled the file version storage feature And user "Alice" has uploaded file with content "uploaded content alice" to "/test/textfile0.txt" And user "Alice" has shared folder "/test" with user "Brian" with permissions "all" And user "Brian" has accepted share "/test" offered by user "Alice" - And the administrator has enabled the file version storage feature And user "Brian" has uploaded file with content "uploaded content brian" to "/Shares/test/textfile0.txt" When user "Brian" restores version index "1" of file "/Shares/test/textfile0.txt" using the WebDAV API Then the HTTP status code should be "204" @@ -410,4 +405,4 @@ Feature: file versions remember the author of each version | 1 | | And as user "Brian" the authors of the versions of file "/Shares/test/textfile0.txt" should be: | index | author | - | 1 | | \ No newline at end of file + | 1 | |