Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrow4a committed Jan 31, 2019
1 parent 0a00dff commit 22b55cd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1384,9 +1384,8 @@ public function getAccessList(\OCP\Files\Node $path) {
* @return \OCP\Share\IShare;
*/
public function newShare() {
$extraPermissions = new ExtraPermissions();
$share = new Share($this->rootFolder, $this->userManager);
$share->setExtraPermissions($extraPermissions);
$share->setExtraPermissions(new ExtraPermissions());
return $share;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use OC\Authentication\Token\DefaultTokenMapper;
use OC\Share20\DefaultShareProvider;
use OCP\Share\IExtraPermissions;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\File;
use OCP\Files\Folder;
Expand Down Expand Up @@ -657,6 +658,28 @@ public function testGetChildren() {
$this->assertEquals('myTarget2', $children[1]->getTarget());
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject | IExtraPermissions
*/
private function createExtraPermissions() {
$extraPermissions = $this->createMock(IExtraPermissions::class);
$extraPermissions->method('getApps')
->with()
->willReturn(['app1']);
$extraPermissions->method('getKeys')
->with('app1')
->willReturn(['perm1', 'perm2']);
$extraPermissions->method('getPermission')
->willReturn(true);

return $extraPermissions;
}

private function assertExtraPermissions(IShare $share) {
$this->assertSame(['app1'], $share->getExtraPermissions()->getApps());
$this->assertSame(['perm1', 'perm2'], $share->getExtraPermissions()->getKeys('app1'));
}

public function testCreateUserShare() {
$share = new \OC\Share20\Share($this->rootFolder, $this->userManager);

Expand Down Expand Up @@ -689,6 +712,9 @@ public function testCreateUserShare() {
$share->setShareOwner('shareOwner');
$share->setNode($path);
$share->setPermissions(1);
$share->setExtraPermissions(
$this->createExtraPermissions()
);
$share->setTarget('/target');

$share2 = $this->provider->create($share);
Expand All @@ -700,6 +726,7 @@ public function testCreateUserShare() {
$this->assertSame('sharedBy', $share2->getSharedBy());
$this->assertSame('shareOwner', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertExtraPermissions($share2);
$this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getNode());
Expand Down Expand Up @@ -737,6 +764,9 @@ public function testCreateGroupShare() {
$share->setShareOwner('shareOwner');
$share->setNode($path);
$share->setPermissions(1);
$share->setExtraPermissions(
$this->createExtraPermissions()
);
$share->setTarget('/target');

$share2 = $this->provider->create($share);
Expand All @@ -748,6 +778,7 @@ public function testCreateGroupShare() {
$this->assertSame('sharedBy', $share2->getSharedBy());
$this->assertSame('shareOwner', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertExtraPermissions($share2);
$this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getNode());
Expand Down Expand Up @@ -784,6 +815,9 @@ public function testCreateLinkShare() {
$share->setShareOwner('shareOwner');
$share->setNode($path);
$share->setPermissions(1);
$share->setExtraPermissions(
$this->createExtraPermissions()
);
$share->setPassword('password');
$share->setToken('token');
$share->setName('some_name');
Expand All @@ -799,6 +833,7 @@ public function testCreateLinkShare() {
$this->assertSame('sharedBy', $share2->getSharedBy());
$this->assertSame('shareOwner', $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertExtraPermissions($share2);
$this->assertSame('/target', $share2->getTarget());
$this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
$this->assertSame($path, $share2->getNode());
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use OCP\Security\IHasher;
use OCP\Security\ISecureRandom;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IExtraPermissions;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
use OCP\Share\IShareProvider;
Expand Down Expand Up @@ -2343,6 +2344,7 @@ public function testCreateShareLink($shouldHashPassword) {
'error' => '',
'itemTarget' => '/target',
'shareWith' => null,
'extraPermissions' => $share->getExtraPermissions(),
];

$hookListnerExpectsPost = [
Expand All @@ -2359,6 +2361,7 @@ public function testCreateShareLink($shouldHashPassword) {
'fileTarget' => '/target',
'shareWith' => null,
'passwordEnabled' => true,
'extraPermissions' => $share->getExtraPermissions(),
];

$hookListner->expects($this->once())
Expand Down

0 comments on commit 22b55cd

Please sign in to comment.