blob: 0437157e84ff71390f26570c1c2d20c1e6ca4824 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<?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][] = ['storage' => $storage, 'mountPoint' => $mountPoint, 'arguments' => $arguments];
}
protected function registerStorageWrapper($name, $wrapper) {
$this->storageFactory->addStorageWrapper($name, $wrapper);
}
protected function setUpMountProviderTrait() {
$this->storageFactory = new StorageFactory();
$this->mountProvider = $this->getMockBuilder('\OCP\Files\Config\IMountProvider')->getMock();
$this->mountProvider->expects($this->any())
->method('getMountsForUser')
->will($this->returnCallback(function (IUser $user) {
if (isset($this->mounts[$user->getUID()])) {
return array_map(function ($config) {
return new MountPoint($config['storage'], $config['mountPoint'], $config['arguments'], $this->storageFactory);
}, $this->mounts[$user->getUID()]);
} else {
return [];
}
}));
\OC::$server->getMountProviderCollection()->registerProvider($this->mountProvider);
}
}
|