diff options
Diffstat (limited to 'build/integration/features/bootstrap')
-rw-r--r-- | build/integration/features/bootstrap/BasicStructure.php | 18 | ||||
-rw-r--r-- | build/integration/features/bootstrap/Provisioning.php | 18 | ||||
-rw-r--r-- | build/integration/features/bootstrap/Sharing.php | 4 | ||||
-rw-r--r-- | build/integration/features/bootstrap/WebDav.php | 109 |
4 files changed, 139 insertions, 10 deletions
diff --git a/build/integration/features/bootstrap/BasicStructure.php b/build/integration/features/bootstrap/BasicStructure.php index 01a288a6c6a..bf3b1d50814 100644 --- a/build/integration/features/bootstrap/BasicStructure.php +++ b/build/integration/features/bootstrap/BasicStructure.php @@ -152,6 +152,14 @@ trait BasicStructure{ if (!file_exists("../../core/skeleton/FOLDER")) { mkdir("../../core/skeleton/FOLDER", 0777, true); } + if (!file_exists("../../core/skeleton/PARENT")) { + mkdir("../../core/skeleton/PARENT", 0777, true); + } + file_put_contents("../../core/skeleton/PARENT/" . "parent.txt", "ownCloud test text file\n"); + if (!file_exists("../../core/skeleton/PARENT/CHILD")) { + mkdir("../../core/skeleton/PARENT/CHILD", 0777, true); + } + file_put_contents("../../core/skeleton/PARENT/CHILD/" . "child.txt", "ownCloud test text file\n"); } @@ -165,6 +173,16 @@ trait BasicStructure{ if (is_dir("../../core/skeleton/FOLDER")) { rmdir("../../core/skeleton/FOLDER"); } + self::removeFile("../../core/skeleton/PARENT/CHILD/", "child.txt"); + if (is_dir("../../core/skeleton/PARENT/CHILD")) { + rmdir("../../core/skeleton/PARENT/CHILD"); + } + self::removeFile("../../core/skeleton/PARENT/", "parent.txt"); + if (is_dir("../../core/skeleton/PARENT")) { + rmdir("../../core/skeleton/PARENT"); + } + + } } diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php index 05a8885d96d..9a21c0bb1d4 100644 --- a/build/integration/features/bootstrap/Provisioning.php +++ b/build/integration/features/bootstrap/Provisioning.php @@ -175,7 +175,7 @@ trait Provisioning { * @Given /^user "([^"]*)" belongs to group "([^"]*)"$/ */ public function assureUserBelongsToGroup($user, $group){ - if (!$this->userBelongsToGroup($user, $group)){ + if (!$this->userBelongsToGroup($user, $group)){ $previous_user = $this->currentUser; $this->currentUser = "admin"; $this->addingUserToGroup($user, $group); @@ -431,7 +431,7 @@ trait Provisioning { $this->theSubadminGroupsShouldBe($groupsList); } - /** + /** * Parses the xml answer to get the array of users returned. * @param ResponseInterface $resp * @return array @@ -511,6 +511,20 @@ trait Provisioning { } /** + * @Given user :user has a quota of :quota + */ + public function userHasAQuotaOf($user, $quota) + { + $body = new \Behat\Gherkin\Node\TableNode([ + 0 => ['key', 'quota'], + 1 => ['value', $quota], + ]); + + // method used from BasicStructure trait + $this->sendingToWith("PUT", "/cloud/users/" . $user, $body); + } + + /** * @BeforeScenario * @AfterScenario */ diff --git a/build/integration/features/bootstrap/Sharing.php b/build/integration/features/bootstrap/Sharing.php index 9c5dc9f374b..5103b4af508 100644 --- a/build/integration/features/bootstrap/Sharing.php +++ b/build/integration/features/bootstrap/Sharing.php @@ -273,7 +273,7 @@ trait Sharing{ } /** - * @Given /^file "([^"]*)" from user "([^"]*)" is shared with user "([^"]*)"$/ + * @Given /^file "([^"]*)" of user "([^"]*)" is shared with user "([^"]*)"$/ */ public function assureFileIsShared($filepath, $user1, $user2){ $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath"; @@ -295,7 +295,7 @@ trait Sharing{ } /** - * @Given /^file "([^"]*)" from user "([^"]*)" is shared with group "([^"]*)"$/ + * @Given /^file "([^"]*)" of user "([^"]*)" is shared with group "([^"]*)"$/ */ public function assureFileIsSharedWithGroup($filepath, $user, $group){ $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares" . "?path=$filepath"; diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php index 1bda8175eeb..a682467f52d 100644 --- a/build/integration/features/bootstrap/WebDav.php +++ b/build/integration/features/bootstrap/WebDav.php @@ -2,8 +2,9 @@ use Behat\Behat\Context\Context; use Behat\Behat\Context\SnippetAcceptingContext; -use GuzzleHttp\Client; +use GuzzleHttp\Client as GClient; use GuzzleHttp\Message\ResponseInterface; +use Sabre\DAV\Client as SClient; require __DIR__ . '/../../vendor/autoload.php'; @@ -20,9 +21,9 @@ trait WebDav{ $this->davPath = $davPath; } - public function makeDavRequest($user, $method, $path, $headers){ + public function makeDavRequest($user, $method, $path, $headers, $body = null){ $fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path"; - $client = new Client(); + $client = new GClient(); $options = []; if ($user === 'admin') { $options['auth'] = $this->adminUser; @@ -30,10 +31,16 @@ trait WebDav{ $options['auth'] = [$user, $this->regularUser]; } $request = $client->createRequest($method, $fullUrl, $options); - foreach ($headers as $key => $value) { - $request->addHeader($key, $value); + if (!is_null($headers)){ + foreach ($headers as $key => $value) { + $request->addHeader($key, $value); + } } - //$this->response = $client->send($request); + + if (!is_null($body)) { + $request->setBody($body); + } + return $client->send($request); } @@ -56,5 +63,95 @@ trait WebDav{ $this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers); } + /** + * @When /^Downloading file "([^"]*)" with range "([^"]*)"$/ + */ + public function downloadFileWithRange($fileSource, $range){ + $fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath; + $headers['Range'] = $range; + $this->response = $this->makeDavRequest($this->currentUser, "GET", $fileSource, $headers); + } + + /** + * @When /^Downloading last public shared file with range "([^"]*)"$/ + */ + public function downloadPublicFileWithRange($range){ + $token = $this->lastShareData->data->token; + $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav"; + $headers['Range'] = $range; + + $client = new GClient(); + $options = []; + $options['auth'] = [$token, ""]; + + $request = $client->createRequest("GET", $fullUrl, $options); + $request->addHeader('Range', $range); + + $this->response = $client->send($request); + } + + /** + * @Then /^Downloaded content should be "([^"]*)"$/ + */ + public function downloadedContentShouldBe($content){ + PHPUnit_Framework_Assert::assertEquals($content, (string)$this->response->getBody()); + } + + /*Returns the elements of a propfind, $folderDepth requires 1 to see elements without children*/ + public function listFolder($user, $path, $folderDepth){ + $fullUrl = substr($this->baseUrl, 0, -4); + + $settings = array( + 'baseUri' => $fullUrl, + 'userName' => $user, + ); + + if ($user === 'admin') { + $settings['password'] = $this->adminUser[1]; + } else { + $settings['password'] = $this->regularUser; + } + + $client = new SClient($settings); + + $response = $client->propfind($this->davPath . "/", array( + '{DAV:}getetag' + ), $folderDepth); + + return $response; + } + + /** + * @Then /^user "([^"]*)" should see following elements$/ + * @param \Behat\Gherkin\Node\TableNode|null $expectedElements + */ + public function checkElementList($user, $expectedElements){ + $elementList = $this->listFolder($user, '/', 2); + if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) { + $elementRows = $expectedElements->getRows(); + $elementsSimplified = $this->simplifyArray($elementRows); + foreach($elementsSimplified as $expectedElement) { + $webdavPath = "/" . $this->davPath . $expectedElement; + if (!array_key_exists($webdavPath,$elementList)){ + PHPUnit_Framework_Assert::fail("$webdavPath" . " is not in propfind answer"); + } + } + } + } + + /** + * @When User :user uploads file :source to :destination + */ + public function userUploadsAFileTo($user, $source, $destination) + { + $file = \GuzzleHttp\Stream\Stream::factory(fopen($source, 'r')); + try { + $this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file); + } catch (\GuzzleHttp\Exception\ServerException $e) { + // 4xx and 5xx responses cause an exception + $this->response = $e->getResponse(); + } + } + } |