Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/acceptance/features/apiVersions/fileVersions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,37 @@ Feature: dav-versions
| header | value |
| Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" |
And the downloaded content should be "uploaded content"


Scenario: enable file versioning and check the history of changes from multiple users
Given the administrator has enabled the file version storage feature
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 user "Alice" creates folder "/test" using the WebDAV API
And user "Alice" shares folder "/test" with user "Brian" with permissions "all" using the sharing API
And user "Alice" shares folder "/test" with user "Carol" with permissions "all" using the sharing API
And user "Alice" has uploaded file with content "uploaded content first" to "/test/textfile0.txt"
And user "Brian" has uploaded file with content "uploaded content changed" to "/test/textfile0.txt"
And user "Carol" has uploaded file with content "uploaded content latest" to "/test/textfile0.txt"
When user "Alice" gets the number of versions of file "/test/textfile0.txt"
Then the number of versions should be "2"
When user "Alice" gets the version metadata of file "/test/textfile0.txt"
Then the author of the created version with index "1" should be "Carol"
And the author of the created version with index "2" should be "Brian"
# Actually Alice was the author of the oldest version of the file,
# and Brian was the author of the 2nd-oldest version of the file,
# and Carol is the author of current file, which is not in the version history.
#Then the author of the created version with index "1" should be "Brian"
#And the author of the created version with index "2" should be "Alice"
When user "Alice" downloads the version of file "/test/textfile0.txt" with the index "1"
Then the HTTP status code should be "200"
And the following headers should be set
| header | value |
| Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" |
And the downloaded content should be "uploaded content changed"
When user "Alice" downloads the version of file "test/textfile0.txt" with the index "2"
Then the HTTP status code should be "200"
And the following headers should be set
| header | value |
| Content-Disposition | attachment; filename*=UTF-8''textfile0.txt; filename="textfile0.txt" |
And the downloaded content should be "uploaded content first"
2 changes: 2 additions & 0 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,8 @@ public function setResponse(?ResponseInterface $response):void {
$this->response = $response;
//after a new response reset the response xml
$this->responseXml = [];
//after a new response reset the response xml object
$this->responseXmlObject = null;
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/features/bootstrap/FilesVersionsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,37 @@ public function userGetsFileVersions(string $user, string $file):void {
$this->featureContext->setResponse($response);
}

/**
* @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 {
$user = $this->featureContext->getActualUsername($user);
$fileId = $this->featureContext->getFileIdForPath($user, $file);
$body = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:prop>
<oc:meta-version-edited-by />
<oc:meta-version-edited-by-name />
</d:prop>
</d:propfind>';
$response = $this->featureContext->makeDavRequest(
$user,
"PROPFIND",
$this->getVersionsPathForFileId($fileId),
null,
$body,
null,
'2'
);
$this->featureContext->setResponse($response);
}

/**
* @When user :user restores version index :versionIndex of file :path using the WebDAV API
* @Given user :user has restored version index :versionIndex of file :path
Expand Down
73 changes: 73 additions & 0 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ public function theNumberOfVersionsShouldBe(int $number):void {
$this->getResponse(),
__METHOD__
);
$this->setResponseXmlObject($resXml);
}
$xmlPart = $resXml->xpath("//d:getlastmodified");
$actualNumber = \count($xmlPart);
Expand Down Expand Up @@ -5052,4 +5053,76 @@ public function resetPreviousSettingsAfterScenario():void {
);
}
}

/**
* @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 :expectedUser
*
* @param string $index
* @param string $expectedUser
*
* @return void
* @throws Exception
*/
public function theAuthorOfEditedVersionFile(string $index, string $expectedUser): void {
$expectedUserDisplayName = $this->getUserDisplayName($expectedUser);
$resXml = $this->getResponseXmlObject();
if ($resXml === null) {
$resXml = HttpRequestHelper::getResponseXml(
$this->getResponse(),
__METHOD__
);
$this->setResponseXmlObject($resXml);
}
$xmlPart = $resXml->xpath("//oc:meta-version-edited-by//text()");
if (!isset($xmlPart[$index - 1])) {
Assert::fail(
'could not find version with index "' . $index . '"'
);
}
$actualUser = $xmlPart[$index - 1][0];
Assert::assertEquals(
$expectedUser,
$actualUser,
"Expected user of version was '$expectedUser', but got '$actualUser'"
);

$xmlPart = $resXml->xpath("//oc:meta-version-edited-by-name//text()");
if (!isset($xmlPart[$index - 1])) {
Assert::fail(
'could not find version with index "' . $index . '"'
);
}
$actualUserDisplayName = $xmlPart[$index - 1][0];
Assert::assertEquals(
$expectedUserDisplayName,
$actualUserDisplayName,
"Expected user of version was '$expectedUser', but got '$actualUser'"
);
}
}