summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-04-11 14:45:02 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2017-04-13 12:58:53 +0200
commite1d54e3b48d68e3d631a6c6828b80ce49f414ea4 (patch)
treee58d2dfe647d4a4145b3b8c413a4c5059c838fd3
parent29f2088a7b83a2346ec440d7ffd4e577558fdd23 (diff)
downloadnextcloud-server-e1d54e3b48d68e3d631a6c6828b80ce49f414ea4.tar.gz
nextcloud-server-e1d54e3b48d68e3d631a6c6828b80ce49f414ea4.zip
Add more tests for the share helper
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--tests/lib/Share20/ShareHelperTest.php111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/lib/Share20/ShareHelperTest.php b/tests/lib/Share20/ShareHelperTest.php
index e2cd4ce038f..69609f9f724 100644
--- a/tests/lib/Share20/ShareHelperTest.php
+++ b/tests/lib/Share20/ShareHelperTest.php
@@ -24,6 +24,7 @@ namespace Test\Share20;
use OC\Share20\ShareHelper;
use OCP\Files\Node;
+use OCP\Files\NotFoundException;
use OCP\Share\IManager;
use Test\TestCase;
@@ -96,6 +97,116 @@ class ShareHelperTest extends TestCase {
$this->assertSame($expected, $helper->getPathsForAccessList($node));
}
+ public function dataGetPathsForUsers() {
+ return [
+ [[], [23 => 'TwentyThree', 42 => 'FortyTwo'], []],
+ [
+ [
+ 'test1' => ['node_id' => 16, 'node_path' => '/foo'],
+ 'test2' => ['node_id' => 23, 'node_path' => '/bar'],
+ 'test3' => ['node_id' => 42, 'node_path' => '/cat'],
+ 'test4' => ['node_id' => 48, 'node_path' => '/dog'],
+ ],
+ [16 => 'SixTeen', 23 => 'TwentyThree', 42 => 'FortyTwo'],
+ [
+ 'test1' => '/foo/TwentyThree/FortyTwo',
+ 'test2' => '/bar/FortyTwo',
+ 'test3' => '/cat',
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetPathsForUsers
+ *
+ * @param array $users
+ * @param array $nodes
+ * @param array $expected
+ */
+ public function testGetPathsForUsers(array $users, array $nodes, array $expected) {
+ $lastNode = null;
+ foreach ($nodes as $nodeId => $nodeName) {
+ /** @var Node|\PHPUnit_Framework_MockObject_MockObject $node */
+ $node = $this->createMock(Node::class);
+ $node->expects($this->any())
+ ->method('getId')
+ ->willReturn($nodeId);
+ $node->expects($this->any())
+ ->method('getName')
+ ->willReturn($nodeName);
+ if ($lastNode === null) {
+ $node->expects($this->any())
+ ->method('getParent')
+ ->willThrowException(new NotFoundException());
+ } else {
+ $node->expects($this->any())
+ ->method('getParent')
+ ->willReturn($lastNode);
+ }
+ $lastNode = $node;
+ }
+
+ $this->assertEquals($expected, self::invokePrivate($this->helper, 'getPathsForUsers', [$lastNode, $users]));
+ }
+
+ public function dataGetPathsForRemotes() {
+ return [
+ [[], [23 => 'TwentyThree', 42 => 'FortyTwo'], []],
+ [
+ [
+ 'test1' => ['node_id' => 16, 'token' => 't1'],
+ 'test2' => ['node_id' => 23, 'token' => 't2'],
+ 'test3' => ['node_id' => 42, 'token' => 't3'],
+ 'test4' => ['node_id' => 48, 'token' => 't4'],
+ ],
+ [
+ 16 => '/admin/files/SixTeen',
+ 23 => '/admin/files/SixTeen/TwentyThree',
+ 42 => '/admin/files/SixTeen/TwentyThree/FortyTwo',
+ ],
+ [
+ 'test1' => ['token' => 't1', 'node_path' => '/SixTeen'],
+ 'test2' => ['token' => 't2', 'node_path' => '/SixTeen/TwentyThree'],
+ 'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'],
+ ],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetPathsForRemotes
+ *
+ * @param array $remotes
+ * @param array $nodes
+ * @param array $expected
+ */
+ public function testGetPathsForRemotes(array $remotes, array $nodes, array $expected) {
+ $lastNode = null;
+ foreach ($nodes as $nodeId => $nodePath) {
+ /** @var Node|\PHPUnit_Framework_MockObject_MockObject $node */
+ $node = $this->createMock(Node::class);
+ $node->expects($this->any())
+ ->method('getId')
+ ->willReturn($nodeId);
+ $node->expects($this->any())
+ ->method('getPath')
+ ->willReturn($nodePath);
+ if ($lastNode === null) {
+ $node->expects($this->any())
+ ->method('getParent')
+ ->willThrowException(new NotFoundException());
+ } else {
+ $node->expects($this->any())
+ ->method('getParent')
+ ->willReturn($lastNode);
+ }
+ $lastNode = $node;
+ }
+
+ $this->assertEquals($expected, self::invokePrivate($this->helper, 'getPathsForRemotes', [$lastNode, $remotes]));
+ }
+
public function dataGetMountedPath() {
return [
['/admin/files/foobar', '/foobar'],