aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/appinfo/app.php6
-rw-r--r--apps/files_sharing/l10n/he.js19
-rw-r--r--apps/files_sharing/l10n/he.json19
-rw-r--r--apps/files_sharing/lib/API/Share20OCS.php24
-rw-r--r--apps/files_sharing/lib/AppInfo/Application.php3
-rw-r--r--apps/files_sharing/lib/External/Storage.php11
-rw-r--r--apps/files_sharing/lib/External/Watcher.php33
-rw-r--r--apps/files_sharing/lib/Helper.php12
-rw-r--r--apps/files_sharing/lib/MountProvider.php38
-rw-r--r--apps/files_sharing/lib/SharedMount.php2
-rw-r--r--apps/files_sharing/tests/API/Share20OCSTest.php21
-rw-r--r--apps/files_sharing/tests/ApiTest.php41
-rw-r--r--apps/files_sharing/tests/MountProviderTest.php129
13 files changed, 315 insertions, 43 deletions
diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php
index 5740574ec4c..c6ae6903eec 100644
--- a/apps/files_sharing/appinfo/app.php
+++ b/apps/files_sharing/appinfo/app.php
@@ -32,14 +32,14 @@ $l = \OC::$server->getL10N('files_sharing');
\OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'files_sharing/lib/share/folder.php';
\OC::$CLASSPATH['OC\Files\Storage\Shared'] = 'files_sharing/lib/sharedstorage.php';
-$application = new \OCA\Files_Sharing\AppInfo\Application();
-$application->registerMountProviders();
-
\OCA\Files_Sharing\Helper::registerHooks();
\OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
\OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
+$application = new \OCA\Files_Sharing\AppInfo\Application();
+$application->registerMountProviders();
+
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
diff --git a/apps/files_sharing/l10n/he.js b/apps/files_sharing/l10n/he.js
index 32fe49005a1..985e5807e5a 100644
--- a/apps/files_sharing/l10n/he.js
+++ b/apps/files_sharing/l10n/he.js
@@ -27,6 +27,25 @@ OC.L10N.register(
"Invalid ownCloud url" : "נתיב ownCloud לא חוקי",
"Shared by" : "שותף על־ידי",
"Sharing" : "שיתוף",
+ "Share API is disabled" : "שיתוף API מנוטרל",
+ "Wrong share ID, share doesn't exist" : "מספר זיהוי שיתוף שגוי, שיתוף אינו קיים",
+ "Could not delete share" : "לא ניתן היה למחוק את השיתוף",
+ "Please specify a file or folder path" : "יש לספק נתיב לקובץ או תיקייה",
+ "Wrong path, file/folder doesn't exist" : "נתיב שגוי, קובץ/תיקייה אינם קיימים",
+ "Please specify a valid user" : "יש לספק משתמש חוקי",
+ "Group sharing is disabled by the administrator" : "שיתוף קבוצתי מנוטרל על ידי המנהל",
+ "Please specify a valid group" : "יש לספק קבוצה חוקית",
+ "Public link sharing is disabled by the administrator" : "שיתוף ציבורי מנוטרל על ידי המנהל",
+ "Public upload disabled by the administrator" : "שיתוף ציבורי מנוטרל על ידי המנהל",
+ "Public upload is only possible for publicly shared folders" : "העלאה ציבורית אפשרית רק אל תיקיות משותפות ציבוריות",
+ "Invalid date, date format must be YYYY-MM-DD" : "תאריך לא חוקי, תבנית התאריך חייבת להיות YYYY-MM-DD",
+ "Sharing %s failed because the back end does not allow shares from type %s" : "שיתוף %s נכשל כיוון שהצד האחרוי ינו מאפשר שיתוף מסוג %s",
+ "Unknown share type" : "סוג שיתוף אינו מוכר",
+ "Not a directory" : "אינה תיקייה",
+ "Could not lock path" : "לא ניתן היה לנעול נתיב",
+ "Can't change permissions for public share links" : "לא ניתן לשנות הרשאות לקישורי שיתוף ציבוריים",
+ "Wrong or no update parameter given" : "משתנה עדכון שניתן שגוי או לא קיים",
+ "Cannot increase permissions" : "לא ניתן להעלות הרשאות",
"A file or folder has been <strong>shared</strong>" : "קובץ או תיקייה <strong>שותפו<strong/>",
"A file or folder was shared from <strong>another server</strong>" : "קובץ או תיקייה שותפו מ- <strong>שרת אחר</strong>",
"A public shared file or folder was <strong>downloaded</strong>" : "קובץ או תיקייה עם שיתוף ציבורי <strong>הורדו</strong>",
diff --git a/apps/files_sharing/l10n/he.json b/apps/files_sharing/l10n/he.json
index 4aa639d8e50..247c8e2239d 100644
--- a/apps/files_sharing/l10n/he.json
+++ b/apps/files_sharing/l10n/he.json
@@ -25,6 +25,25 @@
"Invalid ownCloud url" : "נתיב ownCloud לא חוקי",
"Shared by" : "שותף על־ידי",
"Sharing" : "שיתוף",
+ "Share API is disabled" : "שיתוף API מנוטרל",
+ "Wrong share ID, share doesn't exist" : "מספר זיהוי שיתוף שגוי, שיתוף אינו קיים",
+ "Could not delete share" : "לא ניתן היה למחוק את השיתוף",
+ "Please specify a file or folder path" : "יש לספק נתיב לקובץ או תיקייה",
+ "Wrong path, file/folder doesn't exist" : "נתיב שגוי, קובץ/תיקייה אינם קיימים",
+ "Please specify a valid user" : "יש לספק משתמש חוקי",
+ "Group sharing is disabled by the administrator" : "שיתוף קבוצתי מנוטרל על ידי המנהל",
+ "Please specify a valid group" : "יש לספק קבוצה חוקית",
+ "Public link sharing is disabled by the administrator" : "שיתוף ציבורי מנוטרל על ידי המנהל",
+ "Public upload disabled by the administrator" : "שיתוף ציבורי מנוטרל על ידי המנהל",
+ "Public upload is only possible for publicly shared folders" : "העלאה ציבורית אפשרית רק אל תיקיות משותפות ציבוריות",
+ "Invalid date, date format must be YYYY-MM-DD" : "תאריך לא חוקי, תבנית התאריך חייבת להיות YYYY-MM-DD",
+ "Sharing %s failed because the back end does not allow shares from type %s" : "שיתוף %s נכשל כיוון שהצד האחרוי ינו מאפשר שיתוף מסוג %s",
+ "Unknown share type" : "סוג שיתוף אינו מוכר",
+ "Not a directory" : "אינה תיקייה",
+ "Could not lock path" : "לא ניתן היה לנעול נתיב",
+ "Can't change permissions for public share links" : "לא ניתן לשנות הרשאות לקישורי שיתוף ציבוריים",
+ "Wrong or no update parameter given" : "משתנה עדכון שניתן שגוי או לא קיים",
+ "Cannot increase permissions" : "לא ניתן להעלות הרשאות",
"A file or folder has been <strong>shared</strong>" : "קובץ או תיקייה <strong>שותפו<strong/>",
"A file or folder was shared from <strong>another server</strong>" : "קובץ או תיקייה שותפו מ- <strong>שרת אחר</strong>",
"A public shared file or folder was <strong>downloaded</strong>" : "קובץ או תיקייה עם שיתוף ציבורי <strong>הורדו</strong>",
diff --git a/apps/files_sharing/lib/API/Share20OCS.php b/apps/files_sharing/lib/API/Share20OCS.php
index 90e1f19130c..53b27aae0b8 100644
--- a/apps/files_sharing/lib/API/Share20OCS.php
+++ b/apps/files_sharing/lib/API/Share20OCS.php
@@ -100,15 +100,8 @@ class Share20OCS {
*/
protected function formatShare(\OCP\Share\IShare $share) {
$sharedBy = $this->userManager->get($share->getSharedBy());
- // for federated shares the owner can be a remote user, in this
- // case we use the initiator
- if ($this->userManager->userExists($share->getShareOwner())) {
- $shareOwner = $this->userManager->get($share->getShareOwner());
- $localUser = $share->getShareOwner();
- } else {
- $shareOwner = $this->userManager->get($share->getSharedBy());
- $localUser = $share->getSharedBy();
- }
+ $shareOwner = $this->userManager->get($share->getShareOwner());
+
$result = [
'id' => $share->getId(),
'share_type' => $share->getShareType(),
@@ -123,8 +116,16 @@ class Share20OCS {
'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
];
- $node = $share->getNode();
- $result['path'] = $this->rootFolder->getUserFolder($localUser)->getRelativePath($node->getPath());
+ $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID());
+ $nodes = $userFolder->getById($share->getNodeId());
+
+ if (empty($nodes)) {
+ throw new NotFoundException();
+ }
+
+ $node = $nodes[0];
+
+ $result['path'] = $userFolder->getRelativePath($node->getPath());
if ($node instanceOf \OCP\Files\Folder) {
$result['item_type'] = 'folder';
} else {
@@ -536,7 +537,6 @@ class Share20OCS {
$shares = array_merge($shares, $federatedShares);
}
-
$formatted = [];
foreach ($shares as $share) {
try {
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php
index 2907ceaaea2..fda16c7acac 100644
--- a/apps/files_sharing/lib/AppInfo/Application.php
+++ b/apps/files_sharing/lib/AppInfo/Application.php
@@ -115,7 +115,8 @@ class Application extends App {
$server = $c->query('ServerContainer');
return new MountProvider(
$server->getConfig(),
- $server->getShareManager()
+ $server->getShareManager(),
+ $server->getLogger()
);
});
diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php
index a12b9597dbd..ca99393a1e0 100644
--- a/apps/files_sharing/lib/External/Storage.php
+++ b/apps/files_sharing/lib/External/Storage.php
@@ -89,8 +89,17 @@ class Storage extends DAV implements ISharedStorage {
'user' => $options['token'],
'password' => (string)$options['password']
));
+ }
- $this->getWatcher()->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
+ public function getWatcher($path = '', $storage = null) {
+ if (!$storage) {
+ $storage = $this;
+ }
+ if (!isset($this->watcher)) {
+ $this->watcher = new Watcher($storage);
+ $this->watcher->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
+ }
+ return $this->watcher;
}
public function getRemoteUser() {
diff --git a/apps/files_sharing/lib/External/Watcher.php b/apps/files_sharing/lib/External/Watcher.php
new file mode 100644
index 00000000000..6be35bdeb3b
--- /dev/null
+++ b/apps/files_sharing/lib/External/Watcher.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_Sharing\External;
+
+class Watcher extends \OC\Files\Cache\Watcher {
+ /**
+ * remove deleted files in $path from the cache
+ *
+ * @param string $path
+ */
+ public function cleanFolder($path) {
+ // not needed, the scanner takes care of this
+ }
+}
diff --git a/apps/files_sharing/lib/Helper.php b/apps/files_sharing/lib/Helper.php
index e4640f82eb6..2353a281b7e 100644
--- a/apps/files_sharing/lib/Helper.php
+++ b/apps/files_sharing/lib/Helper.php
@@ -277,19 +277,23 @@ class Helper {
/**
* get default share folder
*
+ * @param \OC\Files\View
* @return string
*/
- public static function getShareFolder() {
+ public static function getShareFolder($view = null) {
+ if ($view === null) {
+ $view = Filesystem::getView();
+ }
$shareFolder = \OC::$server->getConfig()->getSystemValue('share_folder', '/');
$shareFolder = Filesystem::normalizePath($shareFolder);
- if (!Filesystem::file_exists($shareFolder)) {
+ if (!$view->file_exists($shareFolder)) {
$dir = '';
$subdirs = explode('/', $shareFolder);
foreach ($subdirs as $subdir) {
$dir = $dir . '/' . $subdir;
- if (!Filesystem::is_dir($dir)) {
- Filesystem::mkdir($dir);
+ if (!$view->is_dir($dir)) {
+ $view->mkdir($dir);
}
}
}
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php
index d8f355f2fd3..c71c0e8ddea 100644
--- a/apps/files_sharing/lib/MountProvider.php
+++ b/apps/files_sharing/lib/MountProvider.php
@@ -26,6 +26,7 @@ namespace OCA\Files_Sharing;
use OCP\Files\Config\IMountProvider;
use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig;
+use OCP\ILogger;
use OCP\IUser;
use OCP\Share\IManager;
@@ -41,12 +42,19 @@ class MountProvider implements IMountProvider {
protected $shareManager;
/**
+ * @var ILogger
+ */
+ protected $logger;
+
+ /**
* @param \OCP\IConfig $config
* @param IManager $shareManager
+ * @param ILogger $logger
*/
- public function __construct(IConfig $config, IManager $shareManager) {
+ public function __construct(IConfig $config, IManager $shareManager, ILogger $logger) {
$this->config = $config;
$this->shareManager = $shareManager;
+ $this->logger = $logger;
}
@@ -60,22 +68,28 @@ class MountProvider implements IMountProvider {
public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
$shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1);
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1));
- $shares = array_filter($shares, function (\OCP\Share\IShare $share) {
- return $share->getPermissions() > 0;
+ // filter out excluded shares and group shares that includes self
+ $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) {
+ return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID();
});
$mounts = [];
foreach ($shares as $share) {
- $mounts[] = new SharedMount(
- '\OC\Files\Storage\Shared',
- $mounts,
- [
- 'user' => $user->getUID(),
- 'newShare' => $share,
- ],
- $storageFactory
- );
+ try {
+ $mounts[] = new SharedMount(
+ '\OC\Files\Storage\Shared',
+ $mounts,
+ [
+ 'user' => $user->getUID(),
+ 'newShare' => $share,
+ ],
+ $storageFactory
+ );
+ } catch (\Exception $e) {
+ $this->logger->logException($e);
+ $this->logger->error('Error while trying to create shared mount');
+ }
}
// array_filter removes the null values from the array
diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php
index 83527053f43..2b066bd2d94 100644
--- a/apps/files_sharing/lib/SharedMount.php
+++ b/apps/files_sharing/lib/SharedMount.php
@@ -81,7 +81,7 @@ class SharedMount extends MountPoint implements MoveableMount {
$parent = dirname($share->getTarget());
if (!$this->recipientView->is_dir($parent)) {
- $parent = Helper::getShareFolder();
+ $parent = Helper::getShareFolder($this->recipientView);
}
$newMountPoint = $this->generateUniqueTarget(
diff --git a/apps/files_sharing/tests/API/Share20OCSTest.php b/apps/files_sharing/tests/API/Share20OCSTest.php
index 02b16d7bf88..b760a0f47a0 100644
--- a/apps/files_sharing/tests/API/Share20OCSTest.php
+++ b/apps/files_sharing/tests/API/Share20OCSTest.php
@@ -433,8 +433,12 @@ class Share20OCSTest extends \Test\TestCase {
->method('getRelativePath')
->will($this->returnArgument(0));
+ $userFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$share->getNode()]);
+
$this->rootFolder->method('getUserFolder')
- ->with($share->getShareOwner())
+ ->with($this->currentUser->getUID())
->willReturn($userFolder);
$this->urlGenerator
@@ -2006,8 +2010,19 @@ class Share20OCSTest extends \Test\TestCase {
->willReturn('myLink');
- $this->rootFolder->method('getUserFolder')->with($share->getShareOwner())->will($this->returnSelf());
- $this->rootFolder->method('getRelativePath')->will($this->returnArgument(0));
+ $this->rootFolder->method('getUserFolder')
+ ->with($this->currentUser->getUID())
+ ->will($this->returnSelf());
+
+ if (!$exception) {
+ $this->rootFolder->method('getById')
+ ->with($share->getNodeId())
+ ->willReturn([$share->getNode()]);
+
+ $this->rootFolder->method('getRelativePath')
+ ->with($share->getNode()->getPath())
+ ->will($this->returnArgument(0));
+ }
try {
$result = $this->invokePrivate($this->ocs, 'formatShare', [$share]);
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index f44c346236e..058b0c4758c 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -764,8 +764,7 @@ class ApiTest extends TestCase {
// we should get exactly one result
$this->assertCount(1, $data);
- $expectedPath = $this->folder . $this->subfolder;
- $this->assertEquals($expectedPath, $data[0]['path']);
+ $this->assertEquals($this->subfolder, $data[0]['path']);
$this->shareManager->deleteShare($share2);
$this->shareManager->deleteShare($share1);
@@ -801,6 +800,9 @@ class ApiTest extends TestCase {
->setPermissions(1);
$share3 = $this->shareManager->createShare($share3);
+ /*
+ * Test as recipient
+ */
$request = $this->createRequest(['path' => '/', 'subfiles' => 'true']);
$ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER3);
$result = $ocs->getShares();
@@ -811,9 +813,37 @@ class ApiTest extends TestCase {
// we should get exactly one result
$this->assertCount(1, $data);
+ $this->assertEquals($this->subsubfolder, $data[0]['path']);
- $expectedPath = $this->folder . $this->subfolder . $this->subsubfolder;
- $this->assertEquals($expectedPath, $data[0]['path']);
+ /*
+ * Test for first owner/initiator
+ */
+ $request = $this->createRequest([]);
+ $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER1);
+ $result = $ocs->getShares();
+ $this->assertTrue($result->succeeded());
+
+ // test should return one share within $this->folder
+ $data = $result->getData();
+
+ // we should get exactly one result
+ $this->assertCount(1, $data);
+ $this->assertEquals($this->folder . $this->subfolder, $data[0]['path']);
+
+ /*
+ * Test for second initiator
+ */
+ $request = $this->createRequest([]);
+ $ocs = $this->createOCS($request, self::TEST_FILES_SHARING_API_USER2);
+ $result = $ocs->getShares();
+ $this->assertTrue($result->succeeded());
+
+ // test should return one share within $this->folder
+ $data = $result->getData();
+
+ // we should get exactly one result
+ $this->assertCount(1, $data);
+ $this->assertEquals($this->subfolder . $this->subsubfolder, $data[0]['path']);
$this->shareManager->deleteShare($share1);
$this->shareManager->deleteShare($share2);
@@ -922,8 +952,7 @@ class ApiTest extends TestCase {
// we should get exactly one result
$this->assertCount(1, $data);
- $expectedPath = $this->folder.$this->subfolder.$this->filename;
- $this->assertEquals($expectedPath, $data[0]['path']);
+ $this->assertEquals($this->filename, $data[0]['path']);
$this->shareManager->deleteShare($share1);
$this->shareManager->deleteShare($share2);
diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php
new file mode 100644
index 00000000000..993d3654891
--- /dev/null
+++ b/apps/files_sharing/tests/MountProviderTest.php
@@ -0,0 +1,129 @@
+<?php
+/**
+ * @author Vincent Petry <pvince81@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @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,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_Sharing\Tests;
+
+use OCA\Files_Sharing\MountProvider;
+use OCP\Files\Storage\IStorageFactory;
+use OCP\IConfig;
+use OCP\IUser;
+use OCP\Share\IShare;
+use OCP\Share\IManager;
+use OCP\Files\Mount\IMountPoint;
+
+class MountProviderTest extends \Test\TestCase {
+
+ /** @var MountProvider */
+ private $provider;
+
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ private $config;
+
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject */
+ private $user;
+
+ /** @var IStorageFactory|\PHPUnit_Framework_MockObject_MockObject */
+ private $loader;
+
+ /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $shareManager;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->config = $this->getMock('OCP\IConfig');
+ $this->user = $this->getMock('OCP\IUser');
+ $this->loader = $this->getMock('OCP\Files\Storage\IStorageFactory');
+ $this->shareManager = $this->getMock('\OCP\Share\IManager');
+
+ $this->provider = new MountProvider($this->config, $this->shareManager);
+ }
+
+ public function testExcludeShares() {
+ $share1 = $this->getMock('\OCP\Share\IShare');
+ $share1->expects($this->once())
+ ->method('getPermissions')
+ ->will($this->returnValue(0));
+
+ $share2 = $this->getMock('\OCP\Share\IShare');
+ $share2->expects($this->once())
+ ->method('getPermissions')
+ ->will($this->returnValue(31));
+ $share2->expects($this->any())
+ ->method('getShareOwner')
+ ->will($this->returnValue('user2'));
+ $share2->expects($this->any())
+ ->method('getTarget')
+ ->will($this->returnValue('/share2'));
+
+ $share3 = $this->getMock('\OCP\Share\IShare');
+ $share3->expects($this->once())
+ ->method('getPermissions')
+ ->will($this->returnValue(0));
+
+ $share4 = $this->getMock('\OCP\Share\IShare');
+ $share4->expects($this->once())
+ ->method('getPermissions')
+ ->will($this->returnValue(31));
+ $share4->expects($this->any())
+ ->method('getShareOwner')
+ ->will($this->returnValue('user2'));
+ $share4->expects($this->any())
+ ->method('getTarget')
+ ->will($this->returnValue('/share4'));
+
+ $share5 = $this->getMock('\OCP\Share\IShare');
+ $share5->expects($this->once())
+ ->method('getPermissions')
+ ->will($this->returnValue(31));
+ $share5->expects($this->any())
+ ->method('getShareOwner')
+ ->will($this->returnValue('user1'));
+
+ $userShares = [$share1, $share2];
+ $groupShares = [$share3, $share4, $share5];
+
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue('user1'));
+
+ $this->shareManager->expects($this->at(0))
+ ->method('getSharedWith')
+ ->with('user1', \OCP\Share::SHARE_TYPE_USER)
+ ->will($this->returnValue($userShares));
+ $this->shareManager->expects($this->at(1))
+ ->method('getSharedWith')
+ ->with('user1', \OCP\Share::SHARE_TYPE_GROUP, null, -1)
+ ->will($this->returnValue($groupShares));
+
+ $mounts = $this->provider->getMountsForUser($this->user, $this->loader);
+
+ $this->assertCount(2, $mounts);
+ $this->assertSharedMount($share1, $mounts[0]);
+ $this->assertSharedMount($share4, $mounts[1]);
+ }
+
+ private function assertSharedMount(IShare $share, IMountPoint $mount) {
+ $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mount);
+ $this->assertEquals($share, $mount->getShare());
+ }
+}
+