Fix tests
This commit is contained in:
parent
afa37d363f
commit
92abb5f23d
|
@ -40,9 +40,6 @@ class Test_Files_Sharing_Api extends TestCase {
|
|||
|
||||
private static $tempStorage;
|
||||
|
||||
/** @var \OCP\Share\IManager */
|
||||
private $shareManager;
|
||||
|
||||
/** @var \OCP\Files\Folder */
|
||||
private $userFolder;
|
||||
|
||||
|
@ -66,7 +63,6 @@ class Test_Files_Sharing_Api extends TestCase {
|
|||
$this->view->file_put_contents($this->folder.$this->filename, $this->data);
|
||||
$this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data);
|
||||
|
||||
$this->shareManager = \OC::$server->getShareManager();
|
||||
$this->userFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
|
||||
}
|
||||
|
||||
|
@ -1195,10 +1191,13 @@ class Test_Files_Sharing_Api extends TestCase {
|
|||
|
||||
$fileInfo = $this->view->getFileInfo($this->folder);
|
||||
|
||||
$result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
// user2 shares a file from the folder as link
|
||||
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
|
||||
|
@ -1215,14 +1214,20 @@ class Test_Files_Sharing_Api extends TestCase {
|
|||
|
||||
$this->assertTrue($fileInfo2 instanceof \OC\Files\FileInfo);
|
||||
|
||||
$pass = true;
|
||||
try {
|
||||
$result2 = \OCP\Share::shareItem('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER3, 31);
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
'localDir',
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
self::TEST_FILES_SHARING_API_USER3,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$result2 = false;
|
||||
$pass = false;
|
||||
}
|
||||
|
||||
$this->assertFalse($result2);
|
||||
$this->assertFalse($pass);
|
||||
|
||||
//cleanup
|
||||
|
||||
|
@ -1232,8 +1237,7 @@ class Test_Files_Sharing_Api extends TestCase {
|
|||
|
||||
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
\OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1264,10 +1268,13 @@ class Test_Files_Sharing_Api extends TestCase {
|
|||
$fileInfo = $this->view->getFileInfo($this->folder);
|
||||
|
||||
// user 1 shares the mount point folder with user2
|
||||
$result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
// user2: check that mount point name appears correctly
|
||||
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
|
||||
|
@ -1279,8 +1286,7 @@ class Test_Files_Sharing_Api extends TestCase {
|
|||
|
||||
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
\OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
|
||||
$this->shareManager->deleteShare($share);
|
||||
|
||||
\OC_Hook::clear('OC_Filesystem', 'post_initMountPoints', '\Test_Files_Sharing_Api', 'initTestMountPointsHook');
|
||||
}
|
||||
|
|
|
@ -26,27 +26,6 @@
|
|||
*/
|
||||
use OCA\Files_sharing\Tests\TestCase;
|
||||
|
||||
/**
|
||||
* ownCloud
|
||||
*
|
||||
* @author Vincent Petry, Bjoern Schiessle
|
||||
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
|
||||
* 2014 Bjoern Schiessle <schiessle@owncloud.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class Test_Files_Sharing_Cache
|
||||
|
@ -72,9 +51,14 @@ class Test_Files_Sharing_Cache extends TestCase {
|
|||
/** @var \OC\Files\Storage\Storage */
|
||||
protected $sharedStorage;
|
||||
|
||||
/** @var \OCP\Share\IManager */
|
||||
protected $shareManager;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->shareManager = \OC::$server->getShareManager();
|
||||
|
||||
\OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER1, 'User One');
|
||||
\OC_User::setDisplayName(self::TEST_FILES_SHARING_API_USER2, 'User Two');
|
||||
|
||||
|
@ -101,13 +85,25 @@ class Test_Files_Sharing_Cache extends TestCase {
|
|||
$this->ownerStorage->getScanner()->scan('');
|
||||
|
||||
// share "shareddir" with user2
|
||||
$fileinfo = $this->view->getFileInfo('container/shareddir');
|
||||
\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
$fileinfo = $this->view->getFileInfo('container/shared single file.txt');
|
||||
\OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$node = $rootFolder->get('container/shareddir');
|
||||
$share = $this->shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$this->shareManager->createShare($share);
|
||||
|
||||
$node = $rootFolder->get('container/shared single file.txt');
|
||||
$share = $this->shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE));
|
||||
$this->shareManager->createShare($share);
|
||||
|
||||
// login as user2
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
@ -125,13 +121,10 @@ class Test_Files_Sharing_Cache extends TestCase {
|
|||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
$fileinfo = $this->view->getFileInfo('container/shareddir');
|
||||
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
$fileinfo = $this->view->getFileInfo('container/shared single file.txt');
|
||||
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER);
|
||||
foreach ($shares as $share) {
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
$this->view->deleteAll('container');
|
||||
|
||||
|
@ -392,9 +385,15 @@ class Test_Files_Sharing_Cache extends TestCase {
|
|||
function testGetFolderContentsWhenSubSubdirShared() {
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
$fileinfo = $this->view->getFileInfo('container/shareddir/subdir');
|
||||
\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER3, 31);
|
||||
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
|
||||
$node = $rootFolder->get('container/shareddir/subdir');
|
||||
$share = $this->shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$share = $this->shareManager->createShare($share);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
||||
|
||||
|
@ -430,8 +429,7 @@ class Test_Files_Sharing_Cache extends TestCase {
|
|||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER3);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -470,7 +468,17 @@ class Test_Files_Sharing_Cache extends TestCase {
|
|||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
\OC\Files\Filesystem::file_put_contents('test.txt', 'foo');
|
||||
$info = \OC\Files\Filesystem::getFileInfo('test.txt');
|
||||
\OCP\Share::shareItem('file', $info->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
|
||||
|
||||
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
|
||||
$node = $rootFolder->get('test.txt');
|
||||
$share = $this->shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
|
||||
$this->shareManager->createShare($share);
|
||||
|
||||
\OC_Util::tearDownFS();
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
@ -491,7 +499,16 @@ class Test_Files_Sharing_Cache extends TestCase {
|
|||
\OC\Files\Filesystem::touch('foo/bar/test.txt');
|
||||
$folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
|
||||
$fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
|
||||
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
|
||||
|
||||
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
|
||||
$node = $rootFolder->get('foo');
|
||||
$share = $this->shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$this->shareManager->createShare($share);
|
||||
\OC_Util::tearDownFS();
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
|
|
@ -50,13 +50,15 @@ class EtagPropagation extends PropagationTestCase {
|
|||
$this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
|
||||
|
||||
$rootFolder = \OC::$server->getRootFolder();
|
||||
$shareManager = \OC::$server->getShareManager();
|
||||
|
||||
$this->rootView = new View('');
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
||||
$view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
|
||||
$view1->mkdir('/sub1/sub2/folder/inside');
|
||||
$view1->mkdir('/directReshare');
|
||||
$view1->mkdir('/sub1/sub2/folder/other');
|
||||
$view1->mkdir('/sub1/sub2/folder/other');
|
||||
$view1->file_put_contents('/foo.txt', 'foobar');
|
||||
$view1->file_put_contents('/sub1/sub2/folder/file.txt', 'foobar');
|
||||
$view1->file_put_contents('/sub1/sub2/folder/inside/file.txt', 'foobar');
|
||||
|
@ -64,30 +66,90 @@ class EtagPropagation extends PropagationTestCase {
|
|||
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
||||
$fileInfo = $view1->getFileInfo('/foo.txt');
|
||||
$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);
|
||||
\OCP\Share::shareItem('file', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31);
|
||||
|
||||
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
|
||||
->get('/foo.txt');
|
||||
$share = $shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
|
||||
$shareManager->createShare($share);
|
||||
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
|
||||
->get('/sub1/sub2/folder');
|
||||
$share = $shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$shareManager->createShare($share);
|
||||
$share = $shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$shareManager->createShare($share);
|
||||
|
||||
$folderInfo = $view1->getFileInfo('/directReshare');
|
||||
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
||||
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
|
||||
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
|
||||
->get('/directReshare');
|
||||
$share = $shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$shareManager->createShare($share);
|
||||
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1/sub2'] = $view1->getFileInfo('sub1/sub2')->getId();
|
||||
|
||||
/*
|
||||
* User 2
|
||||
*/
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
||||
$view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
$view2->mkdir('/sub1/sub2');
|
||||
$view2->rename('/folder', '/sub1/sub2/folder');
|
||||
$insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
|
||||
$this->assertInstanceOf('\OC\Files\FileInfo', $insideInfo);
|
||||
\OCP\Share::shareItem('folder', $insideInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
|
||||
|
||||
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)
|
||||
->get('/sub1/sub2/folder/inside');
|
||||
$share = $shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER4)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$shareManager->createShare($share);
|
||||
|
||||
$folderInfo = $view2->getFileInfo('/directReshare');
|
||||
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
||||
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31);
|
||||
|
||||
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)
|
||||
->get('/directReshare');
|
||||
$share = $shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER4)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$shareManager->createShare($share);
|
||||
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1/sub2'] = $view2->getFileInfo('sub1/sub2')->getId();
|
||||
|
||||
/*
|
||||
* User 3
|
||||
*/
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
|
||||
$view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
|
||||
$view3->mkdir('/sub1/sub2');
|
||||
|
@ -96,6 +158,9 @@ class EtagPropagation extends PropagationTestCase {
|
|||
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1/sub2'] = $view3->getFileInfo('sub1/sub2')->getId();
|
||||
|
||||
/*
|
||||
* User 4
|
||||
*/
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
|
||||
$view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
|
||||
$view4->mkdir('/sub1/sub2');
|
||||
|
@ -108,6 +173,7 @@ class EtagPropagation extends PropagationTestCase {
|
|||
$this->loginAsUser($user);
|
||||
foreach ($ids as $id) {
|
||||
$path = $this->rootView->getPath($id);
|
||||
$ls = $this->rootView->getDirectoryContent($path);
|
||||
$this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
|
||||
}
|
||||
}
|
||||
|
@ -202,19 +268,40 @@ class EtagPropagation extends PropagationTestCase {
|
|||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
||||
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder');
|
||||
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
||||
$folderId = $folderInfo->getId();
|
||||
$this->assertTrue(
|
||||
\OCP\Share::unshare(
|
||||
'folder',
|
||||
$folderId,
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2
|
||||
)
|
||||
);
|
||||
|
||||
$node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder');
|
||||
$shareManager = \OC::$server->getShareManager();
|
||||
$shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node, true);
|
||||
|
||||
foreach ($shares as $share) {
|
||||
if ($share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2) {
|
||||
$shareManager->deleteShare($share);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEtagsForFoldersChanged([
|
||||
// direct recipient affected
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
// reshare recipient affected
|
||||
]);
|
||||
|
||||
$this->assertAllUnchanged();
|
||||
}
|
||||
|
||||
public function testOwnerUnsharesFlatReshares() {
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
||||
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder/inside');
|
||||
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
||||
|
||||
$node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder/inside');
|
||||
$shareManager = \OC::$server->getShareManager();
|
||||
$shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node, true);
|
||||
|
||||
foreach ($shares as $share) {
|
||||
$shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
$this->assertEtagsForFoldersChanged([
|
||||
// direct recipient affected
|
||||
self::TEST_FILES_SHARING_API_USER4,
|
||||
]);
|
||||
|
||||
|
@ -223,14 +310,13 @@ class EtagPropagation extends PropagationTestCase {
|
|||
|
||||
public function testRecipientUnsharesFromSelf() {
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
||||
$ls = $this->rootView->getDirectoryContent('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/');
|
||||
$this->assertTrue(
|
||||
$this->rootView->unlink('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/folder')
|
||||
);
|
||||
$this->assertEtagsForFoldersChanged([
|
||||
// direct recipient affected
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
// reshare recipient affected
|
||||
self::TEST_FILES_SHARING_API_USER4,
|
||||
]);
|
||||
|
||||
$this->assertAllUnchanged();
|
||||
|
@ -240,8 +326,11 @@ class EtagPropagation extends PropagationTestCase {
|
|||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
||||
Filesystem::file_put_contents('/sub1/sub2/folder/asd.txt', 'bar');
|
||||
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
|
||||
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
||||
self::TEST_FILES_SHARING_API_USER3]);
|
||||
$this->assertEtagsForFoldersChanged([
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
self::TEST_FILES_SHARING_API_USER3
|
||||
]);
|
||||
|
||||
$this->assertAllUnchanged();
|
||||
}
|
||||
|
@ -350,14 +439,21 @@ class EtagPropagation extends PropagationTestCase {
|
|||
}
|
||||
|
||||
public function testEtagChangeOnPermissionsChange() {
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
||||
$userFolder = $this->rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
|
||||
$node = $userFolder->get('/sub1/sub2/folder');
|
||||
|
||||
$view = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
|
||||
$folderInfo = $view->getFileInfo('/sub1/sub2/folder');
|
||||
$shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node);
|
||||
/** @var \OCP\Share\IShare[] $shares */
|
||||
$shares = array_filter($shares, function(\OCP\Share\IShare $share) {
|
||||
return $share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2;
|
||||
});
|
||||
$this->assertCount(1, $shares);
|
||||
|
||||
\OCP\Share::setPermissions('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 17);
|
||||
$share = $shares[0];
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE);
|
||||
$this->shareManager->updateShare($share);
|
||||
|
||||
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]);
|
||||
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2]);
|
||||
|
||||
$this->assertAllUnchanged();
|
||||
}
|
||||
|
|
|
@ -46,18 +46,36 @@ class GroupEtagPropagation extends PropagationTestCase {
|
|||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
||||
$view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
|
||||
$view1->mkdir('/test/sub');
|
||||
$folderInfo = $view1->getFileInfo('/test');
|
||||
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group1', 31);
|
||||
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
'/test',
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
'group1',
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test'] = $view1->getFileInfo('test')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test/sub'] = $view1->getFileInfo('test/sub')->getId();
|
||||
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
||||
$view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
$folderInfo = $view2->getFileInfo('/test');
|
||||
$subFolderInfo = $view2->getFileInfo('/test/sub');
|
||||
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group2', 31);
|
||||
\OCP\Share::shareItem('folder', $subFolderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group3', 31);
|
||||
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
'/test',
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
'group2',
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
'/test/sub',
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
'group3',
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test'] = $view2->getFileInfo('test')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test/sub'] = $view2->getFileInfo('test/sub')->getId();
|
||||
|
|
|
@ -59,7 +59,13 @@ class Locking extends TestCase {
|
|||
Filesystem::file_put_contents('/foo/bar.txt', 'asd');
|
||||
$fileId = Filesystem::getFileInfo('/foo/bar.txt')->getId();
|
||||
|
||||
\OCP\Share::shareItem('file', $fileId, \OCP\Share::SHARE_TYPE_USER, $this->recipientUid, 31);
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
'/foo/bar.txt',
|
||||
$this->ownerUid,
|
||||
$this->recipientUid,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
$this->loginAsUser($this->recipientUid);
|
||||
$this->assertTrue(Filesystem::file_exists('bar.txt'));
|
||||
|
|
|
@ -33,39 +33,25 @@ use OC\Files\View;
|
|||
*/
|
||||
class Test_Files_Sharing_Permissions extends OCA\Files_sharing\Tests\TestCase {
|
||||
|
||||
/**
|
||||
* @var Storage
|
||||
*/
|
||||
/** @var Storage */
|
||||
private $sharedStorageRestrictedShare;
|
||||
|
||||
/**
|
||||
* @var Storage
|
||||
*/
|
||||
/** @var Storage */
|
||||
private $sharedCacheRestrictedShare;
|
||||
|
||||
/**
|
||||
* @var View
|
||||
*/
|
||||
/** @var View */
|
||||
private $secondView;
|
||||
|
||||
/**
|
||||
* @var Storage
|
||||
*/
|
||||
/** @var Storage */
|
||||
private $ownerStorage;
|
||||
|
||||
/**
|
||||
* @var Storage
|
||||
*/
|
||||
/** @var Storage */
|
||||
private $sharedStorage;
|
||||
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
/** @var Cache */
|
||||
private $sharedCache;
|
||||
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
/** @var Cache */
|
||||
private $ownerCache;
|
||||
|
||||
protected function setUp() {
|
||||
|
@ -88,12 +74,25 @@ class Test_Files_Sharing_Permissions extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->ownerStorage->getScanner()->scan('');
|
||||
|
||||
// share "shareddir" with user2
|
||||
$fileinfo = $this->view->getFileInfo('container/shareddir');
|
||||
\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$fileinfo2 = $this->view->getFileInfo('container/shareddirrestricted');
|
||||
\OCP\Share::shareItem('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 7);
|
||||
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
$node = $rootFolder->get('container/shareddir');
|
||||
$share = $this->shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$this->shareManager->createShare($share);
|
||||
|
||||
$node = $rootFolder->get('container/shareddirrestricted');
|
||||
$share = $this->shareManager->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
||||
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
|
||||
$this->shareManager->createShare($share);
|
||||
|
||||
// login as user2
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
@ -113,12 +112,10 @@ class Test_Files_Sharing_Permissions extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
$fileinfo = $this->view->getFileInfo('container/shareddir');
|
||||
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$fileinfo2 = $this->view->getFileInfo('container/shareddirrestricted');
|
||||
\OCP\Share::unshare('folder', $fileinfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER);
|
||||
foreach ($shares as $share) {
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
$this->view->deleteAll('container');
|
||||
|
||||
|
|
|
@ -75,17 +75,21 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
|
|||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
|
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
|
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->filename);
|
||||
$share1 = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, 31);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
|
||||
'testGroup', 31);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$share2 = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
'testGroup',
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
||||
|
@ -102,123 +106,9 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
|
|||
// for user3 nothing should change
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* if a file was shared as group share and as individual share they should be grouped
|
||||
*/
|
||||
public function testGroupingOfShares() {
|
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->filename);
|
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
|
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_GROUP1, \OCP\Constants::PERMISSION_READ);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_UPDATE);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
$result = \OCP\Share::getItemSharedWith('file', null);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
|
||||
// test should return exactly one shares created from testCreateShare()
|
||||
$this->assertSame(1, count($result));
|
||||
|
||||
$share = reset($result);
|
||||
$this->assertSame(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, $share['permissions']);
|
||||
|
||||
\OC\Files\Filesystem::rename($this->filename, $this->filename . '-renamed');
|
||||
|
||||
$result = \OCP\Share::getItemSharedWith('file', null);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
|
||||
// test should return exactly one shares created from testCreateShare()
|
||||
$this->assertSame(1, count($result));
|
||||
|
||||
$share = reset($result);
|
||||
$this->assertSame(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE, $share['permissions']);
|
||||
$this->assertSame($this->filename . '-renamed', $share['file_target']);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
// unshare user share
|
||||
$result = \OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
$result = \OCP\Share::getItemSharedWith('file', null);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
|
||||
// test should return the remaining group share
|
||||
$this->assertSame(1, count($result));
|
||||
|
||||
$share = reset($result);
|
||||
// only the group share permissions should be available now
|
||||
$this->assertSame(\OCP\Constants::PERMISSION_READ, $share['permissions']);
|
||||
$this->assertSame($this->filename . '-renamed', $share['file_target']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* user1 share file to a group and to a user2 in the same group. Then user2
|
||||
* unshares the file from self. Afterwards user1 should no longer see the
|
||||
* single user share to user2. If he re-shares the file to user2 the same target
|
||||
* then the group share should be used to group the item
|
||||
*/
|
||||
public function testShareAndUnshareFromSelf() {
|
||||
$fileinfo = $this->view->getFileInfo($this->filename);
|
||||
|
||||
// share the file to group1 (user2 is a member of this group) and explicitely to user2
|
||||
\OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, \OCP\Constants::PERMISSION_ALL);
|
||||
\OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
|
||||
|
||||
// user1 should have to shared files
|
||||
$shares = \OCP\Share::getItemsShared('file');
|
||||
$this->assertSame(2, count($shares));
|
||||
|
||||
// user2 should have two files "welcome.txt" and the shared file,
|
||||
// both the group share and the single share of the same file should be
|
||||
// grouped to one file
|
||||
\Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
|
||||
$this->assertSame(2, count($dirContent));
|
||||
$this->verifyDirContent($dirContent, array('welcome.txt', ltrim($this->filename, '/')));
|
||||
|
||||
// now user2 deletes the share (= unshare from self)
|
||||
\OC\Files\Filesystem::unlink($this->filename);
|
||||
|
||||
// only welcome.txt should exists
|
||||
$dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
|
||||
$this->assertSame(1, count($dirContent));
|
||||
$this->verifyDirContent($dirContent, array('welcome.txt'));
|
||||
|
||||
// login as user1...
|
||||
\Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
// ... now user1 should have only one shared file, the group share
|
||||
$shares = \OCP\Share::getItemsShared('file');
|
||||
$this->assertSame(1, count($shares));
|
||||
|
||||
// user1 shares a gain the file directly to user2
|
||||
\OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
|
||||
|
||||
// user2 should see again welcome.txt and the shared file
|
||||
\Test_Files_Sharing::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$dirContent = \OC\Files\Filesystem::getDirectoryContent('/');
|
||||
$this->assertSame(2, count($dirContent));
|
||||
$this->verifyDirContent($dirContent, array('welcome.txt', ltrim($this->filename, '/')));
|
||||
|
||||
|
||||
$this->shareManager->deleteShare($share1);
|
||||
$this->shareManager->deleteShare($share2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,15 +128,23 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
|
|||
$fileinfo = $this->view->getFileInfo($this->filename);
|
||||
$folderinfo = $this->view->getFileInfo($this->folder);
|
||||
|
||||
$fileShare = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->assertTrue($fileShare);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
\OCA\Files_Sharing\Helper::setShareFolder('/Shared/subfolder');
|
||||
|
||||
$folderShare = \OCP\Share::shareItem('folder', $folderinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->assertTrue($folderShare);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
|
@ -261,56 +159,59 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
\OC\Files\Filesystem::file_put_contents('test.txt', 'test');
|
||||
|
||||
$fileInfo = \OC\Files\Filesystem::getFileInfo('test.txt');
|
||||
|
||||
$this->assertTrue(
|
||||
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1, 23)
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
'test.txt',
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_GROUP1,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
$items = \OCP\Share::getItemsSharedWith('file');
|
||||
$this->assertSame('/test.txt' ,$items[0]['file_target']);
|
||||
$this->assertSame(23, $items[0]['permissions']);
|
||||
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP);
|
||||
$share = $shares[0];
|
||||
$this->assertSame('/test.txt' ,$share->getTarget());
|
||||
$this->assertSame(19, $share->getPermissions());
|
||||
|
||||
\OC\Files\Filesystem::rename('test.txt', 'new test.txt');
|
||||
|
||||
$items = \OCP\Share::getItemsSharedWith('file');
|
||||
$this->assertSame('/new test.txt' ,$items[0]['file_target']);
|
||||
$this->assertSame(23, $items[0]['permissions']);
|
||||
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP);
|
||||
$share = $shares[0];
|
||||
$this->assertSame('/new test.txt' ,$share->getTarget());
|
||||
$this->assertSame(19, $share->getPermissions());
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
\OCP\Share::setPermissions('file', $items[0]['item_source'], $items[0]['share_type'], $items[0]['share_with'], 3);
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE);
|
||||
$this->shareManager->updateShare($share);
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$items = \OCP\Share::getItemsSharedWith('file');
|
||||
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_GROUP);
|
||||
$share = $shares[0];
|
||||
|
||||
$this->assertSame('/new test.txt' ,$items[0]['file_target']);
|
||||
$this->assertSame(3, $items[0]['permissions']);
|
||||
$this->assertSame('/new test.txt' ,$share->getTarget());
|
||||
$this->assertSame(3, $share->getPermissions());
|
||||
}
|
||||
|
||||
/**
|
||||
* shared files should never have delete permissions
|
||||
* @dataProvider dataProviderTestFileSharePermissions
|
||||
*/
|
||||
public function testFileSharePermissions($permission, $expectedPermissions) {
|
||||
public function testFileSharePermissions($permission, $expectedvalid) {
|
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->filename);
|
||||
$pass = true;
|
||||
try {
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
$permission
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$pass = false;
|
||||
}
|
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, $permission);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = \OCP\Share::getItemShared('file', null);
|
||||
|
||||
$this->assertTrue(is_array($result));
|
||||
|
||||
// test should return exactly one shares created from testCreateShare()
|
||||
$this->assertSame(1, count($result), 'more then one share found');
|
||||
|
||||
$share = reset($result);
|
||||
$this->assertSame($expectedPermissions, $share['permissions']);
|
||||
$this->assertEquals($expectedvalid, $pass);
|
||||
}
|
||||
|
||||
public function dataProviderTestFileSharePermissions() {
|
||||
|
@ -321,22 +222,23 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
|
|||
$permission6 = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
|
||||
|
||||
return array(
|
||||
array($permission1, \OCP\Constants::PERMISSION_ALL & ~\OCP\Constants::PERMISSION_DELETE),
|
||||
array($permission3, $permission3),
|
||||
array($permission4, $permission4),
|
||||
array($permission5, $permission3),
|
||||
array($permission6, $permission4),
|
||||
array($permission1, false),
|
||||
array($permission3, true),
|
||||
array($permission4, true),
|
||||
array($permission5, false),
|
||||
array($permission6, false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testFileOwner() {
|
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->filename);
|
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_ALL);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ
|
||||
);
|
||||
|
||||
$this->loginHelper(\Test_Files_Sharing::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
|
@ -344,135 +246,4 @@ class Test_Files_Sharing extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
$this->assertSame(\Test_Files_Sharing::TEST_FILES_SHARING_API_USER1, $info->getOwner()->getUID());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderGetUsersSharingFile
|
||||
*
|
||||
* @param string $groupName name of group to share with
|
||||
* @param bool $includeOwner whether to include the owner in the result
|
||||
* @param bool $includePaths whether to include paths in the result
|
||||
* @param array $expectedResult expected result of the API call
|
||||
*/
|
||||
public function testGetUsersSharingFile($groupName, $includeOwner, $includePaths, $expectedResult) {
|
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->folder);
|
||||
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
|
||||
$groupName, \OCP\Constants::PERMISSION_READ);
|
||||
$this->assertTrue($result);
|
||||
|
||||
// public share
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_LINK,
|
||||
null, \OCP\Constants::PERMISSION_READ);
|
||||
$this->assertNotNull($result); // returns the token!
|
||||
|
||||
// owner renames after sharing
|
||||
$this->view->rename($this->folder, $this->folder . '_owner_renamed');
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
$user2View->rename($this->folder, $this->folder . '_renamed');
|
||||
|
||||
$ownerPath = $this->folder . '_owner_renamed';
|
||||
$owner = self::TEST_FILES_SHARING_API_USER1;
|
||||
|
||||
$result = \OCP\Share::getUsersSharingFile($ownerPath, $owner, $includeOwner, $includePaths);
|
||||
|
||||
// sort users to make sure it matches
|
||||
if ($includePaths) {
|
||||
ksort($result);
|
||||
} else {
|
||||
sort($result['users']);
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedResult,
|
||||
$result
|
||||
);
|
||||
}
|
||||
|
||||
public function dataProviderGetUsersSharingFile() {
|
||||
// note: "group" contains user1 (the owner), user2 and user3
|
||||
// and self::TEST_FILES_SHARING_API_GROUP1 contains only user2
|
||||
return [
|
||||
// share with group that contains owner
|
||||
[
|
||||
'group',
|
||||
false,
|
||||
false,
|
||||
[
|
||||
'users' =>
|
||||
[
|
||||
// because user1 was in group
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
self::TEST_FILES_SHARING_API_USER3,
|
||||
],
|
||||
'public' => true,
|
||||
'remote' => false,
|
||||
],
|
||||
],
|
||||
// share with group that does not contain owner
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_GROUP1,
|
||||
false,
|
||||
false,
|
||||
[
|
||||
'users' =>
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
],
|
||||
'public' => true,
|
||||
'remote' => false,
|
||||
],
|
||||
],
|
||||
// share with group that does not contain owner, include owner
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_GROUP1,
|
||||
true,
|
||||
false,
|
||||
[
|
||||
'users' =>
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
],
|
||||
'public' => true,
|
||||
'remote' => false,
|
||||
],
|
||||
],
|
||||
// include paths, with owner
|
||||
[
|
||||
'group',
|
||||
true,
|
||||
true,
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_USER1 => self::TEST_FOLDER_NAME . '_owner_renamed',
|
||||
self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME . '_renamed',
|
||||
self::TEST_FILES_SHARING_API_USER3 => self::TEST_FOLDER_NAME,
|
||||
],
|
||||
],
|
||||
// include paths, group without owner
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_GROUP1,
|
||||
false,
|
||||
true,
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME. '_renamed',
|
||||
],
|
||||
],
|
||||
// include paths, include owner, group without owner
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_GROUP1,
|
||||
true,
|
||||
true,
|
||||
[
|
||||
self::TEST_FILES_SHARING_API_USER1 => self::TEST_FOLDER_NAME . '_owner_renamed',
|
||||
self::TEST_FILES_SHARING_API_USER2 => self::TEST_FOLDER_NAME . '_renamed',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,8 +49,12 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
protected function tearDown() {
|
||||
if ($this->view) {
|
||||
$this->view->unlink($this->folder);
|
||||
$this->view->unlink($this->filename);
|
||||
if ($this->view->file_exists($this->folder)) {
|
||||
$this->view->unlink($this->folder);
|
||||
}
|
||||
if ($this->view->file_exists($this->filename)) {
|
||||
$this->view->unlink($this->filename);
|
||||
}
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
|
@ -59,59 +63,46 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
/**
|
||||
* test if the mount point moves up if the parent folder no longer exists
|
||||
*/
|
||||
function testShareMountLoseParentFolder() {
|
||||
public function testShareMountLoseParentFolder() {
|
||||
|
||||
// share to user
|
||||
$fileinfo = $this->view->getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL);
|
||||
|
||||
$statement = "UPDATE `*PREFIX*share` SET `file_target` = ? where `share_with` = ?";
|
||||
$query = \OCP\DB::prepare($statement);
|
||||
$arguments = array('/foo/bar' . $this->folder, self::TEST_FILES_SHARING_API_USER2);
|
||||
$query->execute($arguments);
|
||||
$share->setTarget('/foo/bar' . $this->folder);
|
||||
$this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
|
||||
$result = $query->execute();
|
||||
|
||||
$shares = $result->fetchAll();
|
||||
|
||||
$this->assertSame(1, count($shares));
|
||||
|
||||
$share = reset($shares);
|
||||
$this->assertSame('/foo/bar' . $this->folder, $share['file_target']);
|
||||
$share = $this->shareManager->getShareById($share->getFullId());
|
||||
$this->assertSame('/foo/bar' . $this->folder, $share->getTarget());
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
// share should have moved up
|
||||
|
||||
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*share`');
|
||||
$result = $query->execute();
|
||||
|
||||
$shares = $result->fetchAll();
|
||||
|
||||
$this->assertSame(1, count($shares));
|
||||
|
||||
$share = reset($shares);
|
||||
$this->assertSame($this->folder, $share['file_target']);
|
||||
$share = $this->shareManager->getShareById($share->getFullId());
|
||||
$this->assertSame($this->folder, $share->getTarget());
|
||||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->shareManager->deleteShare($share);
|
||||
$this->view->unlink($this->folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
function testDeleteParentOfMountPoint() {
|
||||
|
||||
public function testDeleteParentOfMountPoint() {
|
||||
// share to user
|
||||
$fileinfo = $this->view->getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -143,10 +134,14 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->view->unlink($this->folder);
|
||||
}
|
||||
|
||||
function testMoveSharedFile() {
|
||||
$fileinfo = $this->view->getFileInfo($this->filename);
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
public function testMoveSharedFile() {
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
|
@ -166,22 +161,27 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
|
||||
|
||||
//cleanup
|
||||
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
/**
|
||||
* share file with a group if a user renames the file the filename should not change
|
||||
* for the other users
|
||||
*/
|
||||
function testMoveGroupShare () {
|
||||
public function testMoveGroupShare () {
|
||||
\OC_Group::createGroup('testGroup');
|
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
|
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
|
||||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
|
||||
|
||||
$fileinfo = $this->view->getFileInfo($this->filename);
|
||||
$result = \OCP\Share::shareItem('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
|
||||
"testGroup", 31);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
'testGroup',
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
|
@ -202,7 +202,7 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
\OCP\Share::unshare('file', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
|
||||
$this->shareManager->deleteShare($share);
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
|
||||
|
@ -214,7 +214,7 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
* @param string $expectedResult
|
||||
* @param bool $exception if a exception is expected
|
||||
*/
|
||||
function testStripUserFilesPath($path, $expectedResult, $exception) {
|
||||
public function testStripUserFilesPath($path, $expectedResult, $exception) {
|
||||
$testClass = new DummyTestClassSharedMount(null, null);
|
||||
try {
|
||||
$result = $testClass->stripUserFilesPathDummy($path);
|
||||
|
@ -228,7 +228,7 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
function dataProviderTestStripUserFilesPath() {
|
||||
public function dataProviderTestStripUserFilesPath() {
|
||||
return array(
|
||||
array('/user/files/foo.txt', '/foo.txt', false),
|
||||
array('/user/files/folder/foo.txt', '/folder/foo.txt', false),
|
||||
|
@ -239,7 +239,7 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
function dataPermissionMovedGroupShare() {
|
||||
public function dataPermissionMovedGroupShare() {
|
||||
$data = [];
|
||||
|
||||
$powerset = function($permissions) {
|
||||
|
@ -256,7 +256,6 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
//Generate file permissions
|
||||
$permissions = [
|
||||
\OCP\Constants::PERMISSION_UPDATE,
|
||||
\OCP\Constants::PERMISSION_CREATE,
|
||||
\OCP\Constants::PERMISSION_SHARE,
|
||||
];
|
||||
|
||||
|
@ -321,54 +320,45 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
|
||||
|
||||
// Share item with group
|
||||
$fileinfo = $this->view->getFileInfo($path);
|
||||
$this->assertTrue(
|
||||
\OCP\Share::shareItem($type, $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", $beforePerm)
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
$path,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
'testGroup',
|
||||
$beforePerm
|
||||
);
|
||||
|
||||
// Login as user 2 and verify the item exists
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($path));
|
||||
$result = \OCP\Share::getItemSharedWithBySource($type, $fileinfo['fileid']);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($beforePerm, $result['permissions']);
|
||||
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertEquals($beforePerm, $result->getPermissions());
|
||||
|
||||
// Now move the item forcing a new entry in the share table
|
||||
\OC\Files\Filesystem::rename($path, "newPath");
|
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists('newPath'));
|
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($path));
|
||||
|
||||
// Login as user 1 again and change permissions
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$this->assertTrue(
|
||||
\OCP\Share::setPermissions($type, $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", $afterPerm)
|
||||
);
|
||||
// change permissions
|
||||
$share->setPermissions($afterPerm);
|
||||
$this->shareManager->updateShare($share);
|
||||
|
||||
// Login as user 3 and verify that the permissions are changed
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
||||
$result = \OCP\Share::getItemSharedWithBySource($type, $fileinfo['fileid']);
|
||||
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER3);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($afterPerm, $result['permissions']);
|
||||
$groupShareId = $result['id'];
|
||||
$this->assertEquals($afterPerm, $result->getPermissions());
|
||||
|
||||
// Login as user 2 and verify that the permissions are changed
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$result = \OCP\Share::getItemSharedWithBySource($type, $fileinfo['fileid']);
|
||||
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($afterPerm, $result['permissions']);
|
||||
$this->assertNotEquals($groupShareId, $result['id']);
|
||||
|
||||
// Also verify in the DB
|
||||
$statement = "SELECT `permissions` FROM `*PREFIX*share` WHERE `id`=?";
|
||||
$query = \OCP\DB::prepare($statement);
|
||||
$result = $query->execute([$result['id']]);
|
||||
$shares = $result->fetchAll();
|
||||
$this->assertCount(1, $shares);
|
||||
$this->assertEquals($afterPerm, $shares[0]['permissions']);
|
||||
$this->assertEquals($afterPerm, $result->getPermissions());
|
||||
$this->assertEquals('/newPath', $result->getTarget());
|
||||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
\OCP\Share::unshare($type, $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
|
||||
$this->shareManager->deleteShare($share);
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
|
||||
|
@ -388,66 +378,44 @@ class Test_Files_Sharing_Mount extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
// Share item with group
|
||||
$fileinfo = $this->view->getFileInfo($this->folder);
|
||||
$this->assertTrue(
|
||||
\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_READ)
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
'testGroup',
|
||||
\OCP\Constants::PERMISSION_READ
|
||||
);
|
||||
|
||||
// Login as user 2 and verify the item exists
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
|
||||
$result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
|
||||
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(\OCP\Constants::PERMISSION_READ, $result['permissions']);
|
||||
$this->assertEquals(\OCP\Constants::PERMISSION_READ, $result->getPermissions());
|
||||
|
||||
// Delete the share
|
||||
$this->assertTrue(\OC\Files\Filesystem::rmdir($this->folder));
|
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
|
||||
|
||||
// Verify we do not get a share
|
||||
$result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
|
||||
$this->assertEmpty($result);
|
||||
|
||||
// Verify that the permission is correct in the DB
|
||||
$qb = $connection->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('share')
|
||||
->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))
|
||||
->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))
|
||||
->setParameter(':fileSource', $fileinfo['fileid'])
|
||||
->setParameter(':shareType', 2);
|
||||
$res = $qb->execute()->fetchAll();
|
||||
|
||||
$this->assertCount(1, $res);
|
||||
$this->assertEquals(0, $res[0]['permissions']);
|
||||
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertEquals(0, $result->getPermissions());
|
||||
|
||||
// Login as user 1 again and change permissions
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$this->assertTrue(
|
||||
\OCP\Share::setPermissions('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, "testGroup", \OCP\Constants::PERMISSION_ALL)
|
||||
);
|
||||
$share->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$share = $this->shareManager->updateShare($share);
|
||||
|
||||
// Login as user 2 and verify
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
|
||||
$result = \OCP\Share::getItemSharedWithBySource('folder', $fileinfo['fileid']);
|
||||
$this->assertEmpty($result);
|
||||
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertEquals(0, $result->getPermissions());
|
||||
|
||||
$connection = \OC::$server->getDatabaseConnection();
|
||||
$qb = $connection->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from('share')
|
||||
->where($qb->expr()->eq('file_source', $qb->createParameter('fileSource')))
|
||||
->andWhere($qb->expr()->eq('share_type', $qb->createParameter('shareType')))
|
||||
->setParameter(':fileSource', $fileinfo['fileid'])
|
||||
->setParameter(':shareType', 2);
|
||||
$res = $qb->execute()->fetchAll();
|
||||
|
||||
$this->assertCount(1, $res);
|
||||
$this->assertEquals(0, $res[0]['permissions']);
|
||||
$this->shareManager->deleteShare($share);
|
||||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_GROUP, 'testGroup');
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
|
||||
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
|
||||
|
|
|
@ -50,8 +50,12 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
protected function tearDown() {
|
||||
if ($this->view) {
|
||||
$this->view->unlink($this->folder);
|
||||
$this->view->unlink($this->filename);
|
||||
if ($this->view->file_exists($this->folder)) {
|
||||
$this->view->unlink($this->folder);
|
||||
}
|
||||
if ($this->view->file_exists($this->filename)) {
|
||||
$this->view->unlink($this->filename);
|
||||
}
|
||||
}
|
||||
|
||||
\OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
|
||||
|
@ -64,14 +68,16 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
*
|
||||
* @medium
|
||||
*/
|
||||
function testParentOfMountPointIsGone() {
|
||||
public function testParentOfMountPointIsGone() {
|
||||
|
||||
// share to user
|
||||
$fileinfo = $this->view->getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
|
||||
$this->assertTrue($result);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -107,14 +113,17 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
/**
|
||||
* @medium
|
||||
*/
|
||||
function testRenamePartFile() {
|
||||
public function testRenamePartFile() {
|
||||
|
||||
// share to user
|
||||
$fileinfo = $this->view->getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -139,26 +148,30 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->assertTrue($this->view->file_exists($this->folder . '/foo.txt'));
|
||||
|
||||
//cleanup
|
||||
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testFilesize() {
|
||||
|
||||
$fileinfoFolder = $this->view->getFileInfo($this->folder);
|
||||
$fileinfoFile = $this->view->getFileInfo($this->filename);
|
||||
|
||||
$folderSize = $this->view->filesize($this->folder);
|
||||
$file1Size = $this->view->filesize($this->folder . $this->filename);
|
||||
$file2Size = $this->view->filesize($this->filename);
|
||||
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->assertTrue($result);
|
||||
$share1 = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
$share2 = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
$result = \OCP\Share::shareItem('file', $fileinfoFile['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->assertTrue($result);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
|
@ -168,21 +181,19 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->assertSame($file2Size, \OC\Files\Filesystem::filesize($this->filename));
|
||||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
$result = \OCP\Share::unshare('file', $fileinfoFile['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
$this->shareManager->deleteShare($share1);
|
||||
$this->shareManager->deleteShare($share2);
|
||||
}
|
||||
|
||||
function testGetPermissions() {
|
||||
$fileinfoFolder = $this->view->getFileInfo($this->folder);
|
||||
public function testGetPermissions() {
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ
|
||||
);
|
||||
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 1);
|
||||
$this->assertTrue($result);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
|
@ -201,18 +212,19 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testFopenWithReadOnlyPermission() {
|
||||
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
|
||||
$fileinfoFolder = $this->view->getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -232,18 +244,20 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
|
||||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testFopenWithCreateOnlyPermission() {
|
||||
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
|
||||
$fileinfoFolder = $this->view->getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -284,11 +298,14 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
public function testFopenWithUpdateOnlyPermission() {
|
||||
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
|
||||
$fileinfoFolder = $this->view->getFileInfo($this->folder);
|
||||
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE);
|
||||
$this->assertTrue($result);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -322,18 +339,19 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->assertFalse($user2View->unlink($this->folder . '/existing-renamed.txt'));
|
||||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testFopenWithDeleteOnlyPermission() {
|
||||
$this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
|
||||
$fileinfoFolder = $this->view->getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -353,23 +371,28 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->assertTrue($user2View->unlink($this->folder . '/existing.txt'));
|
||||
|
||||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$result = \OCP\Share::unshare('folder', $fileinfoFolder['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
function testMountSharesOtherUser() {
|
||||
$folderInfo = $this->view->getFileInfo($this->folder);
|
||||
$fileInfo = $this->view->getFileInfo($this->filename);
|
||||
public function testMountSharesOtherUser() {
|
||||
$rootView = new \OC\Files\View('');
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
// share 2 different files with 2 different users
|
||||
\OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER3, 31);
|
||||
$share1 = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
$share2 = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->filename,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER3,
|
||||
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
|
||||
|
@ -387,15 +410,21 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
//cleanup
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$this->view->unlink($this->folder);
|
||||
|
||||
$this->shareManager->deleteShare($share1);
|
||||
$this->shareManager->deleteShare($share2);
|
||||
}
|
||||
|
||||
public function testCopyFromStorage() {
|
||||
$folderInfo = $this->view->getFileInfo($this->folder);
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
// share 2 different files with 2 different users
|
||||
\OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -416,15 +445,19 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$this->view->unlink($this->folder);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testMoveFromStorage() {
|
||||
$folderInfo = $this->view->getFileInfo($this->folder);
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
// share 2 different files with 2 different users
|
||||
\OCP\Share::shareItem('folder', $folderInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -445,31 +478,40 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$this->view->unlink($this->folder);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testNameConflict() {
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$view1 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
|
||||
$view1->mkdir('foo');
|
||||
$folderInfo1 = $view1->getFileInfo('foo');
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
||||
$view3 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
|
||||
$view3->mkdir('foo');
|
||||
$folderInfo2 = $view3->getFileInfo('foo');
|
||||
|
||||
// share a folder with the same name from two different users to the same user
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
\OCP\Share::shareItem('folder', $folderInfo1['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
|
||||
self::TEST_FILES_SHARING_API_GROUP1, 31);
|
||||
$share1 = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
'foo',
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_GROUP1,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
|
||||
|
||||
\OCP\Share::shareItem('folder', $folderInfo2['fileid'], \OCP\Share::SHARE_TYPE_GROUP,
|
||||
self::TEST_FILES_SHARING_API_GROUP1, 31);
|
||||
$share2 = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_GROUP,
|
||||
'foo',
|
||||
self::TEST_FILES_SHARING_API_USER3,
|
||||
self::TEST_FILES_SHARING_API_GROUP1,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$view2 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -482,7 +524,9 @@ class Test_Files_Sharing_Storage extends OCA\Files_sharing\Tests\TestCase {
|
|||
/** @var \OC\Files\Storage\Shared $storage */
|
||||
$storage = $mount->getStorage();
|
||||
|
||||
$source = $storage->getFile('');
|
||||
$this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $source['uid_owner']);
|
||||
$this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $storage->getOwner(''));
|
||||
|
||||
$this->shareManager->deleteShare($share1);
|
||||
$this->shareManager->deleteShare($share2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,9 +43,13 @@ class SizePropagation extends TestCase {
|
|||
$ownerView->mkdir('/sharedfolder/subfolder');
|
||||
$ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
|
||||
|
||||
$sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
|
||||
$this->assertInstanceOf('\OC\Files\FileInfo', $sharedFolderInfo);
|
||||
\OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
'/sharedfolder',
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
$ownerRootInfo = $ownerView->getFileInfo('', false);
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
@ -76,9 +80,13 @@ class SizePropagation extends TestCase {
|
|||
$ownerView->mkdir('/sharedfolder/subfolder');
|
||||
$ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
|
||||
|
||||
$sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
|
||||
$this->assertInstanceOf('\OC\Files\FileInfo', $sharedFolderInfo);
|
||||
\OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
'/sharedfolder',
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
$ownerRootInfo = $ownerView->getFileInfo('', false);
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
|
|
@ -59,6 +59,11 @@ abstract class TestCase extends \Test\TestCase {
|
|||
public $folder;
|
||||
public $subfolder;
|
||||
|
||||
/** @var \OCP\Share\IManager */
|
||||
protected $shareManager;
|
||||
/** @var \OCP\Files\IRootFolder */
|
||||
protected $rootFolder;
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
|
@ -96,7 +101,6 @@ abstract class TestCase extends \Test\TestCase {
|
|||
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER4, 'group3');
|
||||
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_GROUP1);
|
||||
\OC_Group::useBackend($groupBackend);
|
||||
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
|
@ -107,6 +111,9 @@ abstract class TestCase extends \Test\TestCase {
|
|||
|
||||
$this->data = 'foobar';
|
||||
$this->view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
|
||||
|
||||
$this->shareManager = \OC::$server->getShareManager();
|
||||
$this->rootFolder = \OC::$server->getRootFolder();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
|
@ -201,4 +208,26 @@ abstract class TestCase extends \Test\TestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type The share type
|
||||
* @param string $path The path to share relative to $initiators root
|
||||
* @param string $initiator
|
||||
* @param string $recipient
|
||||
* @param int $permissions
|
||||
* @return \OCP\Share\IShare
|
||||
*/
|
||||
protected function share($type, $path, $initiator, $recipient, $permissions) {
|
||||
$userFolder = $this->rootFolder->getUserFolder($initiator);
|
||||
$node = $userFolder->get($path);
|
||||
|
||||
$share = $this->shareManager->newShare();
|
||||
$share->setShareType($type)
|
||||
->setSharedWith($recipient)
|
||||
->setSharedBy($initiator)
|
||||
->setNode($node)
|
||||
->setPermissions($permissions);
|
||||
$share = $this->shareManager->createShare($share);
|
||||
|
||||
return $share;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,14 +78,19 @@ class UnshareChildren extends TestCase {
|
|||
|
||||
$fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
|
||||
|
||||
$result = \OCP\Share::shareItem('folder', $fileInfo2->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->assertTrue($result);
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
// one folder should be shared with the user
|
||||
$sharedFolders = \OCP\Share::getItemsSharedWith('folder');
|
||||
$this->assertSame(1, count($sharedFolders));
|
||||
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
|
||||
$this->assertCount(1, $shares);
|
||||
|
||||
// move shared folder to 'localDir'
|
||||
\OC\Files\Filesystem::mkdir('localDir');
|
||||
|
@ -97,8 +102,8 @@ class UnshareChildren extends TestCase {
|
|||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
// after the parent directory was deleted the share should be unshared
|
||||
$sharedFolders = \OCP\Share::getItemsSharedWith('folder');
|
||||
$this->assertTrue(empty($sharedFolders));
|
||||
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
|
||||
$this->assertEmpty($shares);
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
|
|
|
@ -75,7 +75,13 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
|
|||
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
||||
$this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);
|
||||
|
||||
\OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
|
@ -152,9 +158,14 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
|
|||
$etagBeforeShareDir = $beforeShareDir->getEtag();
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
|
@ -173,8 +184,7 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
|
|||
|
||||
// cleanup
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
$this->shareManager->deleteShare($share);
|
||||
|
||||
$config->setSystemValue('share_folder', $oldShareFolder);
|
||||
}
|
||||
|
@ -185,8 +195,14 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
|
|||
function testRename() {
|
||||
|
||||
$fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
$this->folder,
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
|
@ -210,9 +226,7 @@ class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
|
|||
$this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
|
||||
|
||||
// cleanup
|
||||
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
$result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->assertTrue($result);
|
||||
$this->shareManager->deleteShare($share);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,33 +32,27 @@
|
|||
*/
|
||||
class Test_Files_Sharing_Watcher extends OCA\Files_sharing\Tests\TestCase {
|
||||
|
||||
/**
|
||||
* @var \OC\Files\Storage\Storage
|
||||
*/
|
||||
/** @var \OC\Files\Storage\Storage */
|
||||
private $ownerStorage;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\Cache\Cache
|
||||
*/
|
||||
/** @var \OC\Files\Cache\Cache */
|
||||
private $ownerCache;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\Storage\Storage
|
||||
*/
|
||||
/** @var \OC\Files\Storage\Storage */
|
||||
private $sharedStorage;
|
||||
|
||||
/**
|
||||
* @var \OC\Files\Cache\Cache
|
||||
*/
|
||||
/** @var \OC\Files\Cache\Cache */
|
||||
private $sharedCache;
|
||||
|
||||
/** @var \OCP\Share\IShare */
|
||||
private $_share;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
// prepare user1's dir structure
|
||||
$textData = "dummy file data\n";
|
||||
$this->view->mkdir('container');
|
||||
$this->view->mkdir('container/shareddir');
|
||||
$this->view->mkdir('container/shareddir/subdir');
|
||||
|
@ -68,9 +62,13 @@ class Test_Files_Sharing_Watcher extends OCA\Files_sharing\Tests\TestCase {
|
|||
$this->ownerStorage->getScanner()->scan('');
|
||||
|
||||
// share "shareddir" with user2
|
||||
$fileinfo = $this->view->getFileInfo('container/shareddir');
|
||||
\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2, 31);
|
||||
$this->_share = $this->share(
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
'container/shareddir',
|
||||
self::TEST_FILES_SHARING_API_USER1,
|
||||
self::TEST_FILES_SHARING_API_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
|
||||
// login as user2
|
||||
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
|
||||
|
@ -89,9 +87,7 @@ class Test_Files_Sharing_Watcher extends OCA\Files_sharing\Tests\TestCase {
|
|||
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
if ($this->view) {
|
||||
$fileinfo = $this->view->getFileInfo('container/shareddir');
|
||||
\OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_FILES_SHARING_API_USER2);
|
||||
$this->shareManager->deleteShare($this->_share);
|
||||
|
||||
$this->view->deleteAll('container');
|
||||
|
||||
|
|
|
@ -261,9 +261,14 @@ class Storage extends \Test\TestCase {
|
|||
$recipientUser = $this->getUniqueId('recipient_');
|
||||
\OC::$server->getUserManager()->createUser($recipientUser, $recipientUser);
|
||||
|
||||
$fileinfo = $this->userView->getFileInfo('share');
|
||||
$this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
$recipientUser, 31));
|
||||
$node = \OC::$server->getUserFolder($this->user)->get('share');
|
||||
$share = \OC::$server->getShareManager()->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedBy($this->user)
|
||||
->setSharedWith($recipientUser)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
\OC::$server->getShareManager()->createShare($share);
|
||||
|
||||
$this->loginAsUser($recipientUser);
|
||||
|
||||
|
@ -309,9 +314,14 @@ class Storage extends \Test\TestCase {
|
|||
$recipientUser = $this->getUniqueId('recipient_');
|
||||
\OC::$server->getUserManager()->createUser($recipientUser, $recipientUser);
|
||||
|
||||
$fileinfo = $this->userView->getFileInfo('share');
|
||||
$this->assertTrue(\OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
$recipientUser, 31));
|
||||
$node = \OC::$server->getUserFolder($this->user)->get('share');
|
||||
$share = \OC::$server->getShareManager()->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedBy($this->user)
|
||||
->setSharedWith($recipientUser)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
\OC::$server->getShareManager()->createShare($share);
|
||||
|
||||
$this->loginAsUser($recipientUser);
|
||||
|
||||
|
|
|
@ -211,9 +211,14 @@ class Test_Trashbin extends \Test\TestCase {
|
|||
\OC\Files\Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
|
||||
|
||||
//share user1-4.txt with user2
|
||||
$fileInfo = \OC\Files\Filesystem::getFileInfo($folder);
|
||||
$result = \OCP\Share::shareItem('folder', $fileInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_TRASHBIN_USER2, 31);
|
||||
$this->assertTrue($result);
|
||||
$node = \OC::$server->getUserFolder(self::TEST_TRASHBIN_USER1)->get($folder);
|
||||
$share = \OC::$server->getShareManager()->newShare();
|
||||
$share->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setNode($node)
|
||||
->setSharedBy(self::TEST_TRASHBIN_USER1)
|
||||
->setSharedWith(self::TEST_TRASHBIN_USER2)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
\OC::$server->getShareManager()->createShare($share);
|
||||
|
||||
// delete them so that they end up in the trash bin
|
||||
\OC\Files\Filesystem::unlink($folder . 'user1-1.txt');
|
||||
|
|
|
@ -297,8 +297,6 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
\OC\Files\Filesystem::mkdir('folder1/folder2');
|
||||
\OC\Files\Filesystem::file_put_contents("folder1/test.txt", "test file");
|
||||
|
||||
$fileInfo = \OC\Files\Filesystem::getFileInfo('folder1');
|
||||
|
||||
$t1 = time();
|
||||
// second version is two weeks older, this way we make sure that no
|
||||
// version will be expired
|
||||
|
@ -314,7 +312,14 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
$this->rootView->file_put_contents($v1, 'version1');
|
||||
$this->rootView->file_put_contents($v2, 'version2');
|
||||
|
||||
\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
|
||||
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
|
||||
$share = \OC::$server->getShareManager()->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedBy(self::TEST_VERSIONS_USER)
|
||||
->setSharedWith(self::TEST_VERSIONS_USER2)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$share = \OC::$server->getShareManager()->createShare($share);
|
||||
|
||||
self::loginHelper(self::TEST_VERSIONS_USER2);
|
||||
|
||||
|
@ -332,6 +337,8 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
|
||||
$this->assertTrue($this->rootView->file_exists($v1Renamed));
|
||||
$this->assertTrue($this->rootView->file_exists($v2Renamed));
|
||||
|
||||
\OC::$server->getShareManager()->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testMoveFolder() {
|
||||
|
@ -373,13 +380,14 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
\OC\Files\Filesystem::mkdir('folder1');
|
||||
$fileInfo = \OC\Files\Filesystem::getFileInfo('folder1');
|
||||
|
||||
\OCP\Share::shareItem(
|
||||
'folder',
|
||||
$fileInfo['fileid'],
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_VERSIONS_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
|
||||
$share = \OC::$server->getShareManager()->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedBy(self::TEST_VERSIONS_USER)
|
||||
->setSharedWith(self::TEST_VERSIONS_USER2)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$share = \OC::$server->getShareManager()->createShare($share);
|
||||
|
||||
self::loginHelper(self::TEST_VERSIONS_USER2);
|
||||
$versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions';
|
||||
|
@ -413,20 +421,22 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
|
||||
$this->assertTrue($this->rootView->file_exists($v1Renamed));
|
||||
$this->assertTrue($this->rootView->file_exists($v2Renamed));
|
||||
|
||||
\OC::$server->getShareManager()->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testMoveFolderIntoSharedFolderAsRecipient() {
|
||||
|
||||
\OC\Files\Filesystem::mkdir('folder1');
|
||||
$fileInfo = \OC\Files\Filesystem::getFileInfo('folder1');
|
||||
|
||||
\OCP\Share::shareItem(
|
||||
'folder',
|
||||
$fileInfo['fileid'],
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_VERSIONS_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
|
||||
$share = \OC::$server->getShareManager()->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedBy(self::TEST_VERSIONS_USER)
|
||||
->setSharedWith(self::TEST_VERSIONS_USER2)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$share = \OC::$server->getShareManager()->createShare($share);
|
||||
|
||||
self::loginHelper(self::TEST_VERSIONS_USER2);
|
||||
$versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions';
|
||||
|
@ -462,14 +472,14 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
|
||||
$this->assertTrue($this->rootView->file_exists($v1Renamed));
|
||||
$this->assertTrue($this->rootView->file_exists($v2Renamed));
|
||||
|
||||
\OC::$server->getShareManager()->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testRenameSharedFile() {
|
||||
|
||||
\OC\Files\Filesystem::file_put_contents("test.txt", "test file");
|
||||
|
||||
$fileInfo = \OC\Files\Filesystem::getFileInfo('test.txt');
|
||||
|
||||
$t1 = time();
|
||||
// second version is two weeks older, this way we make sure that no
|
||||
// version will be expired
|
||||
|
@ -486,7 +496,14 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
$this->rootView->file_put_contents($v1, 'version1');
|
||||
$this->rootView->file_put_contents($v2, 'version2');
|
||||
|
||||
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
|
||||
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('test.txt');
|
||||
$share = \OC::$server->getShareManager()->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedBy(self::TEST_VERSIONS_USER)
|
||||
->setSharedWith(self::TEST_VERSIONS_USER2)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
|
||||
$share = \OC::$server->getShareManager()->createShare($share);
|
||||
|
||||
self::loginHelper(self::TEST_VERSIONS_USER2);
|
||||
|
||||
|
@ -504,6 +521,8 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
|
||||
$this->assertFalse($this->rootView->file_exists($v1Renamed));
|
||||
$this->assertFalse($this->rootView->file_exists($v2Renamed));
|
||||
|
||||
\OC::$server->getShareManager()->deleteShare($share);
|
||||
}
|
||||
|
||||
public function testCopy() {
|
||||
|
@ -744,15 +763,15 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
|
||||
\OC\Files\Filesystem::mkdir('folder');
|
||||
\OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
|
||||
$fileInfo = \OC\Files\Filesystem::getFileInfo('folder');
|
||||
|
||||
\OCP\Share::shareItem(
|
||||
'folder',
|
||||
$fileInfo['fileid'],
|
||||
\OCP\Share::SHARE_TYPE_USER,
|
||||
self::TEST_VERSIONS_USER2,
|
||||
\OCP\Constants::PERMISSION_ALL
|
||||
);
|
||||
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder');
|
||||
$share = \OC::$server->getShareManager()->newShare();
|
||||
$share->setNode($node)
|
||||
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setSharedBy(self::TEST_VERSIONS_USER)
|
||||
->setSharedWith(self::TEST_VERSIONS_USER2)
|
||||
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
||||
$share = \OC::$server->getShareManager()->createShare($share);
|
||||
|
||||
$this->loginAsUser(self::TEST_VERSIONS_USER2);
|
||||
|
||||
|
@ -760,6 +779,8 @@ class Test_Files_Versioning extends \Test\TestCase {
|
|||
\OC\Files\Filesystem::getView(),
|
||||
'folder/test.txt'
|
||||
);
|
||||
|
||||
\OC::$server->getShareManager()->deleteShare($share);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -647,7 +647,7 @@ class ManagerTest extends \Test\TestCase {
|
|||
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true];
|
||||
$data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true];
|
||||
|
||||
$nonMoveableMountPermssions = $this->getMock('\OCP\Files\File');
|
||||
$nonMoveableMountPermssions = $this->getMock('\OCP\Files\Folder');
|
||||
$nonMoveableMountPermssions->method('isShareable')->willReturn(true);
|
||||
$nonMoveableMountPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ);
|
||||
$nonMoveableMountPermssions->method('getPath')->willReturn('path');
|
||||
|
@ -2477,7 +2477,9 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
public function testMoveShareUser() {
|
||||
$share = $this->manager->newShare();
|
||||
$share->setShareType(\OCP\Share::SHARE_TYPE_USER);
|
||||
$share->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
||||
->setId('42')
|
||||
->setProviderId('foo');
|
||||
|
||||
$share->setSharedWith('recipient');
|
||||
|
||||
|
@ -2508,7 +2510,9 @@ class ManagerTest extends \Test\TestCase {
|
|||
|
||||
public function testMoveShareGroup() {
|
||||
$share = $this->manager->newShare();
|
||||
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
|
||||
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
|
||||
->setId('42')
|
||||
->setProviderId('foo');
|
||||
|
||||
$group = $this->getMock('\OCP\IGroup');
|
||||
$share->setSharedWith('group');
|
||||
|
|
Loading…
Reference in New Issue