diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-08-13 20:22:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-13 20:22:47 +0200 |
commit | 34868f09644b4b63559d1d9ce072dbed7802c620 (patch) | |
tree | 6a01ae374a8847ce10a01d9d1a505d067a25da6d /apps/dav/tests | |
parent | 3a99ef30dfa6a49ef0c5f4c0515a98e55c43dbe4 (diff) | |
parent | a85392615d74f08a8ec62eca5d9ccc94294d89ec (diff) | |
download | nextcloud-server-34868f09644b4b63559d1d9ce072dbed7802c620.tar.gz nextcloud-server-34868f09644b4b63559d1d9ce072dbed7802c620.zip |
Merge pull request #14429 from tobiasKaminsky/shareesOnDav
Show sharees via propfind
Diffstat (limited to 'apps/dav/tests')
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php | 104 |
1 files changed, 39 insertions, 65 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php index d4dd3b49f34..af8208791e0 100644 --- a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php @@ -68,28 +68,17 @@ class SharesPluginTest extends \Test\TestCase { public function setUp() { parent::setUp(); $this->server = new \Sabre\DAV\Server(); - $this->tree = $this->getMockBuilder(Tree::class) - ->disableOriginalConstructor() - ->getMock(); - $this->shareManager = $this->getMockBuilder(IManager::class) - ->disableOriginalConstructor() - ->getMock(); - $user = $this->getMockBuilder(IUser::class) - ->disableOriginalConstructor() - ->getMock(); + $this->tree = $this->createMock(Tree::class); + $this->shareManager = $this->createMock(IManager::class); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getUID') ->will($this->returnValue('user1')); - $userSession = $this->getMockBuilder(IUserSession::class) - ->disableOriginalConstructor() - ->getMock(); + $userSession = $this->createMock(IUserSession::class); $userSession->expects($this->once()) ->method('getUser') ->will($this->returnValue($user)); - - $this->userFolder = $this->getMockBuilder(Folder::class) - ->disableOriginalConstructor() - ->getMock(); + $this->userFolder = $this->createMock(Folder::class); $this->plugin = new \OCA\DAV\Connector\Sabre\SharesPlugin( $this->tree, @@ -131,11 +120,14 @@ class SharesPluginTest extends \Test\TestCase { $this->anything(), $this->anything(), $this->equalTo(false), - $this->equalTo(1) + $this->equalTo(-1) ) ->will($this->returnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes){ if (in_array($requestedShareType, $shareTypes)) { - return ['dummyshare']; + $share = $this->createMock(IShare::class); + $share->method('getShareType') + ->willReturn($requestedShareType); + return [$share]; } return []; })); @@ -162,30 +154,18 @@ class SharesPluginTest extends \Test\TestCase { * @dataProvider sharesGetPropertiesDataProvider */ public function testPreloadThenGetProperties($shareTypes) { - $sabreNode1 = $this->getMockBuilder(File::class) - ->disableOriginalConstructor() - ->getMock(); - $sabreNode1->expects($this->any()) - ->method('getId') - ->will($this->returnValue(111)); - $sabreNode1->expects($this->any()) - ->method('getPath'); - $sabreNode2 = $this->getMockBuilder(File::class) - ->disableOriginalConstructor() - ->getMock(); - $sabreNode2->expects($this->any()) - ->method('getId') - ->will($this->returnValue(222)); - $sabreNode2->expects($this->any()) - ->method('getPath') - ->will($this->returnValue('/subdir/foo')); + $sabreNode1 = $this->createMock(File::class); + $sabreNode1->method('getId') + ->willReturn(111); + $sabreNode2 = $this->createMock(File::class); + $sabreNode2->method('getId') + ->willReturn(222); + $sabreNode2->method('getPath') + ->willReturn('/subdir/foo'); - $sabreNode = $this->getMockBuilder(Directory::class) - ->disableOriginalConstructor() - ->getMock(); - $sabreNode->expects($this->any()) - ->method('getId') - ->will($this->returnValue(123)); + $sabreNode = $this->createMock(Directory::class); + $sabreNode->method('getId') + ->willReturn(123); // never, because we use getDirectoryListing from the Node API instead $sabreNode->expects($this->never()) ->method('getChildren'); @@ -194,29 +174,19 @@ class SharesPluginTest extends \Test\TestCase { ->will($this->returnValue('/subdir')); // node API nodes - $node = $this->getMockBuilder(Folder::class) - ->disableOriginalConstructor() - ->getMock(); - $node->expects($this->any()) - ->method('getId') - ->will($this->returnValue(123)); - $node1 = $this->getMockBuilder(File::class) - ->disableOriginalConstructor() - ->getMock(); - $node1->expects($this->any()) - ->method('getId') - ->will($this->returnValue(111)); - $node2 = $this->getMockBuilder(File::class) - ->disableOriginalConstructor() - ->getMock(); - $node2->expects($this->any()) - ->method('getId') - ->will($this->returnValue(222)); + $node = $this->createMock(Folder::class); + $node->method('getId') + ->willReturn(123); + $node1 = $this->createMock(File::class); + $node1->method('getId') + ->willReturn(111); + $node2 = $this->createMock(File::class); + $node2->method('getId') + ->willReturn(222); - $this->userFolder->expects($this->once()) - ->method('get') + $this->userFolder->method('get') ->with('/subdir') - ->will($this->returnValue($node)); + ->willReturn($node); $dummyShares = array_map(function($type) { $share = $this->getMockBuilder(IShare::class)->getMock(); @@ -233,11 +203,15 @@ class SharesPluginTest extends \Test\TestCase { $this->anything(), $this->anything(), $this->equalTo(false), - $this->equalTo(1) + $this->equalTo(-1) ) - ->will($this->returnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes){ + ->will($this->returnCallback(function($userId, $requestedShareType, $node, $flag, $limit) use ($shareTypes, $dummyShares){ if ($node->getId() === 111 && in_array($requestedShareType, $shareTypes)) { - return ['dummyshare']; + foreach ($dummyShares as $dummyShare) { + if ($dummyShare->getShareType() === $requestedShareType) { + return [$dummyShare]; + } + } } return []; |