Skip to content

Commit 76a0ddb

Browse files
committed
Add shareHelper test
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent ae6f748 commit 76a0ddb

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
4+
*
5+
* @author Roeland Jago Douma <roeland@famdouma.nl>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
namespace Test\Share20;
24+
25+
use OC\Share20\ShareHelper;
26+
use OCP\Files\Folder;
27+
use OCP\Files\IRootFolder;
28+
use OCP\Files\Node;
29+
use OCP\Files\NotFoundException;
30+
use Test\TestCase;
31+
32+
class ShareHelperTests extends TestCase {
33+
34+
/** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */
35+
private $rootFolder;
36+
37+
/** @var ShareHelper */
38+
private $helper;
39+
40+
public function setUp() {
41+
parent::setUp();
42+
43+
$this->rootFolder = $this->createMock(IRootFolder::class);
44+
45+
$this->helper = new ShareHelper($this->rootFolder);
46+
}
47+
48+
/**
49+
* uid1 - Exists with valid node
50+
* uid2 - Does not exist
51+
* uid3 - Exists but no valid node
52+
* uid4 - Exists with valid node
53+
*/
54+
public function testGetPathsForAccessList() {
55+
/** @var Folder[]|\PHPUnit_Framework_MockObject_MockObject[] $userFolder */
56+
$userFolder = [
57+
'uid1' => $this->createMock(Folder::class),
58+
'uid3' => $this->createMock(Folder::class),
59+
'uid4' => $this->createMock(Folder::class),
60+
];
61+
62+
$this->rootFolder->method('getUserFolder')
63+
->willReturnCallback(function($uid) use ($userFolder) {
64+
if (isset($userFolder[$uid])) {
65+
return $userFolder[$uid];
66+
}
67+
throw new NotFoundException();
68+
});
69+
70+
/** @var Node|\PHPUnit_Framework_MockObject_MockObject $node */
71+
$node = $this->createMock(Node::class);
72+
$node->method('getId')
73+
->willReturn(42);
74+
75+
$userFolder['uid1']->method('getById')
76+
->with(42)
77+
->willReturn([$node]);
78+
$userFolder['uid3']->method('getById')
79+
->with(42)
80+
->willReturn([]);
81+
$userFolder['uid4']->method('getById')
82+
->with(42)
83+
->willReturn([$node]);
84+
85+
$expects = [
86+
'uid1' => [$node],
87+
'uid4' => [$node],
88+
];
89+
90+
$result = $this->helper->getPathsForAccessList($node, ['uid1', 'uid2', 'uid3', 'uid4']);
91+
92+
$this->assertSame($expects, $result);
93+
}
94+
}

0 commit comments

Comments
 (0)