Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Jul 3, 2019
1 parent 99d1769 commit 32a46db
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@ public function testCreateShareUserNoShareWith() {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER);
}

Expand Down Expand Up @@ -791,6 +797,12 @@ public function testCreateShareUserNoValidShareWith() {
->with('invalidUser')
->willReturn(false);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, 'invalidUser');
}

Expand Down Expand Up @@ -839,6 +851,12 @@ public function testCreateShareUser() {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->shareManager->method('createShare')
->with($this->callback(function (\OCP\Share\IShare $share) use ($path) {
return $share->getNode() === $path &&
Expand Down Expand Up @@ -891,6 +909,12 @@ public function testCreateShareGroupNoValidShareWith() {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, 'invalidGroup');
}

Expand Down Expand Up @@ -952,6 +976,12 @@ public function testCreateShareGroup() {
->method('lock')
->with(\OCP\Lock\ILockingProvider::LOCK_SHARED);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->shareManager->method('createShare')
->with($this->callback(function (\OCP\Share\IShare $share) use ($path) {
return $share->getNode() === $path &&
Expand Down Expand Up @@ -1000,6 +1030,12 @@ public function testCreateShareGroupNotAllowed() {
->method('allowGroupSharing')
->willReturn(false);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, 'invalidGroup');
}

Expand All @@ -1026,6 +1062,12 @@ public function testCreateShareLinkNoLinksAllowed() {

$this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare());

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK);
}

Expand All @@ -1046,6 +1088,12 @@ public function testCreateShareLinkNoPublicUpload() {
$this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare());
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'true');
}

Expand All @@ -1067,6 +1115,12 @@ public function testCreateShareLinkPublicUploadFile() {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'true');
}

Expand Down Expand Up @@ -1097,6 +1151,12 @@ public function testCreateShareLinkPublicUploadFolder() {
})
)->will($this->returnArgument(0));

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$expected = new DataResponse([]);
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'true', '', null, '');

Expand Down Expand Up @@ -1131,6 +1191,12 @@ public function testCreateShareLinkPassword() {
})
)->will($this->returnArgument(0));

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$expected = new DataResponse([]);
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', 'password', null, '');

Expand Down Expand Up @@ -1168,6 +1234,12 @@ public function testCreateShareLinkSendPasswordByTalk() {
})
)->will($this->returnArgument(0));

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$expected = new DataResponse([]);
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', 'password', 'true', '');

Expand Down Expand Up @@ -1200,6 +1272,12 @@ public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled() {

$this->shareManager->expects($this->never())->method('createShare');

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', 'password', 'true', '');
}

Expand Down Expand Up @@ -1243,6 +1321,12 @@ public function testCreateShareValidExpireDate() {
})
)->will($this->returnArgument(0));

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$expected = new DataResponse([]);
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '', null, '2000-01-01');

Expand Down Expand Up @@ -1270,6 +1354,12 @@ public function testCreateShareInvalidExpireDate() {
$this->shareManager->method('shareApiAllowLinks')->willReturn(true);
$this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'false', '', null, 'a1b2d3');
}

Expand Down Expand Up @@ -1344,6 +1434,12 @@ function ($share) {
}))
->will($this->returnArgument(0));

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$expected = new DataResponse([]);
$result = $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_ROOM, 'recipientRoom');

Expand Down Expand Up @@ -1387,6 +1483,12 @@ public function testCreateShareRoomHelperNotAvailable() {
->with('spreed')
->willReturn(false);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->shareManager->expects($this->never())->method('createShare');

$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_ROOM, 'recipientRoom');
Expand Down Expand Up @@ -1448,6 +1550,12 @@ function ($share) {
->with('\OCA\Spreed\Share\Helper\ShareAPIController')
->willReturn($helper);

$user = $this->createMock(IUser::class);
$user->method('getUID')
->willReturn($this->currentUser);
$path->method('getOwner')
->willReturn($user);

$this->shareManager->expects($this->never())->method('createShare');

$ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_ROOM, 'recipientRoom');
Expand Down

0 comments on commit 32a46db

Please sign in to comment.