summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2015-08-20 14:52:22 +0200
committerRobin Appelman <icewind@owncloud.com>2015-08-20 16:39:32 +0200
commit24a2fff946a36d45cb3bd04263d173ab0d81792b (patch)
tree9d8c167dfaa0d7c4d593a23ad0b90dbf2c90948d /tests
parent3dbfbdaf549f69c63c6e59d91681c7df65789ece (diff)
downloadnextcloud-server-24a2fff946a36d45cb3bd04263d173ab0d81792b.tar.gz
nextcloud-server-24a2fff946a36d45cb3bd04263d173ab0d81792b.zip
add test mountprovider logic to a trait
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/connector/sabre/requesttest/requesttest.php35
-rw-r--r--tests/lib/traits/mountprovidertrait.php56
2 files changed, 60 insertions, 31 deletions
diff --git a/tests/lib/connector/sabre/requesttest/requesttest.php b/tests/lib/connector/sabre/requesttest/requesttest.php
index 7b192824412..7f33dcf817b 100644
--- a/tests/lib/connector/sabre/requesttest/requesttest.php
+++ b/tests/lib/connector/sabre/requesttest/requesttest.php
@@ -11,20 +11,18 @@ namespace Test\Connector\Sabre\RequestTest;
use OC\Connector\Sabre\Server;
use OC\Connector\Sabre\ServerFactory;
use OC\Files\Mount\MountPoint;
+use OC\Files\Storage\StorageFactory;
use OC\Files\Storage\Temporary;
use OC\Files\View;
use OCP\IUser;
use Sabre\HTTP\Request;
use Test\TestCase;
+use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait;
abstract class RequestTest extends TestCase {
use UserTrait;
-
- /**
- * @var \OCP\Files\Config\IMountProvider[]
- */
- protected $mountProviders;
+ use MountProviderTrait;
/**
* @var \OC\Connector\Sabre\ServerFactory
@@ -38,29 +36,6 @@ abstract class RequestTest extends TestCase {
return $stream;
}
- /**
- * @param $userId
- * @param $storages
- * @return \OCP\Files\Config\IMountProvider
- */
- protected function getMountProvider($userId, $storages) {
- $mounts = [];
- foreach ($storages as $mountPoint => $storage) {
- $mounts[] = new MountPoint($storage, $mountPoint);
- }
- $provider = $this->getMock('\OCP\Files\Config\IMountProvider');
- $provider->expects($this->any())
- ->method('getMountsForUser')
- ->will($this->returnCallback(function (IUser $user) use ($userId, $mounts) {
- if ($user->getUID() === $userId) {
- return $mounts;
- } else {
- return [];
- }
- }));
- return $provider;
- }
-
protected function setUp() {
parent::setUp();
@@ -76,9 +51,7 @@ abstract class RequestTest extends TestCase {
protected function setupUser($name, $password) {
$this->createUser($name, $password);
- \OC::$server->getMountProviderCollection()->registerProvider($this->getMountProvider($name, [
- '/' . $name => '\OC\Files\Storage\Temporary'
- ]));
+ $this->registerMount($name, '\OC\Files\Storage\Temporary', '/' . $name);
$this->loginAsUser($name);
return new View('/' . $name . '/files');
}
diff --git a/tests/lib/traits/mountprovidertrait.php b/tests/lib/traits/mountprovidertrait.php
new file mode 100644
index 00000000000..66eca1597c8
--- /dev/null
+++ b/tests/lib/traits/mountprovidertrait.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Traits;
+
+use OC\Files\Mount\MountPoint;
+use OC\Files\Storage\StorageFactory;
+use OCP\IUser;
+
+/**
+ * Allow setting mounts for users
+ */
+trait MountProviderTrait {
+ /**
+ * @var \OCP\Files\Config\IMountProvider
+ */
+ protected $mountProvider;
+
+ /**
+ * @var \OC\Files\Storage\StorageFactory
+ */
+ protected $storageFactory;
+
+ protected $mounts = [];
+
+ protected function registerMount($userId, $storage, $mountPoint, $arguments = null) {
+ if (!isset($this->mounts[$userId])) {
+ $this->mounts[$userId] = [];
+ }
+ $this->mounts[$userId][] = new MountPoint($storage, $mountPoint, $arguments, $this->storageFactory);
+ }
+
+ protected function registerStorageWrapper($name, $wrapper) {
+ $this->storageFactory->addStorageWrapper($name, $wrapper);
+ }
+
+ protected function setUpMountProviderTrait() {
+ $this->storageFactory = new StorageFactory();
+ $this->mountProvider = $this->getMock('\OCP\Files\Config\IMountProvider');
+ $this->mountProvider->expects($this->any())
+ ->method('getMountsForUser')
+ ->will($this->returnCallback(function (IUser $user) {
+ if (isset($this->mounts[$user->getUID()])) {
+ return $this->mounts[$user->getUID()];
+ } else {
+ return [];
+ }
+ }));
+ \OC::$server->getMountProviderCollection()->registerProvider($this->mountProvider);
+ }
+}