You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandLineContext.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @author Vincent Petry <pvince81@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. require __DIR__ . '/../../vendor/autoload.php';
  22. use Behat\Behat\Hook\Scope\BeforeScenarioScope;
  23. class CommandLineContext implements \Behat\Behat\Context\Context {
  24. use CommandLine;
  25. private $lastTransferPath;
  26. private $featureContext;
  27. public function __construct($ocPath, $baseUrl) {
  28. $this->ocPath = rtrim($ocPath, '/') . '/';
  29. $this->localBaseUrl = $baseUrl;
  30. $this->remoteBaseUrl = $baseUrl;
  31. }
  32. /** @BeforeScenario */
  33. public function gatherContexts(BeforeScenarioScope $scope) {
  34. $environment = $scope->getEnvironment();
  35. // this should really be "WebDavContext" ...
  36. $this->featureContext = $environment->getContext('FeatureContext');
  37. }
  38. private function findLastTransferFolderForUser($sourceUser, $targetUser) {
  39. $foundPaths = [];
  40. $results = $this->featureContext->listFolder($targetUser, '', 1);
  41. foreach ($results as $path => $data) {
  42. $path = rawurldecode($path);
  43. $parts = explode(' ', $path);
  44. if (basename($parts[0]) !== 'transferred') {
  45. continue;
  46. }
  47. if (isset($parts[2]) && $parts[2] === $sourceUser) {
  48. // store timestamp as key
  49. $foundPaths[] = [
  50. 'date' => strtotime(trim($parts[4], '/')),
  51. 'path' => $path,
  52. ];
  53. }
  54. }
  55. if (empty($foundPaths)) {
  56. return null;
  57. }
  58. usort($foundPaths, function($a, $b) {
  59. return $a['date'] - $b['date'];
  60. });
  61. $davPath = rtrim($this->featureContext->getDavFilesPath($targetUser), '/');
  62. $foundPath = end($foundPaths)['path'];
  63. // strip dav path
  64. return substr($foundPath, strlen($davPath) + 1);
  65. }
  66. /**
  67. * @When /^transfering ownership from "([^"]+)" to "([^"]+)"/
  68. */
  69. public function transferingOwnership($user1, $user2) {
  70. if ($this->runOcc(['files:transfer-ownership', $user1, $user2]) === 0) {
  71. $this->lastTransferPath = $this->findLastTransferFolderForUser($user1, $user2);
  72. } else {
  73. // failure
  74. $this->lastTransferPath = null;
  75. }
  76. }
  77. /**
  78. * @When /^using received transfer folder of "([^"]+)" as dav path$/
  79. */
  80. public function usingTransferFolderAsDavPath($user) {
  81. $davPath = $this->featureContext->getDavFilesPath($user);
  82. $davPath = rtrim($davPath, '/') . $this->lastTransferPath;
  83. $this->featureContext->usingDavPath($davPath);
  84. }
  85. }