From a7f1f2ae08c2208916b0b88a691d38ecc9678083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 20 Nov 2017 20:10:30 +0100 Subject: [PATCH] Testing /remote.php/dav/meta/$fileId/v --- composer.json | 3 +- composer.lock | 41 +++++++++++- tests/integration/config/behat.yml | 2 + .../features/bootstrap/FeatureContext.php | 2 +- .../integration/features/bootstrap/WebDav.php | 67 +++++++++++++++++++ 5 files changed, 112 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c45080714d58..77efd9ca576d 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "behat/mink-selenium2-driver": "dev-master", "sensiolabs/behat-page-object-extension": "^2.0", "behat/behat": "^3.0", - "jarnaiz/behat-junit-formatter": "^1.3" + "jarnaiz/behat-junit-formatter": "^1.3", + "rdx/behat-variables": "^1.2" }, "require": { "php": ">=5.4.1", diff --git a/composer.lock b/composer.lock index d8a89e24245c..3e2c6a27f205 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "afe01a9162d2444fecf937c68bec7db2", + "content-hash": "225f33588968102e080c32fd5a128164", "packages": [ { "name": "bantu/ini-get-wrapper", @@ -4903,6 +4903,45 @@ ], "time": "2017-06-30T09:13:00+00:00" }, + { + "name": "rdx/behat-variables", + "version": "1.2", + "source": { + "type": "git", + "url": "https://github.com/rudiedirkx/behat-variables.git", + "reference": "3729c7aec18cf4a4ce1a0faacc8da3fc0dc9354a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rudiedirkx/behat-variables/zipball/3729c7aec18cf4a4ce1a0faacc8da3fc0dc9354a", + "reference": "3729c7aec18cf4a4ce1a0faacc8da3fc0dc9354a", + "shasum": "" + }, + "require": { + "behat/behat": "^3.0" + }, + "require-dev": { + "symfony/process": "^2.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "rdx\\behatvars\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Rudie Dirkx", + "email": "github@hotblocks.nl" + } + ], + "description": "Store variables across Scenarios during Behat testing", + "time": "2017-11-16T11:58:21+00:00" + }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", diff --git a/tests/integration/config/behat.yml b/tests/integration/config/behat.yml index 768915d6e0b4..89813ab40c70 100644 --- a/tests/integration/config/behat.yml +++ b/tests/integration/config/behat.yml @@ -60,3 +60,5 @@ default: jarnaiz\JUnitFormatter\JUnitFormatterExtension: filename: report.xml outputDir: %paths.base%/../output/ + + rdx\behatvars\BehatVariablesExtension: ~ diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 0ac12c538abb..cecc9e4ee035 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -31,7 +31,7 @@ /** * Features context. */ -class FeatureContext implements Context, SnippetAcceptingContext { +class FeatureContext extends \rdx\behatvars\BehatVariablesContext { use BasicStructure; /** diff --git a/tests/integration/features/bootstrap/WebDav.php b/tests/integration/features/bootstrap/WebDav.php index d775c14546bc..9ad37a20bfb5 100644 --- a/tests/integration/features/bootstrap/WebDav.php +++ b/tests/integration/features/bootstrap/WebDav.php @@ -491,6 +491,58 @@ public function listFolder($user, $path, $folderDepth, $properties = null) { return $response; } + public function listVersionFolder($user, $path, $folderDepth, $properties = null) { + $client = $this->getSabreClient($user); + if (!$properties) { + $properties = [ + '{DAV:}getetag' + ]; + } + + try { + $response = $client->propfind($this->makeSabrePathNotForFiles($path), $properties, $folderDepth); + } catch (Sabre\HTTP\ClientHttpException $e) { + $response = $e->getResponse(); + } + return $response; + } + + /** + * @Then the version folder of file :path for user :user contains :count elements + * @param $path + * @param $count + * @param $user + */ + public function theVersionFolderOfFileContainsElements($path, $user, $count) { + $fileId = $this->getFileIdForPath($user, $path); + $elements = $this->listVersionFolder($user, '/meta/'.$fileId.'/v', 1); + PHPUnit_Framework_Assert::assertEquals($count, count($elements)-1); + } + + /** + * @Then the version folder of fileId :fileId contains :count elements + * @param int $count + * @param int $fileId + */ + public function theVersionFolderOfFileIdContainsElements($fileId, $count) { + $elements = $this->listVersionFolder($this->currentUser, '/meta/'.$fileId.'/v', 1); + PHPUnit_Framework_Assert::assertEquals($count, count($elements)-1); + } + + /** + * @Then the content length of file :path with version index :index for user :user in versions folder is :length + * @param $path + * @param $index + * @param $user + * @param $length + */ + public function theContentLengthOfFileForUserInVersionsFolderIs($path, $index, $user, $length) { + $fileId = $this->getFileIdForPath($user, $path); + $elements = $this->listVersionFolder($user, '/meta/'.$fileId.'/v', 1, ['{DAV:}getcontentlength']); + $elements = array_values($elements); + PHPUnit_Framework_Assert::assertEquals($length, $elements[$index]['{DAV:}getcontentlength']); + } + /* Returns the elements of a report command * @param string $user * @param string $path @@ -778,6 +830,7 @@ public function userUploadsAFileWithContentTo($user, $content, $destination) $file = \GuzzleHttp\Stream\Stream::factory($content); try { $this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file); + return $this->response->getHeader('oc-fileid'); } catch (BadResponseException $e) { // 4xx and 5xx responses cause an exception $this->response = $e->getResponse(); @@ -1142,4 +1195,18 @@ public function userChecksFileIdForPath($user, $path) { $currentFileID = $this->getFileIdForPath($user, $path); PHPUnit_Framework_Assert::assertEquals($currentFileID, $this->storedFileID); } + + /** + * @When user :user restores version index :versionIndex of file :path + * @param string $user + * @param int $versionIndex + * @param string $path + */ + public function userRestoresVersionIndexOfFile($user, $versionIndex, $path) { + $fileId = $this->getFileIdForPath($user, $path); + $client = $this->getSabreClient($user); + $versions = array_keys($this->listVersionFolder($user, '/meta/'.$fileId.'/v', 1)); + $client->request('COPY', $versions[$versionIndex], null, ['Destination' => $this->makeSabrePath($user, $path)]); + } + }