2016-11-07 16:52:07 -05:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2016-11-07 16:52:07 -05:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-11-07 16:52:07 -05:00
|
|
|
*/
|
|
|
|
|
require __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
|
|
2024-10-08 17:51:38 -04:00
|
|
|
use Behat\Behat\Context\Exception\ContextNotFoundException;
|
2016-11-07 16:52:07 -05:00
|
|
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
|
2020-09-18 12:32:59 -04:00
|
|
|
use PHPUnit\Framework\Assert;
|
2016-11-07 16:52:07 -05:00
|
|
|
|
|
|
|
|
class CommandLineContext implements \Behat\Behat\Context\Context {
|
|
|
|
|
use CommandLine;
|
|
|
|
|
|
|
|
|
|
private $lastTransferPath;
|
|
|
|
|
|
|
|
|
|
private $featureContext;
|
2023-10-27 02:08:24 -04:00
|
|
|
private $localBaseUrl;
|
|
|
|
|
private $remoteBaseUrl;
|
2016-11-07 16:52:07 -05:00
|
|
|
|
|
|
|
|
public function __construct($ocPath, $baseUrl) {
|
|
|
|
|
$this->ocPath = rtrim($ocPath, '/') . '/';
|
|
|
|
|
$this->localBaseUrl = $baseUrl;
|
|
|
|
|
$this->remoteBaseUrl = $baseUrl;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 19:30:32 -04:00
|
|
|
/**
|
|
|
|
|
* @Given Maintenance mode is enabled
|
|
|
|
|
*/
|
2020-04-09 07:53:40 -04:00
|
|
|
public function maintenanceModeIsEnabled() {
|
2017-04-10 19:30:32 -04:00
|
|
|
$this->runOcc(['maintenance:mode', '--on']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Then Maintenance mode is disabled
|
|
|
|
|
*/
|
2020-04-09 07:53:40 -04:00
|
|
|
public function maintenanceModeIsDisabled() {
|
2017-04-10 19:30:32 -04:00
|
|
|
$this->runOcc(['maintenance:mode', '--off']);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 16:52:07 -05:00
|
|
|
/** @BeforeScenario */
|
|
|
|
|
public function gatherContexts(BeforeScenarioScope $scope) {
|
|
|
|
|
$environment = $scope->getEnvironment();
|
2024-10-08 17:51:38 -04:00
|
|
|
// this should really be "WebDavContext"
|
|
|
|
|
try {
|
|
|
|
|
$this->featureContext = $environment->getContext('FeatureContext');
|
|
|
|
|
} catch (ContextNotFoundException) {
|
|
|
|
|
$this->featureContext = $environment->getContext('DavFeatureContext');
|
|
|
|
|
}
|
2016-11-07 16:52:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function findLastTransferFolderForUser($sourceUser, $targetUser) {
|
|
|
|
|
$foundPaths = [];
|
|
|
|
|
$results = $this->featureContext->listFolder($targetUser, '', 1);
|
|
|
|
|
foreach ($results as $path => $data) {
|
|
|
|
|
$path = rawurldecode($path);
|
|
|
|
|
$parts = explode(' ', $path);
|
2024-04-17 17:50:18 -04:00
|
|
|
if (basename($parts[0]) !== 'Transferred') {
|
2016-11-07 16:52:07 -05:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (isset($parts[2]) && $parts[2] === $sourceUser) {
|
|
|
|
|
// store timestamp as key
|
|
|
|
|
$foundPaths[] = [
|
2016-11-14 06:06:01 -05:00
|
|
|
'date' => strtotime(trim($parts[4], '/')),
|
2016-11-07 16:52:07 -05:00
|
|
|
'path' => $path,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($foundPaths)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 07:53:40 -04:00
|
|
|
usort($foundPaths, function ($a, $b) {
|
2016-11-07 16:52:07 -05: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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-08-27 11:56:16 -04:00
|
|
|
* @When /^transferring ownership from "([^"]+)" to "([^"]+)"$/
|
2016-11-07 16:52:07 -05:00
|
|
|
*/
|
2020-06-06 09:57:08 -04:00
|
|
|
public function transferringOwnership($user1, $user2) {
|
2016-11-07 16:52:07 -05:00
|
|
|
if ($this->runOcc(['files:transfer-ownership', $user1, $user2]) === 0) {
|
|
|
|
|
$this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
|
|
|
|
|
} else {
|
|
|
|
|
// failure
|
|
|
|
|
$this->lastTransferPath = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-09 04:54:33 -05:00
|
|
|
/**
|
2021-08-27 11:56:16 -04:00
|
|
|
* @When /^transferring ownership of path "([^"]+)" from "([^"]+)" to "([^"]+)"$/
|
2017-03-09 04:54:33 -05:00
|
|
|
*/
|
2020-06-06 09:57:08 -04:00
|
|
|
public function transferringOwnershipPath($path, $user1, $user2) {
|
2017-03-09 04:54:33 -05:00
|
|
|
$path = '--path=' . $path;
|
2020-04-10 08:19:56 -04:00
|
|
|
if ($this->runOcc(['files:transfer-ownership', $path, $user1, $user2]) === 0) {
|
2017-03-09 04:54:33 -05:00
|
|
|
$this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
|
|
|
|
|
} else {
|
|
|
|
|
// failure
|
|
|
|
|
$this->lastTransferPath = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 16:52:07 -05: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);
|
|
|
|
|
}
|
2020-09-18 12:32:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Then /^transfer folder name contains "([^"]+)"$/
|
|
|
|
|
*/
|
|
|
|
|
public function transferFolderNameContains($text) {
|
2022-03-30 10:13:16 -04:00
|
|
|
Assert::assertStringContainsString($text, $this->lastTransferPath);
|
2020-09-18 12:32:59 -04:00
|
|
|
}
|
2016-11-07 16:52:07 -05:00
|
|
|
}
|