From 8cc13a2dbe97e52d411969b0cd3f58c60346d21e Mon Sep 17 00:00:00 2001 From: amrita Date: Thu, 26 Sep 2024 16:58:06 +0545 Subject: [PATCH] add tests for file version with OCIS_DISABLE_VERSIONING config --- .../bootstrap/FilesVersionsContext.php | 47 ++++++++--- tests/acceptance/config/behat.yml | 1 + .../fileVersionByFileID.feature | 4 +- .../disableFileVersioning.feature | 83 +++++++++++++++++++ 4 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 tests/acceptance/features/coreApiVersions/disableFileVersioning.feature diff --git a/tests/acceptance/bootstrap/FilesVersionsContext.php b/tests/acceptance/bootstrap/FilesVersionsContext.php index ed66e4ffe..7507ad78e 100644 --- a/tests/acceptance/bootstrap/FilesVersionsContext.php +++ b/tests/acceptance/bootstrap/FilesVersionsContext.php @@ -36,6 +36,25 @@ require_once 'bootstrap.php'; */ class FilesVersionsContext implements Context { private FeatureContext $featureContext; + private SpacesContext $spacesContext; + + /** + * This will run before EVERY scenario. + * It will set the properties for this object. + * + * @BeforeScenario + * + * @param BeforeScenarioScope $scope + * + * @return void + */ + public function before(BeforeScenarioScope $scope):void { + // Get the environment + $environment = $scope->getEnvironment(); + // Get all the contexts you need in this context + $this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext'); + $this->spacesContext = BehatHelper::getContext($scope, $environment, 'SpacesContext'); + } /** * @When user :user tries to get versions of file :file from :fileOwner @@ -547,19 +566,27 @@ class FilesVersionsContext implements Context { } /** - * This will run before EVERY scenario. - * It will set the properties for this object. + * @When user :user gets the number of versions of file :file from space :space + * @When user :user tries to get the number of versions of file :file from space :space * - * @BeforeScenario - * - * @param BeforeScenarioScope $scope + * @param string $user + * @param string $file + * @param string $space * * @return void */ - public function before(BeforeScenarioScope $scope):void { - // Get the environment - $environment = $scope->getEnvironment(); - // Get all the contexts you need in this context - $this->featureContext = BehatHelper::getContext($scope, $environment, 'FeatureContext'); + public function userGetsTheNumberOfVersionsOfFileFromSpace(string $user, string $file, string $space): void { + $fileId = $this->spacesContext->getFileId($user, $space, $file); + $this->featureContext->setResponse( + $this->featureContext->makeDavRequest( + $user, + "PROPFIND", + $fileId, + null, + null, + null, + "versions" + ) + ); } } diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 35b72f433..82673b782 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -615,6 +615,7 @@ default: - WebDavPropertiesContext: - TrashbinContext: - SharingNgContext: + - OcisConfigContext: coreApiWebdavDelete: paths: diff --git a/tests/acceptance/features/apiSpacesDavOperation/fileVersionByFileID.feature b/tests/acceptance/features/apiSpacesDavOperation/fileVersionByFileID.feature index 012c59385..baef8395b 100644 --- a/tests/acceptance/features/apiSpacesDavOperation/fileVersionByFileID.feature +++ b/tests/acceptance/features/apiSpacesDavOperation/fileVersionByFileID.feature @@ -1,7 +1,7 @@ Feature: checking file versions using file id As a user - I want to share file outside of the space - So that other users can access the file + I want the versions of files to be available + So that I can manage the changes made to the files Background: Given these users have been created with default attributes and without skeleton files: diff --git a/tests/acceptance/features/coreApiVersions/disableFileVersioning.feature b/tests/acceptance/features/coreApiVersions/disableFileVersioning.feature new file mode 100644 index 000000000..9de21b516 --- /dev/null +++ b/tests/acceptance/features/coreApiVersions/disableFileVersioning.feature @@ -0,0 +1,83 @@ +@env-config @skipOnReva +Feature: checking file versions + As a user + I want the versions of files to be available + So that I can manage the changes made to the files + + Background: + Given these users have been created with default attributes and without skeleton files: + | username | + | Alice | + | Brian | + And using spaces DAV path + + + Scenario: check version number of a file when versioning is disabled + Given the config "OCIS_DISABLE_VERSIONING" has been set to "true" + And user "Alice" has uploaded file with content "test file version 1" to "/testfile.txt" + And user "Alice" has uploaded file with content "test file version 2" to "/testfile.txt" + When user "Alice" gets the number of versions of file "/testfile.txt" + Then the HTTP status code should be "207" + And the number of versions should be "0" + + + Scenario: file version number should not be added after disabling versioning + Given user "Alice" has uploaded file with content "test file version 1" to "/testfile.txt" + And user "Alice" has uploaded file with content "test file version 2" to "/testfile.txt" + And the config "OCIS_DISABLE_VERSIONING" has been set to "true" + And user "Alice" has uploaded file with content "test file version 3" to "/testfile.txt" + And user "Alice" has uploaded file with content "test file version 4" to "/testfile.txt" + When user "Alice" gets the number of versions of file "/testfile.txt" + Then the HTTP status code should be "207" + And the number of versions should be "1" + + + Scenario Outline: sharee tries to check version number of a file shared from project space when versioning is disabled + Given the config "OCIS_DISABLE_VERSIONING" has been set to "true" + And the administrator has assigned the role "Space Admin" to user "Alice" using the Graph API + And user "Alice" has created a space "Project1" with the default quota using the Graph API + And user "Alice" has uploaded a file inside space "Project1" with content "hello world version 1" to "text.txt" + And user "Alice" has uploaded a file inside space "Project1" with content "hello world version 1.1" to "text.txt" + And user "Alice" has sent the following resource share invitation: + | resource | text.txt | + | space | Project1 | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + And user "Brian" has a share "text.txt" synced + When user "Brian" tries to get the number of versions of file "/text.txt" from space "Shares" + Then the HTTP status code should be "403" + Examples: + | role | + | File Editor | + | Viewer | + + + Scenario Outline: sharee tries to check version number of a file shared from personal space when versioning is disabled + Given the config "OCIS_DISABLE_VERSIONING" has been set to "true" + And user "Alice" has uploaded file with content "test file version 2" to "/text.txt" + And user "Alice" has sent the following resource share invitation: + | resource | text.txt | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | | + And user "Brian" has a share "text.txt" synced + When user "Brian" tries to get the number of versions of file "/text.txt" from space "Shares" + Then the HTTP status code should be "403" + Examples: + | permissionsRole | + | File Editor | + | Viewer | + + + Scenario: check file version number after disabling versioning, creating versions and then enabling versioning + Given the config "OCIS_DISABLE_VERSIONING" has been set to "true" + And user "Alice" has uploaded file with content "test file version 1" to "/testfile.txt" + And user "Alice" has uploaded file with content "test file version 2" to "/testfile.txt" + And the config "OCIS_DISABLE_VERSIONING" has been set to "false" + And user "Alice" has uploaded file with content "test file version 3" to "/testfile.txt" + And user "Alice" has uploaded file with content "test file version 4" to "/testfile.txt" + When user "Alice" gets the number of versions of file "/testfile.txt" + Then the HTTP status code should be "207" + And the number of versions should be "2"