2015-11-24 15:48:06 +03:00
|
|
|
<?php
|
2016-07-21 19:13:36 +03:00
|
|
|
/**
|
2017-11-06 17:56:42 +03:00
|
|
|
*
|
2016-07-21 19:13:36 +03:00
|
|
|
*
|
|
|
|
* @author David Toledo <dtoledo@solidgear.es>
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
* @author Sergio Bertolin <sbertolin@solidgear.es>
|
|
|
|
* @author Sergio Bertolín <sbertolin@solidgear.es>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
|
2015-11-27 15:55:48 +03:00
|
|
|
use GuzzleHttp\Client as GClient;
|
2015-11-24 15:48:06 +03:00
|
|
|
use GuzzleHttp\Message\ResponseInterface;
|
2018-06-13 08:15:42 +03:00
|
|
|
use PHPUnit\Framework\Assert;
|
2015-11-27 15:55:48 +03:00
|
|
|
use Sabre\DAV\Client as SClient;
|
2016-12-06 15:35:45 +03:00
|
|
|
use Sabre\DAV\Xml\Property\ResourceType;
|
2015-11-24 15:48:06 +03:00
|
|
|
|
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
|
|
|
|
|
2016-02-19 01:07:41 +03:00
|
|
|
trait WebDav {
|
2016-03-11 13:14:49 +03:00
|
|
|
use Sharing;
|
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
/** @var string */
|
2015-11-24 15:48:06 +03:00
|
|
|
private $davPath = "remote.php/webdav";
|
2018-02-09 15:19:39 +03:00
|
|
|
/** @var boolean */
|
2016-09-27 14:09:55 +03:00
|
|
|
private $usingOldDavPath = true;
|
2016-02-23 13:54:22 +03:00
|
|
|
/** @var ResponseInterface */
|
|
|
|
private $response;
|
2017-03-27 13:27:23 +03:00
|
|
|
/** @var array map with user as key and another map as value, which has path as key and etag as value */
|
|
|
|
private $storedETAG = null;
|
|
|
|
/** @var int */
|
|
|
|
private $storedFileID = null;
|
2015-11-24 15:48:06 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^using dav path "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function usingDavPath($davPath) {
|
|
|
|
$this->davPath = $davPath;
|
2016-02-24 12:39:04 +03:00
|
|
|
}
|
2015-11-24 15:48:06 +03:00
|
|
|
|
2016-07-29 07:40:39 +03:00
|
|
|
/**
|
2016-09-27 14:09:55 +03:00
|
|
|
* @Given /^using old dav path$/
|
2016-07-29 07:40:39 +03:00
|
|
|
*/
|
2016-09-27 14:09:55 +03:00
|
|
|
public function usingOldDavPath() {
|
|
|
|
$this->davPath = "remote.php/webdav";
|
|
|
|
$this->usingOldDavPath = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^using new dav path$/
|
|
|
|
*/
|
|
|
|
public function usingNewDavPath() {
|
|
|
|
$this->davPath = "remote.php/dav";
|
|
|
|
$this->usingOldDavPath = false;
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
public function getDavFilesPath($user) {
|
|
|
|
if ($this->usingOldDavPath === true) {
|
2016-09-27 14:09:55 +03:00
|
|
|
return $this->davPath;
|
2016-07-29 07:40:39 +03:00
|
|
|
} else {
|
2016-09-27 14:09:55 +03:00
|
|
|
return $this->davPath . '/files/' . $user;
|
2016-07-29 07:40:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
public function makeDavRequest($user, $method, $path, $headers, $body = null, $type = "files") {
|
|
|
|
if ($type === "files") {
|
2016-09-27 14:09:55 +03:00
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . "$path";
|
2018-02-09 15:19:39 +03:00
|
|
|
} else if ($type === "uploads") {
|
2016-09-27 14:09:55 +03:00
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
|
2018-02-09 15:19:39 +03:00
|
|
|
}
|
2015-11-27 15:55:48 +03:00
|
|
|
$client = new GClient();
|
2018-02-09 15:19:39 +03:00
|
|
|
$options = [
|
|
|
|
'headers' => $headers,
|
|
|
|
'body' => $body
|
|
|
|
];
|
2015-11-24 15:48:06 +03:00
|
|
|
if ($user === 'admin') {
|
|
|
|
$options['auth'] = $this->adminUser;
|
|
|
|
} else {
|
|
|
|
$options['auth'] = [$user, $this->regularUser];
|
|
|
|
}
|
2018-02-09 15:19:39 +03:00
|
|
|
return $client->request($method, $fullUrl, $options);
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 12:42:21 +03:00
|
|
|
* @Given /^User "([^"]*)" moved (file|folder|entry) "([^"]*)" to "([^"]*)"$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $user
|
|
|
|
* @param string $fileSource
|
|
|
|
* @param string $fileDestination
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userMovedFile($user, $entry, $fileSource, $fileDestination) {
|
2016-09-27 14:09:55 +03:00
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user);
|
2015-11-24 15:48:06 +03:00
|
|
|
$headers['Destination'] = $fullUrl . $fileDestination;
|
|
|
|
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers);
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertEquals(201, $this->response->getStatusCode());
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-22 12:42:21 +03:00
|
|
|
* @When /^User "([^"]*)" moves (file|folder|entry) "([^"]*)" to "([^"]*)"$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $user
|
|
|
|
* @param string $fileSource
|
|
|
|
* @param string $fileDestination
|
2015-11-24 15:48:06 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userMovesFile($user, $entry, $fileSource, $fileDestination) {
|
2016-09-27 14:09:55 +03:00
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user);
|
2015-11-24 15:48:06 +03:00
|
|
|
$headers['Destination'] = $fullUrl . $fileDestination;
|
2016-11-04 09:50:21 +03:00
|
|
|
try {
|
|
|
|
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers);
|
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
|
|
|
$this->response = $e->getResponse();
|
|
|
|
}
|
2015-11-24 15:48:06 +03:00
|
|
|
}
|
|
|
|
|
2016-06-30 13:15:58 +03:00
|
|
|
/**
|
|
|
|
* @When /^User "([^"]*)" copies file "([^"]*)" to "([^"]*)"$/
|
|
|
|
* @param string $user
|
|
|
|
* @param string $fileSource
|
|
|
|
* @param string $fileDestination
|
|
|
|
*/
|
|
|
|
public function userCopiesFileTo($user, $fileSource, $fileDestination) {
|
2016-09-27 14:09:55 +03:00
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user);
|
2016-06-30 13:15:58 +03:00
|
|
|
$headers['Destination'] = $fullUrl . $fileDestination;
|
|
|
|
try {
|
|
|
|
$this->response = $this->makeDavRequest($user, 'COPY', $fileSource, $headers);
|
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
|
|
|
// 4xx and 5xx responses cause an exception
|
|
|
|
$this->response = $e->getResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-30 17:07:02 +03:00
|
|
|
/**
|
|
|
|
* @When /^Downloading file "([^"]*)" with range "([^"]*)"$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $fileSource
|
|
|
|
* @param string $range
|
2015-11-30 17:07:02 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function downloadFileWithRange($fileSource, $range) {
|
2015-11-30 17:07:02 +03:00
|
|
|
$headers['Range'] = $range;
|
|
|
|
$this->response = $this->makeDavRequest($this->currentUser, "GET", $fileSource, $headers);
|
|
|
|
}
|
|
|
|
|
2015-12-03 12:46:00 +03:00
|
|
|
/**
|
|
|
|
* @When /^Downloading last public shared file with range "([^"]*)"$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $range
|
2015-12-03 12:46:00 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function downloadPublicFileWithRange($range) {
|
2015-12-03 12:46:00 +03:00
|
|
|
$token = $this->lastShareData->data->token;
|
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav";
|
|
|
|
|
|
|
|
$client = new GClient();
|
|
|
|
$options = [];
|
|
|
|
$options['auth'] = [$token, ""];
|
2018-02-09 15:19:39 +03:00
|
|
|
$options['headers'] = [
|
|
|
|
'Range' => $range
|
|
|
|
];
|
2016-02-24 12:39:04 +03:00
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->response = $client->request("GET", $fullUrl, $options);
|
2016-04-13 17:43:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When /^Downloading last public shared file inside a folder "([^"]*)" with range "([^"]*)"$/
|
|
|
|
* @param string $range
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function downloadPublicFileInsideAFolderWithRange($path, $range) {
|
2016-04-13 17:43:55 +03:00
|
|
|
$token = $this->lastShareData->data->token;
|
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav" . "$path";
|
|
|
|
|
|
|
|
$client = new GClient();
|
2018-02-09 15:19:39 +03:00
|
|
|
$options = [
|
|
|
|
'headers' => [
|
|
|
|
'Range' => $range
|
|
|
|
]
|
|
|
|
];
|
2016-04-13 17:43:55 +03:00
|
|
|
$options['auth'] = [$token, ""];
|
2016-02-24 12:39:04 +03:00
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->response = $client->request("GET", $fullUrl, $options);
|
2015-12-03 12:46:00 +03:00
|
|
|
}
|
|
|
|
|
2015-11-30 17:07:02 +03:00
|
|
|
/**
|
|
|
|
* @Then /^Downloaded content should be "([^"]*)"$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $content
|
2015-11-30 17:07:02 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function downloadedContentShouldBe($content) {
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertEquals($content, (string)$this->response->getBody());
|
2015-11-30 17:07:02 +03:00
|
|
|
}
|
|
|
|
|
2015-12-09 15:56:03 +03:00
|
|
|
/**
|
|
|
|
* @Then /^Downloaded content when downloading file "([^"]*)" with range "([^"]*)" should be "([^"]*)"$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $fileSource
|
|
|
|
* @param string $range
|
|
|
|
* @param string $content
|
2015-12-09 15:56:03 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function downloadedContentWhenDownloadindShouldBe($fileSource, $range, $content) {
|
2015-12-09 15:56:03 +03:00
|
|
|
$this->downloadFileWithRange($fileSource, $range);
|
|
|
|
$this->downloadedContentShouldBe($content);
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:54:22 +03:00
|
|
|
/**
|
|
|
|
* @When Downloading file :fileName
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $fileName
|
2016-02-23 13:54:22 +03:00
|
|
|
*/
|
|
|
|
public function downloadingFile($fileName) {
|
2016-11-04 09:50:21 +03:00
|
|
|
try {
|
|
|
|
$this->response = $this->makeDavRequest($this->currentUser, 'GET', $fileName, []);
|
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
|
|
|
$this->response = $e->getResponse();
|
|
|
|
}
|
2016-02-23 13:54:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then The following headers should be set
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param \Behat\Gherkin\Node\TableNode $table
|
|
|
|
* @throws \Exception
|
2016-02-23 13:54:22 +03:00
|
|
|
*/
|
|
|
|
public function theFollowingHeadersShouldBeSet(\Behat\Gherkin\Node\TableNode $table) {
|
2018-02-09 15:19:39 +03:00
|
|
|
foreach ($table->getTable() as $header) {
|
2016-02-23 13:54:22 +03:00
|
|
|
$headerName = $header[0];
|
|
|
|
$expectedHeaderValue = $header[1];
|
2018-02-09 15:19:39 +03:00
|
|
|
$returnedHeader = $this->response->getHeader($headerName)[0];
|
|
|
|
if ($returnedHeader !== $expectedHeaderValue) {
|
2016-02-23 13:54:22 +03:00
|
|
|
throw new \Exception(
|
|
|
|
sprintf(
|
|
|
|
"Expected value '%s' for header '%s', got '%s'",
|
|
|
|
$expectedHeaderValue,
|
|
|
|
$headerName,
|
|
|
|
$returnedHeader
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then Downloaded content should start with :start
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param int $start
|
|
|
|
* @throws \Exception
|
2016-02-23 13:54:22 +03:00
|
|
|
*/
|
|
|
|
public function downloadedContentShouldStartWith($start) {
|
2018-02-09 15:19:39 +03:00
|
|
|
if (strpos($this->response->getBody()->getContents(), $start) !== 0) {
|
2016-02-23 13:54:22 +03:00
|
|
|
throw new \Exception(
|
|
|
|
sprintf(
|
|
|
|
"Expected '%s', got '%s'",
|
|
|
|
$start,
|
|
|
|
$this->response->getBody()->getContents()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2015-12-09 15:56:03 +03:00
|
|
|
|
2016-02-24 12:39:04 +03:00
|
|
|
/**
|
2016-09-27 14:09:55 +03:00
|
|
|
* @Then /^as "([^"]*)" gets properties of (file|folder|entry) "([^"]*)" with$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $user
|
2016-11-04 09:50:21 +03:00
|
|
|
* @param string $elementType
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $path
|
2016-02-24 12:39:04 +03:00
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $propertiesTable
|
|
|
|
*/
|
2016-11-04 09:50:21 +03:00
|
|
|
public function asGetsPropertiesOfFolderWith($user, $elementType, $path, $propertiesTable) {
|
2016-02-24 12:39:04 +03:00
|
|
|
$properties = null;
|
|
|
|
if ($propertiesTable instanceof \Behat\Gherkin\Node\TableNode) {
|
|
|
|
foreach ($propertiesTable->getRows() as $row) {
|
|
|
|
$properties[] = $row[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->response = $this->listFolder($user, $path, 0, $properties);
|
|
|
|
}
|
|
|
|
|
2016-07-11 18:33:24 +03:00
|
|
|
/**
|
|
|
|
* @Then /^as "([^"]*)" the (file|folder|entry) "([^"]*)" does not exist$/
|
|
|
|
* @param string $user
|
2016-09-21 11:18:10 +03:00
|
|
|
* @param string $entry
|
2016-07-11 18:33:24 +03:00
|
|
|
* @param string $path
|
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $propertiesTable
|
|
|
|
*/
|
|
|
|
public function asTheFileOrFolderDoesNotExist($user, $entry, $path) {
|
|
|
|
$client = $this->getSabreClient($user);
|
2016-09-21 11:18:10 +03:00
|
|
|
$response = $client->request('HEAD', $this->makeSabrePath($user, $path));
|
2016-07-11 18:33:24 +03:00
|
|
|
if ($response['statusCode'] !== 404) {
|
|
|
|
throw new \Exception($entry . ' "' . $path . '" expected to not exist (status code ' . $response['statusCode'] . ', expected 404)');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then /^as "([^"]*)" the (file|folder|entry) "([^"]*)" exists$/
|
|
|
|
* @param string $user
|
2016-09-21 11:18:10 +03:00
|
|
|
* @param string $entry
|
2016-07-11 18:33:24 +03:00
|
|
|
* @param string $path
|
|
|
|
*/
|
|
|
|
public function asTheFileOrFolderExists($user, $entry, $path) {
|
|
|
|
$this->response = $this->listFolder($user, $path, 0);
|
|
|
|
}
|
|
|
|
|
2016-02-24 12:39:04 +03:00
|
|
|
/**
|
|
|
|
* @Then the single response should contain a property :key with value :value
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $key
|
|
|
|
* @param string $expectedValue
|
|
|
|
* @throws \Exception
|
2016-02-24 12:39:04 +03:00
|
|
|
*/
|
|
|
|
public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) {
|
|
|
|
$keys = $this->response;
|
2016-03-17 17:50:33 +03:00
|
|
|
if (!array_key_exists($key, $keys)) {
|
2016-03-11 13:14:49 +03:00
|
|
|
throw new \Exception("Cannot find property \"$key\" with \"$expectedValue\"");
|
2016-02-24 12:39:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$value = $keys[$key];
|
2016-12-06 15:35:45 +03:00
|
|
|
if ($value instanceof ResourceType) {
|
|
|
|
$value = $value->getValue();
|
|
|
|
if (empty($value)) {
|
|
|
|
$value = '';
|
|
|
|
} else {
|
|
|
|
$value = $value[0];
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 13:16:27 +03:00
|
|
|
if ($value != $expectedValue) {
|
2016-02-24 12:39:04 +03:00
|
|
|
throw new \Exception("Property \"$key\" found with value \"$value\", expected \"$expectedValue\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 17:50:33 +03:00
|
|
|
/**
|
|
|
|
* @Then the response should contain a share-types property with
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function theResponseShouldContainAShareTypesPropertyWith($table) {
|
2016-03-17 17:50:33 +03:00
|
|
|
$keys = $this->response;
|
|
|
|
if (!array_key_exists('{http://owncloud.org/ns}share-types', $keys)) {
|
|
|
|
throw new \Exception("Cannot find property \"{http://owncloud.org/ns}share-types\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
$foundTypes = [];
|
|
|
|
$data = $keys['{http://owncloud.org/ns}share-types'];
|
|
|
|
foreach ($data as $item) {
|
|
|
|
if ($item['name'] !== '{http://owncloud.org/ns}share-type') {
|
|
|
|
throw new \Exception('Invalid property found: "' . $item['name'] . '"');
|
|
|
|
}
|
|
|
|
|
|
|
|
$foundTypes[] = $item['value'];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($table->getRows() as $row) {
|
|
|
|
$key = array_search($row[0], $foundTypes);
|
|
|
|
if ($key === false) {
|
|
|
|
throw new \Exception('Expected type ' . $row[0] . ' not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($foundTypes[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($foundTypes !== []) {
|
|
|
|
throw new \Exception('Found more share types then specified: ' . $foundTypes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then the response should contain an empty property :property
|
|
|
|
* @param string $property
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public function theResponseShouldContainAnEmptyProperty($property) {
|
|
|
|
$properties = $this->response;
|
|
|
|
if (!array_key_exists($property, $properties)) {
|
|
|
|
throw new \Exception("Cannot find property \"$property\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($properties[$property] !== null) {
|
|
|
|
throw new \Exception("Property \"$property\" is not empty");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-30 15:20:05 +03:00
|
|
|
/*Returns the elements of a propfind, $folderDepth requires 1 to see elements without children*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function listFolder($user, $path, $folderDepth, $properties = null) {
|
2016-07-11 18:33:24 +03:00
|
|
|
$client = $this->getSabreClient($user);
|
|
|
|
if (!$properties) {
|
|
|
|
$properties = [
|
|
|
|
'{DAV:}getetag'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-09-21 11:18:10 +03:00
|
|
|
$response = $client->propfind($this->makeSabrePath($user, $path), $properties, $folderDepth);
|
2016-07-11 18:33:24 +03:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2016-11-23 20:43:57 +03:00
|
|
|
/* Returns the elements of a report command
|
|
|
|
* @param string $user
|
|
|
|
* @param string $path
|
|
|
|
* @param string $properties properties which needs to be included in the report
|
|
|
|
* @param string $filterRules filter-rules to choose what needs to appear in the report
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function reportFolder($user, $path, $properties, $filterRules) {
|
2016-11-23 12:43:55 +03:00
|
|
|
$client = $this->getSabreClient($user);
|
|
|
|
|
2016-11-23 15:02:09 +03:00
|
|
|
$body = '<?xml version="1.0" encoding="utf-8" ?>
|
2016-11-23 12:43:55 +03:00
|
|
|
<oc:filter-files xmlns:a="DAV:" xmlns:oc="http://owncloud.org/ns" >
|
|
|
|
<a:prop>
|
2016-11-23 20:43:57 +03:00
|
|
|
' . $properties . '
|
2016-11-23 12:43:55 +03:00
|
|
|
</a:prop>
|
|
|
|
<oc:filter-rules>
|
2016-11-23 20:43:57 +03:00
|
|
|
' . $filterRules . '
|
2016-11-23 12:43:55 +03:00
|
|
|
</oc:filter-rules>
|
2016-11-23 15:02:09 +03:00
|
|
|
</oc:filter-files>';
|
2016-11-23 12:43:55 +03:00
|
|
|
|
|
|
|
$response = $client->request('REPORT', $this->makeSabrePath($user, $path), $body);
|
2016-11-23 15:02:09 +03:00
|
|
|
$parsedResponse = $client->parseMultistatus($response['body']);
|
|
|
|
return $parsedResponse;
|
2016-11-23 12:43:55 +03:00
|
|
|
}
|
|
|
|
|
2016-09-21 11:18:10 +03:00
|
|
|
public function makeSabrePath($user, $path) {
|
2016-09-27 14:09:55 +03:00
|
|
|
return $this->encodePath($this->getDavFilesPath($user) . $path);
|
2016-07-11 18:33:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSabreClient($user) {
|
2015-11-27 15:55:48 +03:00
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4);
|
|
|
|
|
2017-03-20 14:41:56 +03:00
|
|
|
$settings = [
|
2015-11-27 15:55:48 +03:00
|
|
|
'baseUri' => $fullUrl,
|
|
|
|
'userName' => $user,
|
2017-03-20 14:41:56 +03:00
|
|
|
];
|
2015-11-27 15:55:48 +03:00
|
|
|
|
|
|
|
if ($user === 'admin') {
|
|
|
|
$settings['password'] = $this->adminUser[1];
|
|
|
|
} else {
|
|
|
|
$settings['password'] = $this->regularUser;
|
|
|
|
}
|
2017-03-20 14:41:56 +03:00
|
|
|
$settings['authType'] = SClient::AUTH_BASIC;
|
2015-11-27 15:55:48 +03:00
|
|
|
|
2016-07-11 18:33:24 +03:00
|
|
|
return new SClient($settings);
|
2015-11-27 15:55:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-30 15:20:05 +03:00
|
|
|
* @Then /^user "([^"]*)" should see following elements$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $user
|
2015-11-30 15:20:05 +03:00
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $expectedElements
|
2015-11-27 15:55:48 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function checkElementList($user, $expectedElements) {
|
2015-12-07 17:03:40 +03:00
|
|
|
$elementList = $this->listFolder($user, '/', 3);
|
2015-11-30 15:20:05 +03:00
|
|
|
if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) {
|
|
|
|
$elementRows = $expectedElements->getRows();
|
|
|
|
$elementsSimplified = $this->simplifyArray($elementRows);
|
2018-02-09 15:19:39 +03:00
|
|
|
foreach ($elementsSimplified as $expectedElement) {
|
2016-09-27 14:09:55 +03:00
|
|
|
$webdavPath = "/" . $this->getDavFilesPath($user) . $expectedElement;
|
2018-02-09 15:19:39 +03:00
|
|
|
if (!array_key_exists($webdavPath, $elementList)) {
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::fail("$webdavPath" . " is not in propfind answer");
|
2015-11-30 15:20:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-27 15:55:48 +03:00
|
|
|
}
|
2015-12-01 15:36:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @When User :user uploads file :source to :destination
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $user
|
|
|
|
* @param string $source
|
|
|
|
* @param string $destination
|
2015-12-01 15:36:55 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userUploadsAFileTo($user, $source, $destination) {
|
|
|
|
$file = \GuzzleHttp\Psr7\stream_for(fopen($source, 'r'));
|
2015-12-01 15:36:55 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2015-11-27 15:55:48 +03:00
|
|
|
|
2016-09-26 13:44:14 +03:00
|
|
|
/**
|
|
|
|
* @When User :user adds a file of :bytes bytes to :destination
|
|
|
|
* @param string $user
|
|
|
|
* @param string $bytes
|
|
|
|
* @param string $destination
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userAddsAFileTo($user, $bytes, $destination) {
|
2016-09-26 13:44:14 +03:00
|
|
|
$filename = "filespecificSize.txt";
|
2016-09-26 15:10:24 +03:00
|
|
|
$this->createFileSpecificSize($filename, $bytes);
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertEquals(1, file_exists("work/$filename"));
|
2016-12-22 13:17:01 +03:00
|
|
|
$this->userUploadsAFileTo($user, "work/$filename", $destination);
|
|
|
|
$this->removeFile("work/", $filename);
|
2016-12-22 14:35:03 +03:00
|
|
|
$expectedElements = new \Behat\Gherkin\Node\TableNode([["$destination"]]);
|
|
|
|
$this->checkElementList($user, $expectedElements);
|
2016-09-26 13:44:14 +03:00
|
|
|
}
|
|
|
|
|
2016-03-03 22:58:18 +03:00
|
|
|
/**
|
|
|
|
* @When User :user uploads file with content :content to :destination
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userUploadsAFileWithContentTo($user, $content, $destination) {
|
|
|
|
$file = \GuzzleHttp\Psr7\stream_for($content);
|
2016-03-03 22:58:18 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-19 01:07:41 +03:00
|
|
|
/**
|
2016-08-30 12:28:27 +03:00
|
|
|
* @When /^User "([^"]*)" deletes (file|folder) "([^"]*)"$/
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $user
|
2016-08-30 12:28:27 +03:00
|
|
|
* @param string $type
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $file
|
2016-02-19 01:07:41 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userDeletesFile($user, $type, $file) {
|
2016-02-19 01:07:41 +03:00
|
|
|
try {
|
|
|
|
$this->response = $this->makeDavRequest($user, 'DELETE', $file, []);
|
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) {
|
|
|
|
// 4xx and 5xx responses cause an exception
|
|
|
|
$this->response = $e->getResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 14:44:03 +03:00
|
|
|
/**
|
|
|
|
* @Given User :user created a folder :destination
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $user
|
|
|
|
* @param string $destination
|
2015-12-02 14:44:03 +03:00
|
|
|
*/
|
2016-07-29 07:40:39 +03:00
|
|
|
public function userCreatedAFolder($user, $destination) {
|
2015-12-02 14:44:03 +03:00
|
|
|
try {
|
2016-11-08 00:52:07 +03:00
|
|
|
$destination = '/' . ltrim($destination, '/');
|
2016-09-27 14:09:55 +03:00
|
|
|
$this->response = $this->makeDavRequest($user, "MKCOL", $destination, []);
|
2015-12-02 14:44:03 +03:00
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) {
|
|
|
|
// 4xx and 5xx responses cause an exception
|
|
|
|
$this->response = $e->getResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 22:55:49 +03:00
|
|
|
/**
|
|
|
|
* @Given user :user uploads chunk file :num of :total with :data to :destination
|
2016-03-11 13:14:49 +03:00
|
|
|
* @param string $user
|
|
|
|
* @param int $num
|
|
|
|
* @param int $total
|
|
|
|
* @param string $data
|
|
|
|
* @param string $destination
|
2016-03-07 22:55:49 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination) {
|
2016-03-07 22:55:49 +03:00
|
|
|
$num -= 1;
|
2018-02-09 15:19:39 +03:00
|
|
|
$data = \GuzzleHttp\Psr7\stream_for($data);
|
2016-09-27 14:09:55 +03:00
|
|
|
$file = $destination . '-chunking-42-' . $total . '-' . $num;
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->makeDavRequest($user, 'PUT', $file, ['OC-Chunked' => '1'], $data, "uploads");
|
2016-03-07 22:55:49 +03:00
|
|
|
}
|
|
|
|
|
2016-03-11 18:18:02 +03:00
|
|
|
/**
|
|
|
|
* @Given user :user creates a new chunking upload with id :id
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userCreatesANewChunkingUploadWithId($user, $id) {
|
|
|
|
$destination = '/uploads/' . $user . '/' . $id;
|
2016-09-27 14:09:55 +03:00
|
|
|
$this->makeDavRequest($user, 'MKCOL', $destination, [], null, "uploads");
|
2016-03-11 18:18:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given user :user uploads new chunk file :num with :data to id :id
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userUploadsNewChunkFileOfWithToId($user, $num, $data, $id) {
|
|
|
|
$data = \GuzzleHttp\Psr7\stream_for($data);
|
|
|
|
$destination = '/uploads/' . $user . '/' . $id . '/' . $num;
|
2016-09-27 14:09:55 +03:00
|
|
|
$this->makeDavRequest($user, 'PUT', $destination, [], $data, "uploads");
|
2016-03-11 18:18:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given user :user moves new chunk file with id :id to :dest
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $dest) {
|
2016-09-27 14:09:55 +03:00
|
|
|
$source = '/uploads/' . $user . '/' . $id . '/.file';
|
|
|
|
$destination = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $dest;
|
2016-03-11 18:18:02 +03:00
|
|
|
$this->makeDavRequest($user, 'MOVE', $source, [
|
|
|
|
'Destination' => $destination
|
2016-09-27 14:09:55 +03:00
|
|
|
], null, "uploads");
|
2016-03-11 18:18:02 +03:00
|
|
|
}
|
|
|
|
|
2017-08-10 13:14:02 +03:00
|
|
|
/**
|
|
|
|
* @Then user :user moves new chunk file with id :id to :dest with size :size
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userMovesNewChunkFileWithIdToMychunkedfileWithSize($user, $id, $dest, $size) {
|
2017-08-10 13:14:02 +03:00
|
|
|
$source = '/uploads/' . $user . '/' . $id . '/.file';
|
|
|
|
$destination = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $dest;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->response = $this->makeDavRequest($user, 'MOVE', $source, [
|
|
|
|
'Destination' => $destination,
|
|
|
|
'OC-Total-Length' => $size
|
|
|
|
], null, "uploads");
|
2018-02-09 15:19:39 +03:00
|
|
|
} catch (\GuzzleHttp\Exception\BadResponseException $ex) {
|
2017-08-10 13:14:02 +03:00
|
|
|
$this->response = $ex->getResponse();
|
|
|
|
}
|
|
|
|
}
|
2016-03-11 18:18:02 +03:00
|
|
|
|
2016-04-08 18:06:53 +03:00
|
|
|
/**
|
|
|
|
* @Given /^Downloading file "([^"]*)" as "([^"]*)"$/
|
|
|
|
*/
|
|
|
|
public function downloadingFileAs($fileName, $user) {
|
|
|
|
try {
|
|
|
|
$this->response = $this->makeDavRequest($user, 'GET', $fileName, []);
|
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $ex) {
|
|
|
|
$this->response = $ex->getResponse();
|
|
|
|
}
|
|
|
|
}
|
2015-11-24 15:48:06 +03:00
|
|
|
|
2016-07-11 18:33:24 +03:00
|
|
|
/**
|
|
|
|
* URL encodes the given path but keeps the slashes
|
|
|
|
*
|
|
|
|
* @param string $path to encode
|
|
|
|
* @return string encoded path
|
|
|
|
*/
|
|
|
|
private function encodePath($path) {
|
|
|
|
// slashes need to stay
|
|
|
|
return str_replace('%2F', '/', rawurlencode($path));
|
|
|
|
}
|
|
|
|
|
2016-06-14 19:20:40 +03:00
|
|
|
/**
|
|
|
|
* @When user :user favorites element :path
|
2016-04-25 17:00:19 +03:00
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userFavoritesElement($user, $path) {
|
2016-06-15 13:16:27 +03:00
|
|
|
$this->response = $this->changeFavStateOfAnElement($user, $path, 1, 0, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @When user :user unfavorites element :path
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userUnfavoritesElement($user, $path) {
|
2016-06-15 13:16:27 +03:00
|
|
|
$this->response = $this->changeFavStateOfAnElement($user, $path, 0, 0, null);
|
2016-04-25 17:00:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*Set the elements of a proppatch, $folderDepth requires 1 to see elements without children*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function changeFavStateOfAnElement($user, $path, $favOrUnfav, $folderDepth, $properties = null) {
|
2016-04-25 17:00:19 +03:00
|
|
|
$fullUrl = substr($this->baseUrl, 0, -4);
|
2017-03-20 14:41:56 +03:00
|
|
|
$settings = [
|
2016-04-25 17:00:19 +03:00
|
|
|
'baseUri' => $fullUrl,
|
|
|
|
'userName' => $user,
|
2017-03-20 14:41:56 +03:00
|
|
|
];
|
2016-04-25 17:00:19 +03:00
|
|
|
if ($user === 'admin') {
|
|
|
|
$settings['password'] = $this->adminUser[1];
|
|
|
|
} else {
|
|
|
|
$settings['password'] = $this->regularUser;
|
|
|
|
}
|
2017-03-20 14:41:56 +03:00
|
|
|
$settings['authType'] = SClient::AUTH_BASIC;
|
|
|
|
|
2016-04-25 17:00:19 +03:00
|
|
|
$client = new SClient($settings);
|
|
|
|
if (!$properties) {
|
|
|
|
$properties = [
|
2016-06-15 13:16:27 +03:00
|
|
|
'{http://owncloud.org/ns}favorite' => $favOrUnfav
|
2016-04-25 17:00:19 +03:00
|
|
|
];
|
|
|
|
}
|
2016-06-14 19:20:40 +03:00
|
|
|
|
2016-09-27 14:09:55 +03:00
|
|
|
$response = $client->proppatch($this->getDavFilesPath($user) . $path, $properties, $folderDepth);
|
2016-04-25 17:00:19 +03:00
|
|
|
return $response;
|
|
|
|
}
|
2016-06-14 19:20:40 +03:00
|
|
|
|
2016-10-13 16:16:30 +03:00
|
|
|
/**
|
|
|
|
* @Given user :user stores etag of element :path
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userStoresEtagOfElement($user, $path) {
|
2016-10-13 16:16:30 +03:00
|
|
|
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
|
2016-11-04 09:50:21 +03:00
|
|
|
$this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable);
|
2016-10-13 16:16:30 +03:00
|
|
|
$pathETAG[$path] = $this->response['{DAV:}getetag'];
|
2018-02-09 15:19:39 +03:00
|
|
|
$this->storedETAG[$user] = $pathETAG;
|
2016-10-13 16:16:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then etag of element :path of user :user has not changed
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function checkIfETAGHasNotChanged($path, $user) {
|
2016-10-13 16:16:30 +03:00
|
|
|
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
|
2016-11-04 09:50:21 +03:00
|
|
|
$this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable);
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertEquals($this->response['{DAV:}getetag'], $this->storedETAG[$user][$path]);
|
2016-10-13 16:16:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then etag of element :path of user :user has changed
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function checkIfETAGHasChanged($path, $user) {
|
2016-10-13 16:16:30 +03:00
|
|
|
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
|
2016-11-04 09:50:21 +03:00
|
|
|
$this->asGetsPropertiesOfFolderWith($user, 'entry', $path, $propertiesTable);
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertNotEquals($this->response['{DAV:}getetag'], $this->storedETAG[$user][$path]);
|
2016-10-13 16:16:30 +03:00
|
|
|
}
|
2016-11-22 20:24:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @When Connecting to dav endpoint
|
|
|
|
*/
|
|
|
|
public function connectingToDavEndpoint() {
|
|
|
|
try {
|
|
|
|
$this->response = $this->makeDavRequest(null, 'PROPFIND', '', []);
|
|
|
|
} catch (\GuzzleHttp\Exception\ClientException $e) {
|
|
|
|
$this->response = $e->getResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then there are no duplicate headers
|
|
|
|
*/
|
|
|
|
public function thereAreNoDuplicateHeaders() {
|
|
|
|
$headers = $this->response->getHeaders();
|
|
|
|
foreach ($headers as $headerName => $headerValues) {
|
|
|
|
// if a header has multiple values, they must be different
|
|
|
|
if (count($headerValues) > 1 && count(array_unique($headerValues)) < count($headerValues)) {
|
|
|
|
throw new \Exception('Duplicate header found: ' . $headerName);
|
|
|
|
}
|
|
|
|
}
|
2018-02-09 15:19:39 +03:00
|
|
|
}
|
2016-11-23 12:43:55 +03:00
|
|
|
|
2018-02-09 15:19:39 +03:00
|
|
|
/**
|
2016-11-23 12:43:55 +03:00
|
|
|
* @Then /^user "([^"]*)" in folder "([^"]*)" should have favorited the following elements$/
|
|
|
|
* @param string $user
|
|
|
|
* @param string $folder
|
|
|
|
* @param \Behat\Gherkin\Node\TableNode|null $expectedElements
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function checkFavoritedElements($user, $folder, $expectedElements) {
|
2016-11-23 20:43:57 +03:00
|
|
|
$elementList = $this->reportFolder($user,
|
2018-02-09 15:19:39 +03:00
|
|
|
$folder,
|
|
|
|
'<oc:favorite/>',
|
|
|
|
'<oc:favorite>1</oc:favorite>');
|
2016-11-23 12:43:55 +03:00
|
|
|
if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) {
|
|
|
|
$elementRows = $expectedElements->getRows();
|
|
|
|
$elementsSimplified = $this->simplifyArray($elementRows);
|
2018-02-09 15:19:39 +03:00
|
|
|
foreach ($elementsSimplified as $expectedElement) {
|
2016-11-23 12:43:55 +03:00
|
|
|
$webdavPath = "/" . $this->getDavFilesPath($user) . $expectedElement;
|
2018-02-09 15:19:39 +03:00
|
|
|
if (!array_key_exists($webdavPath, $elementList)) {
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::fail("$webdavPath" . " is not in report answer");
|
2016-11-23 12:43:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 17:31:48 +03:00
|
|
|
/**
|
|
|
|
* @When /^User "([^"]*)" deletes everything from folder "([^"]*)"$/
|
|
|
|
* @param string $user
|
|
|
|
* @param string $folder
|
|
|
|
*/
|
2018-02-09 15:19:39 +03:00
|
|
|
public function userDeletesEverythingInFolder($user, $folder) {
|
2017-03-15 17:31:48 +03:00
|
|
|
$elementList = $this->listFolder($user, $folder, 1);
|
|
|
|
$elementListKeys = array_keys($elementList);
|
|
|
|
array_shift($elementListKeys);
|
2018-02-09 15:19:39 +03:00
|
|
|
$davPrefix = "/" . $this->getDavFilesPath($user);
|
|
|
|
foreach ($elementListKeys as $element) {
|
2017-03-15 17:31:48 +03:00
|
|
|
if (substr($element, 0, strlen($davPrefix)) == $davPrefix) {
|
|
|
|
$element = substr($element, strlen($davPrefix));
|
|
|
|
}
|
|
|
|
$this->userDeletesFile($user, "element", $element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-27 13:27:23 +03:00
|
|
|
/**
|
|
|
|
* @param string $user
|
|
|
|
* @param string $path
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private function getFileIdForPath($user, $path) {
|
|
|
|
$propertiesTable = new \Behat\Gherkin\Node\TableNode([["{http://owncloud.org/ns}fileid"]]);
|
|
|
|
$this->asGetsPropertiesOfFolderWith($user, 'file', $path, $propertiesTable);
|
2018-02-09 15:19:39 +03:00
|
|
|
return (int)$this->response['{http://owncloud.org/ns}fileid'];
|
2017-03-27 13:27:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^User "([^"]*)" stores id of file "([^"]*)"$/
|
|
|
|
* @param string $user
|
|
|
|
* @param string $path
|
|
|
|
*/
|
|
|
|
public function userStoresFileIdForPath($user, $path) {
|
|
|
|
$this->storedFileID = $this->getFileIdForPath($user, $path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Given /^User "([^"]*)" checks id of file "([^"]*)"$/
|
|
|
|
* @param string $user
|
|
|
|
* @param string $path
|
|
|
|
*/
|
|
|
|
public function userChecksFileIdForPath($user, $path) {
|
|
|
|
$currentFileID = $this->getFileIdForPath($user, $path);
|
2018-06-13 08:15:42 +03:00
|
|
|
Assert::assertEquals($currentFileID, $this->storedFileID);
|
2017-03-27 13:27:23 +03:00
|
|
|
}
|
2016-04-25 17:00:19 +03:00
|
|
|
}
|