diff options
Diffstat (limited to 'build/integration/features/bootstrap/FeatureContext.php')
-rw-r--r-- | build/integration/features/bootstrap/FeatureContext.php | 129 |
1 files changed, 118 insertions, 11 deletions
diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index 4a0299d6e49..46c86f1300b 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -562,7 +562,30 @@ class FeatureContext implements Context, SnippetAcceptingContext { * @param \Behat\Gherkin\Node\TableNode|null $formData */ public function createPublicShare($body) { - $this->sendingToWith("POST", "/apps/files_sharing/api/v1/shares", $body); + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v1/shares"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + + if ($body instanceof \Behat\Gherkin\Node\TableNode) { + $fd = $body->getRowsHash(); + if (array_key_exists('expireDate', $fd)){ + $dateModification = $fd['expireDate']; + $fd['expireDate'] = date('Y-m-d', strtotime($dateModification)); + } + $options['body'] = $fd; + } + + try { + $this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + $this->response = $ex->getResponse(); + } + $this->lastShareData = $this->response->xml(); } @@ -572,7 +595,12 @@ class FeatureContext implements Context, SnippetAcceptingContext { public function checkPublicSharedFile($filename) { $client = new Client(); $options = []; - $url = $this->lastShareData->data[0]->url; + if (count($this->lastShareData->data->element) > 0){ + $url = $this->lastShareData->data[0]->url; + } + else{ + $url = $this->lastShareData->data->url; + } $fullUrl = $url . "/download"; $options['save_to'] = "./$filename"; $this->response = $client->get($fullUrl, $options); @@ -590,7 +618,13 @@ class FeatureContext implements Context, SnippetAcceptingContext { public function checkPublicSharedFileWithPassword($filename, $password) { $client = new Client(); $options = []; - $token = $this->lastShareData->data[0]->token; + if (count($this->lastShareData->data->element) > 0){ + $token = $this->lastShareData->data[0]->token; + } + else{ + $token = $this->lastShareData->data->token; + } + $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav"; $options['auth'] = [$token, $password]; $options['save_to'] = "./$filename"; @@ -622,6 +656,40 @@ class FeatureContext implements Context, SnippetAcceptingContext { PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); } + /** + * @When /^Updating last share with$/ + * @param \Behat\Gherkin\Node\TableNode|null $formData + */ + public function updatingLastShare($body) { + $share_id = $this->lastShareData->data[0]->id; + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + + if ($body instanceof \Behat\Gherkin\Node\TableNode) { + $fd = $body->getRowsHash(); + if (array_key_exists('expireDate', $fd)){ + $dateModification = $fd['expireDate']; + $fd['expireDate'] = date('Y-m-d', strtotime($dateModification)); + } + $options['body'] = $fd; + } + + try { + $this->response = $client->send($client->createRequest("PUT", $fullUrl, $options)); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + $this->response = $ex->getResponse(); + } + + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + } + + public function createShare($user, $path = null, $shareType = null, @@ -669,17 +737,49 @@ class FeatureContext implements Context, SnippetAcceptingContext { } - public function isFieldInResponse($field, $content_expected){ + public function isExpectedUrl($possibleUrl, $finalPart){ + $baseUrlChopped = substr($this->baseUrl, 0, -4); + $endCharacter = strlen($baseUrlChopped) + strlen($finalPart); + return (substr($possibleUrl,0,$endCharacter) == "$baseUrlChopped" . "$finalPart"); + } + + public function isFieldInResponse($field, $contentExpected){ $data = $this->response->xml()->data[0]; - foreach($data as $element) { - if ($content_expected == "A_NUMBER"){ - return is_numeric((string)$element->$field); - } - elseif ($element->$field == $content_expected){ - return True; + if ((string)$field == 'expiration'){ + $contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00"; + } + if (count($data->element) > 0){ + foreach($data as $element) { + if ($contentExpected == "A_TOKEN"){ + return (strlen((string)$element->$field) == 15); + } + elseif ($contentExpected == "A_NUMBER"){ + return is_numeric((string)$element->$field); + } + elseif($contentExpected == "AN_URL"){ + return $this->isExpectedUrl((string)$element->$field, "index.php/s/"); + } + elseif ($element->$field == $contentExpected){ + return True; + } + } + + return False; + } else { + if ($contentExpected == "A_TOKEN"){ + return (strlen((string)$data->$field) == 15); + } + elseif ($contentExpected == "A_NUMBER"){ + return is_numeric((string)$data->$field); + } + elseif($contentExpected == "AN_URL"){ + return $this->isExpectedUrl((string)$data->$field, "index.php/s/"); + } + elseif ($data->$field == $contentExpected){ + return True; } + return False; } - return False; } /** @@ -767,6 +867,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { public function checkShareFields($body){ if ($body instanceof \Behat\Gherkin\Node\TableNode) { $fd = $body->getRowsHash(); + foreach($fd as $field => $value) { PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse($field, $value)); } @@ -786,6 +887,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { for ($i=0; $i<5; $i++){ file_put_contents("../../core/skeleton/" . "textfile" . "$i" . ".txt", "ownCloud test text file\n"); } + if (!file_exists("../../core/skeleton/FOLDER")) { + mkdir("../../core/skeleton/FOLDER", 0777, true); + } } @@ -796,6 +900,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { for ($i=0; $i<5; $i++){ self::removeFile("../../core/skeleton/", "textfile" . "$i" . ".txt"); } + if (!is_dir("../../core/skeleton/FOLDER")) { + rmdir("../../core/skeleton/FOLDER"); + } } /** |