summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-25 15:25:50 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-11-25 15:25:50 +0100
commit9ec2f8886e129d87f58baacfbb625d8ef9d4e58c (patch)
treec57c58e881e913bc0e37c2436594b46ddf613344 /tests
parentafe76840f8806e5fbbdf785cfa8b8857c57c702e (diff)
parent8d309767d7a48a7fe1dd23fd79bc827c29f94931 (diff)
downloadnextcloud-server-9ec2f8886e129d87f58baacfbb625d8ef9d4e58c.tar.gz
nextcloud-server-9ec2f8886e129d87f58baacfbb625d8ef9d4e58c.zip
Merge pull request #20691 from owncloud/share2.0_di_fixes
[Sharing 2.0] di fixes
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/share20/defaultshareprovidertest.php246
-rw-r--r--tests/lib/share20/managertest.php117
2 files changed, 108 insertions, 255 deletions
diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php
index 4c0b5523947..dc45bc7c085 100644
--- a/tests/lib/share20/defaultshareprovidertest.php
+++ b/tests/lib/share20/defaultshareprovidertest.php
@@ -23,7 +23,7 @@ namespace Test\Share20;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\IGroupManager;
-use OCP\Files\Folder;
+use OCP\Files\IRootFolder;
use OC\Share20\DefaultShareProvider;
class DefaultShareProviderTest extends \Test\TestCase {
@@ -37,8 +37,8 @@ class DefaultShareProviderTest extends \Test\TestCase {
/** @var IGroupManager */
protected $groupManager;
- /** @var Folder */
- protected $userFolder;
+ /** @var IRootFolder */
+ protected $rootFolder;
/** @var DefaultShareProvider */
protected $provider;
@@ -47,7 +47,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->dbConn = \OC::$server->getDatabaseConnection();
$this->userManager = $this->getMock('OCP\IUserManager');
$this->groupManager = $this->getMock('OCP\IGroupManager');
- $this->userFolder = $this->getMock('OCP\Files\Folder');
+ $this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
//Empty share table
$this->dbConn->getQueryBuilder()->delete('share')->execute();
@@ -56,7 +56,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->dbConn,
$this->userManager,
$this->groupManager,
- $this->userFolder
+ $this->rootFolder
);
}
@@ -65,7 +65,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
}
/**
- * @expectedException OC\Share20\Exception\ShareNotFound
+ * @expectedException \OC\Share20\Exception\ShareNotFound
*/
public function testGetShareByIdNotExist() {
$this->provider->getShareById(1);
@@ -97,25 +97,30 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $id['id'];
$cursor->closeCursor();
- $storage = $this->getMock('OC\Files\Storage\Storage');
- $storage
- ->expects($this->once())
- ->method('getOwner')
- ->willReturn('shareOwner');
- $path = $this->getMock('OCP\Files\File');
- $path
- ->expects($this->once())
- ->method('getStorage')
- ->wilLReturn($storage);
- $this->userFolder
- ->expects($this->once())
- ->method('getById')
- ->with(42)
- ->willReturn([$path]);
-
$sharedWith = $this->getMock('OCP\IUser');
$sharedBy = $this->getMock('OCP\IUser');
+ $sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
+
+ $sharedByPath = $this->getMock('\OCP\Files\File');
+ $ownerPath = $this->getMock('\OCP\Files\File');
+
+ $sharedByPath->method('getOwner')->willReturn($shareOwner);
+
+ $sharedByFolder = $this->getMock('\OCP\Files\Folder');
+ $sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
+
+ $shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
+ $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
+
+ $this->rootFolder
+ ->method('getUserFolder')
+ ->will($this->returnValueMap([
+ ['sharedBy', $sharedByFolder],
+ ['shareOwner', $shareOwnerFolder],
+ ]));
+
$this->userManager
->method('get')
->will($this->returnValueMap([
@@ -131,7 +136,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($sharedWith, $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner());
- $this->assertEquals($path, $share->getPath());
+ $this->assertEquals($ownerPath, $share->getPath());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate());
@@ -164,25 +169,30 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $id['id'];
$cursor->closeCursor();
- $storage = $this->getMock('OC\Files\Storage\Storage');
- $storage
- ->expects($this->once())
- ->method('getOwner')
- ->willReturn('shareOwner');
- $path = $this->getMock('OCP\Files\Folder');
- $path
- ->expects($this->once())
- ->method('getStorage')
- ->wilLReturn($storage);
- $this->userFolder
- ->expects($this->once())
- ->method('getById')
- ->with(42)
- ->willReturn([$path]);
-
$sharedWith = $this->getMock('OCP\IGroup');
$sharedBy = $this->getMock('OCP\IUser');
+ $sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
+
+ $sharedByPath = $this->getMock('\OCP\Files\Folder');
+ $ownerPath = $this->getMock('\OCP\Files\Folder');
+
+ $sharedByPath->method('getOwner')->willReturn($shareOwner);
+
+ $sharedByFolder = $this->getMock('\OCP\Files\Folder');
+ $sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
+
+ $shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
+ $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
+
+ $this->rootFolder
+ ->method('getUserFolder')
+ ->will($this->returnValueMap([
+ ['sharedBy', $sharedByFolder],
+ ['shareOwner', $shareOwnerFolder],
+ ]));
+
$this->userManager
->method('get')
->will($this->returnValueMap([
@@ -202,7 +212,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($sharedWith, $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner());
- $this->assertEquals($path, $share->getPath());
+ $this->assertEquals($ownerPath, $share->getPath());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate());
@@ -237,90 +247,29 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $id['id'];
$cursor->closeCursor();
- $storage = $this->getMock('OC\Files\Storage\Storage');
- $storage
- ->expects($this->once())
- ->method('getOwner')
- ->willReturn('shareOwner');
- $path = $this->getMock('OCP\Files\Node');
- $path
- ->expects($this->once())
- ->method('getStorage')
- ->wilLReturn($storage);
- $this->userFolder
- ->expects($this->once())
- ->method('getById')
- ->with(42)
- ->willReturn([$path]);
-
$sharedBy = $this->getMock('OCP\IUser');
+ $sharedBy->method('getUID')->willReturn('sharedBy');
$shareOwner = $this->getMock('OCP\IUser');
- $this->userManager
- ->method('get')
- ->will($this->returnValueMap([
- ['sharedBy', $sharedBy],
- ['shareOwner', $shareOwner],
- ]));
-
- $share = $this->provider->getShareById($id);
-
- $this->assertEquals($id, $share->getId());
- $this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType());
- $this->assertEquals('sharedWith', $share->getPassword());
- $this->assertEquals($sharedBy, $share->getSharedBy());
- $this->assertEquals($shareOwner, $share->getShareOwner());
- $this->assertEquals($path, $share->getPath());
- $this->assertEquals(13, $share->getPermissions());
- $this->assertEquals('token', $share->getToken());
- $this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate());
- $this->assertEquals('myTarget', $share->getTarget());
- }
+ $shareOwner->method('getUID')->willReturn('shareOwner');
- public function testGetShareByIdRemoteShare() {
- $qb = $this->dbConn->getQueryBuilder();
+ $sharedByPath = $this->getMock('\OCP\Files\Folder');
+ $ownerPath = $this->getMock('\OCP\Files\Folder');
- $qb->insert('share')
- ->values([
- 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_REMOTE),
- 'share_with' => $qb->expr()->literal('sharedWith'),
- 'uid_owner' => $qb->expr()->literal('sharedBy'),
- 'item_type' => $qb->expr()->literal('file'),
- 'file_source' => $qb->expr()->literal(42),
- 'file_target' => $qb->expr()->literal('myTarget'),
- 'permissions' => $qb->expr()->literal(13),
- ]);
- $this->assertEquals(1, $qb->execute());
+ $sharedByPath->method('getOwner')->willReturn($shareOwner);
- // Get the id
- $qb = $this->dbConn->getQueryBuilder();
- $cursor = $qb->select('id')
- ->from('share')
- ->setMaxResults(1)
- ->orderBy('id', 'DESC')
- ->execute();
- $id = $cursor->fetch();
- $id = $id['id'];
- $cursor->closeCursor();
+ $sharedByFolder = $this->getMock('\OCP\Files\Folder');
+ $sharedByFolder->method('getById')->with(42)->willReturn([$sharedByPath]);
+ $shareOwnerFolder = $this->getMock('\OCP\Files\Folder');
+ $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]);
- $storage = $this->getMock('OC\Files\Storage\Storage');
- $storage
- ->expects($this->once())
- ->method('getOwner')
- ->willReturn('shareOwner');
- $path = $this->getMock('OCP\Files\Node');
- $path
- ->expects($this->once())
- ->method('getStorage')
- ->wilLReturn($storage);
- $this->userFolder
- ->expects($this->once())
- ->method('getById')
- ->with(42)
- ->willReturn([$path]);
+ $this->rootFolder
+ ->method('getUserFolder')
+ ->will($this->returnValueMap([
+ ['sharedBy', $sharedByFolder],
+ ['shareOwner', $shareOwnerFolder],
+ ]));
- $sharedBy = $this->getMock('OCP\IUser');
- $shareOwner = $this->getMock('OCP\IUser');
$this->userManager
->method('get')
->will($this->returnValueMap([
@@ -331,14 +280,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$share = $this->provider->getShareById($id);
$this->assertEquals($id, $share->getId());
- $this->assertEquals(\OCP\Share::SHARE_TYPE_REMOTE, $share->getShareType());
- $this->assertEquals('sharedWith', $share->getSharedWith());
+ $this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType());
+ $this->assertEquals('sharedWith', $share->getPassword());
$this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner());
- $this->assertEquals($path, $share->getPath());
+ $this->assertEquals($ownerPath, $share->getPath());
$this->assertEquals(13, $share->getPermissions());
- $this->assertEquals(null, $share->getToken());
- $this->assertEquals(null, $share->getExpirationDate());
+ $this->assertEquals('token', $share->getToken());
+ $this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate());
$this->assertEquals('myTarget', $share->getTarget());
}
@@ -376,7 +325,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->dbConn,
$this->userManager,
$this->groupManager,
- $this->userFolder,
+ $this->rootFolder,
]
)
->setMethods(['getShareById'])
@@ -437,7 +386,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$db,
$this->userManager,
$this->groupManager,
- $this->userFolder,
+ $this->rootFolder,
]
)
->setMethods(['getShareById'])
@@ -504,30 +453,45 @@ class DefaultShareProviderTest extends \Test\TestCase {
]);
$qb->execute();
+ $shareOwner = $this->getMock('OCP\IUser');
+ $shareOwner->method('getUID')->willReturn('shareOwner');
+ $user1 = $this->getMock('OCP\IUser');
+ $user2 = $this->getMock('OCP\IUser');
+ $user2->method('getUID')->willReturn('user2');
+ $user3 = $this->getMock('OCP\IUser');
+ $user3->method('getUID')->willReturn('user3');
+
+ $user2Path = $this->getMock('\OCP\Files\File');
+ $user2Path->expects($this->once())->method('getOwner')->willReturn($shareOwner);
+ $user2Folder = $this->getMock('\OCP\Files\Folder');
+ $user2Folder->expects($this->once())
+ ->method('getById')
+ ->with(1)
+ ->willReturn([$user2Path]);
- $storage = $this->getMock('OC\Files\Storage\Storage');
- $storage
- ->method('getOwner')
- ->willReturn('shareOwner');
- $path1 = $this->getMock('OCP\Files\File');
- $path1->expects($this->once())->method('getStorage')->willReturn($storage);
- $path2 = $this->getMock('OCP\Files\Folder');
- $path2->expects($this->once())->method('getStorage')->willReturn($storage);
- $this->userFolder
+ $user3Path = $this->getMock('\OCP\Files\Folder');
+ $user3Path->expects($this->once())->method('getOwner')->willReturn($shareOwner);
+ $user3Folder = $this->getMock('\OCP\Files\Folder');
+ $user3Folder->expects($this->once())
->method('getById')
+ ->with(3)
+ ->willReturn([$user3Path]);
+
+ $ownerPath = $this->getMock('\OCP\Files\Folder');
+ $ownerFolder = $this->getMock('\OCP\Files\Folder');
+ $ownerFolder->method('getById')->willReturn([$ownerPath]);
+
+ $this->rootFolder
+ ->method('getUserFolder')
->will($this->returnValueMap([
- [1, [$path1]],
- [3, [$path2]],
+ ['shareOwner', $ownerFolder],
+ ['user2', $user2Folder],
+ ['user3', $user3Folder],
]));
- $shareOwner = $this->getMock('OCP\IUser');
- $user1 = $this->getMock('OCP\IUser');
- $user2 = $this->getMock('OCP\IUser');
- $user3 = $this->getMock('OCP\IUser');
$this->userManager
->method('get')
->will($this->returnValueMap([
- ['shareOwner', $shareOwner],
['user1', $user1],
['user2', $user2],
['user3', $user3],
@@ -552,7 +516,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($user1, $children[0]->getSharedWith());
$this->assertEquals($user2, $children[0]->getSharedBy());
$this->assertEquals($shareOwner, $children[0]->getShareOwner());
- $this->assertEquals($path1, $children[0]->getPath());
+ $this->assertEquals($ownerPath, $children[0]->getPath());
$this->assertEquals(2, $children[0]->getPermissions());
$this->assertEquals(null, $children[0]->getToken());
$this->assertEquals(null, $children[0]->getExpirationDate());
@@ -563,7 +527,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals($group1, $children[1]->getSharedWith());
$this->assertEquals($user3, $children[1]->getSharedBy());
$this->assertEquals($shareOwner, $children[1]->getShareOwner());
- $this->assertEquals($path2, $children[1]->getPath());
+ $this->assertEquals($ownerPath, $children[1]->getPath());
$this->assertEquals(4, $children[1]->getPermissions());
$this->assertEquals(null, $children[1]->getToken());
$this->assertEquals(null, $children[1]->getExpirationDate());
diff --git a/tests/lib/share20/managertest.php b/tests/lib/share20/managertest.php
index 54be9033567..e4d0bfad584 100644
--- a/tests/lib/share20/managertest.php
+++ b/tests/lib/share20/managertest.php
@@ -23,64 +23,39 @@ namespace Test\Share20;
use OC\Share20\Manager;
use OC\Share20\Exception;
-
-use OCP\IUser;
-use OCP\IUserManager;
-use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IAppConfig;
-use OCP\Files\Folder;
-use OCP\Share20\IShareProvider;
+use OC\Share20\IShareProvider;
class ManagerTest extends \Test\TestCase {
/** @var Manager */
protected $manager;
- /** @var IUser */
- protected $user;
-
- /** @var IUserManager */
- protected $userManager;
-
- /** @var IGroupManager */
- protected $groupManager;
-
/** @var ILogger */
protected $logger;
/** @var IAppConfig */
protected $appConfig;
- /** @var Folder */
- protected $userFolder;
-
/** @var IShareProvider */
protected $defaultProvider;
public function setUp() {
- $this->user = $this->getMock('\OCP\IUser');
- $this->userManager = $this->getMock('\OCP\IUserManager');
- $this->groupManager = $this->getMock('\OCP\IGroupManager');
$this->logger = $this->getMock('\OCP\ILogger');
$this->appConfig = $this->getMock('\OCP\IAppConfig');
- $this->userFolder = $this->getMock('\OCP\Files\Folder');
$this->defaultProvider = $this->getMock('\OC\Share20\IShareProvider');
$this->manager = new Manager(
- $this->user,
- $this->userManager,
- $this->groupManager,
$this->logger,
$this->appConfig,
- $this->userFolder,
$this->defaultProvider
);
}
/**
- * @expectedException OC\Share20\Exception\ShareNotFound
+ * @expectedException \OC\Share20\Exception\ShareNotFound
*/
public function testDeleteNoShareId() {
$share = $this->getMock('\OC\Share20\IShare');
@@ -115,12 +90,8 @@ class ManagerTest extends \Test\TestCase {
public function testDelete($shareType, $sharedWith, $sharedWith_string) {
$manager = $this->getMockBuilder('\OC\Share20\Manager')
->setConstructorArgs([
- $this->user,
- $this->userManager,
- $this->groupManager,
$this->logger,
$this->appConfig,
- $this->userFolder,
$this->defaultProvider
])
->setMethods(['getShareById', 'deleteChildren'])
@@ -205,12 +176,8 @@ class ManagerTest extends \Test\TestCase {
public function testDeleteNested() {
$manager = $this->getMockBuilder('\OC\Share20\Manager')
->setConstructorArgs([
- $this->user,
- $this->userManager,
- $this->groupManager,
$this->logger,
$this->appConfig,
- $this->userFolder,
$this->defaultProvider
])
->setMethods(['getShareById'])
@@ -349,12 +316,8 @@ class ManagerTest extends \Test\TestCase {
public function testDeleteChildren() {
$manager = $this->getMockBuilder('\OC\Share20\Manager')
->setConstructorArgs([
- $this->user,
- $this->userManager,
- $this->groupManager,
$this->logger,
$this->appConfig,
- $this->userFolder,
$this->defaultProvider
])
->setMethods(['deleteShare'])
@@ -391,82 +354,8 @@ class ManagerTest extends \Test\TestCase {
$this->assertSame($shares, $result);
}
- /**
- * @expectedException OC\Share20\Exception\ShareNotFound
- */
- public function testGetShareByIdNotFoundInBackend() {
- $this->defaultProvider
- ->expects($this->once())
- ->method('getShareById')
- ->with(42)
- ->will($this->throwException(new \OC\Share20\Exception\ShareNotFound()));
-
- $this->manager->getShareById(42);
- }
-
- /**
- * @expectedException OC\Share20\Exception\ShareNotFound
- */
- public function testGetShareByIdNotAuthorized() {
- $otherUser1 = $this->getMock('\OCP\IUser');
- $otherUser2 = $this->getMock('\OCP\IUser');
- $otherUser3 = $this->getMock('\OCP\IUser');
-
+ public function testGetShareById() {
$share = $this->getMock('\OC\Share20\IShare');
- $share
- ->expects($this->once())
- ->method('getSharedWith')
- ->with()
- ->willReturn($otherUser1);
- $share
- ->expects($this->once())
- ->method('getSharedBy')
- ->with()
- ->willReturn($otherUser2);
- $share
- ->expects($this->once())
- ->method('getShareOwner')
- ->with()
- ->willReturn($otherUser3);
-
- $this->defaultProvider
- ->expects($this->once())
- ->method('getShareById')
- ->with(42)
- ->willReturn($share);
-
- $this->manager->getShareById(42);
- }
-
- public function dataGetShareById() {
- return [
- ['getSharedWith'],
- ['getSharedBy'],
- ['getShareOwner'],
- ];
- }
-
- /**
- * @dataProvider dataGetShareById
- */
- public function testGetShareById($currentUserIs) {
- $otherUser1 = $this->getMock('\OCP\IUser');
- $otherUser2 = $this->getMock('\OCP\IUser');
- $otherUser3 = $this->getMock('\OCP\IUser');
-
- $share = $this->getMock('\OC\Share20\IShare');
- $share
- ->method('getSharedWith')
- ->with()
- ->willReturn($currentUserIs === 'getSharedWith' ? $this->user : $otherUser1);
- $share
- ->method('getSharedBy')
- ->with()
- ->willReturn($currentUserIs === 'getSharedBy' ? $this->user : $otherUser2);
- $share
- ->method('getShareOwner')
- ->with()
- ->willReturn($currentUserIs === 'getShareOwner' ? $this->user : $otherUser3);
$this->defaultProvider
->expects($this->once())