summaryrefslogtreecommitdiffstats
path: root/tests/lib/Share20
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-01-04 09:13:08 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2017-04-13 12:58:50 +0200
commit4437e00f162f74b6a8aad4ac5c1376099af0c194 (patch)
tree11e7104fd0d62a0fe0b2e25bb4130ce9be22703a /tests/lib/Share20
parent12afd7d1d5bc2a85d04815964bf7fb37e77466d6 (diff)
downloadnextcloud-server-4437e00f162f74b6a8aad4ac5c1376099af0c194.tar.gz
nextcloud-server-4437e00f162f74b6a8aad4ac5c1376099af0c194.zip
Add shareHelper test
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/lib/Share20')
-rw-r--r--tests/lib/Share20/ShareHelperTests.php94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/lib/Share20/ShareHelperTests.php b/tests/lib/Share20/ShareHelperTests.php
new file mode 100644
index 00000000000..b6c737cf444
--- /dev/null
+++ b/tests/lib/Share20/ShareHelperTests.php
@@ -0,0 +1,94 @@
+<?php
+/**
+ * @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace Test\Share20;
+
+use OC\Share20\ShareHelper;
+use OCP\Files\Folder;
+use OCP\Files\IRootFolder;
+use OCP\Files\Node;
+use OCP\Files\NotFoundException;
+use Test\TestCase;
+
+class ShareHelperTests extends TestCase {
+
+ /** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */
+ private $rootFolder;
+
+ /** @var ShareHelper */
+ private $helper;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->rootFolder = $this->createMock(IRootFolder::class);
+
+ $this->helper = new ShareHelper($this->rootFolder);
+ }
+
+ /**
+ * uid1 - Exists with valid node
+ * uid2 - Does not exist
+ * uid3 - Exists but no valid node
+ * uid4 - Exists with valid node
+ */
+ public function testGetPathsForAccessList() {
+ /** @var Folder[]|\PHPUnit_Framework_MockObject_MockObject[] $userFolder */
+ $userFolder = [
+ 'uid1' => $this->createMock(Folder::class),
+ 'uid3' => $this->createMock(Folder::class),
+ 'uid4' => $this->createMock(Folder::class),
+ ];
+
+ $this->rootFolder->method('getUserFolder')
+ ->willReturnCallback(function($uid) use ($userFolder) {
+ if (isset($userFolder[$uid])) {
+ return $userFolder[$uid];
+ }
+ throw new NotFoundException();
+ });
+
+ /** @var Node|\PHPUnit_Framework_MockObject_MockObject $node */
+ $node = $this->createMock(Node::class);
+ $node->method('getId')
+ ->willReturn(42);
+
+ $userFolder['uid1']->method('getById')
+ ->with(42)
+ ->willReturn([$node]);
+ $userFolder['uid3']->method('getById')
+ ->with(42)
+ ->willReturn([]);
+ $userFolder['uid4']->method('getById')
+ ->with(42)
+ ->willReturn([$node]);
+
+ $expects = [
+ 'uid1' => [$node],
+ 'uid4' => [$node],
+ ];
+
+ $result = $this->helper->getPathsForAccessList($node, ['uid1', 'uid2', 'uid3', 'uid4']);
+
+ $this->assertSame($expects, $result);
+ }
+}