2016-11-08 00:52:07 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2017-11-06 17:56:42 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author Sujith H <sharidasan@owncloud.com>
|
2016-11-08 00:52:07 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-11-08 00:52:07 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
|
|
|
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
|
|
|
|
|
|
|
class CommandLineContext implements \Behat\Behat\Context\Context {
|
|
|
|
use CommandLine;
|
|
|
|
|
|
|
|
private $lastTransferPath;
|
|
|
|
|
|
|
|
private $featureContext;
|
|
|
|
|
|
|
|
public function __construct($ocPath, $baseUrl) {
|
|
|
|
$this->ocPath = rtrim($ocPath, '/') . '/';
|
|
|
|
$this->localBaseUrl = $baseUrl;
|
|
|
|
$this->remoteBaseUrl = $baseUrl;
|
|
|
|
}
|
|
|
|
|
2017-04-11 02:30:32 +03:00
|
|
|
/**
|
|
|
|
* @Given Maintenance mode is enabled
|
|
|
|
*/
|
2020-04-09 14:53:40 +03:00
|
|
|
public function maintenanceModeIsEnabled() {
|
2017-04-11 02:30:32 +03:00
|
|
|
$this->runOcc(['maintenance:mode', '--on']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Then Maintenance mode is disabled
|
|
|
|
*/
|
2020-04-09 14:53:40 +03:00
|
|
|
public function maintenanceModeIsDisabled() {
|
2017-04-11 02:30:32 +03:00
|
|
|
$this->runOcc(['maintenance:mode', '--off']);
|
|
|
|
}
|
|
|
|
|
2016-11-08 00:52:07 +03:00
|
|
|
/** @BeforeScenario */
|
|
|
|
public function gatherContexts(BeforeScenarioScope $scope) {
|
|
|
|
$environment = $scope->getEnvironment();
|
|
|
|
// this should really be "WebDavContext" ...
|
|
|
|
$this->featureContext = $environment->getContext('FeatureContext');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function findLastTransferFolderForUser($sourceUser, $targetUser) {
|
|
|
|
$foundPaths = [];
|
|
|
|
$results = $this->featureContext->listFolder($targetUser, '', 1);
|
|
|
|
foreach ($results as $path => $data) {
|
|
|
|
$path = rawurldecode($path);
|
|
|
|
$parts = explode(' ', $path);
|
|
|
|
if (basename($parts[0]) !== 'transferred') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isset($parts[2]) && $parts[2] === $sourceUser) {
|
|
|
|
// store timestamp as key
|
|
|
|
$foundPaths[] = [
|
2016-11-14 14:06:01 +03:00
|
|
|
'date' => strtotime(trim($parts[4], '/')),
|
2016-11-08 00:52:07 +03:00
|
|
|
'path' => $path,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($foundPaths)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-09 14:53:40 +03:00
|
|
|
usort($foundPaths, function ($a, $b) {
|
2016-11-08 00:52:07 +03:00
|
|
|
return $a['date'] - $b['date'];
|
|
|
|
});
|
|
|
|
|
|
|
|
$davPath = rtrim($this->featureContext->getDavFilesPath($targetUser), '/');
|
|
|
|
|
|
|
|
$foundPath = end($foundPaths)['path'];
|
|
|
|
// strip dav path
|
|
|
|
return substr($foundPath, strlen($davPath) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-08 20:36:30 +03:00
|
|
|
* @When /^transferring ownership from "([^"]+)" to "([^"]+)"/
|
2016-11-08 00:52:07 +03:00
|
|
|
*/
|
2020-06-06 16:57:08 +03:00
|
|
|
public function transferringOwnership($user1, $user2) {
|
2016-11-08 00:52:07 +03:00
|
|
|
if ($this->runOcc(['files:transfer-ownership', $user1, $user2]) === 0) {
|
|
|
|
$this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
|
|
|
|
} else {
|
|
|
|
// failure
|
|
|
|
$this->lastTransferPath = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-09 12:54:33 +03:00
|
|
|
/**
|
2017-04-08 20:36:30 +03:00
|
|
|
* @When /^transferring ownership of path "([^"]+)" from "([^"]+)" to "([^"]+)"/
|
2017-03-09 12:54:33 +03:00
|
|
|
*/
|
2020-06-06 16:57:08 +03:00
|
|
|
public function transferringOwnershipPath($path, $user1, $user2) {
|
2017-03-09 12:54:33 +03:00
|
|
|
$path = '--path=' . $path;
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($this->runOcc(['files:transfer-ownership', $path, $user1, $user2]) === 0) {
|
2017-03-09 12:54:33 +03:00
|
|
|
$this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
|
|
|
|
} else {
|
|
|
|
// failure
|
|
|
|
$this->lastTransferPath = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-08 00:52:07 +03:00
|
|
|
/**
|
|
|
|
* @When /^using received transfer folder of "([^"]+)" as dav path$/
|
|
|
|
*/
|
|
|
|
public function usingTransferFolderAsDavPath($user) {
|
|
|
|
$davPath = $this->featureContext->getDavFilesPath($user);
|
|
|
|
$davPath = rtrim($davPath, '/') . $this->lastTransferPath;
|
|
|
|
$this->featureContext->usingDavPath($davPath);
|
|
|
|
}
|
|
|
|
}
|