diff --git a/tests/lib/Share20/ShareHelperTests.php b/tests/lib/Share20/ShareHelperTests.php new file mode 100644 index 0000000000..b6c737cf44 --- /dev/null +++ b/tests/lib/Share20/ShareHelperTests.php @@ -0,0 +1,94 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ +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); + } +}