aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Share20
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Share20')
-rw-r--r--tests/lib/Share20/DefaultShareProviderTest.php461
-rw-r--r--tests/lib/Share20/LegacyHooksTest.php7
-rw-r--r--tests/lib/Share20/ManagerTest.php710
-rw-r--r--tests/lib/Share20/ShareHelperTest.php3
-rw-r--r--tests/lib/Share20/ShareTest.php35
5 files changed, 743 insertions, 473 deletions
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php
index f5f710cbbd3..33c64265f7b 100644
--- a/tests/lib/Share20/DefaultShareProviderTest.php
+++ b/tests/lib/Share20/DefaultShareProviderTest.php
@@ -19,21 +19,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace Test\Share20;
+use OC\Share20\DefaultShareProvider;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Defaults;
use OCP\Files\File;
use OCP\Files\Folder;
+use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IGroup;
+use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
-use OCP\IGroupManager;
-use OCP\Files\IRootFolder;
-use OC\Share20\DefaultShareProvider;
use OCP\Mail\IMailer;
use OCP\Share\IShare;
@@ -72,7 +73,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject|IURLGenerator */
protected $urlGenerator;
- public function setUp() {
+ protected function setUp(): void {
$this->dbConn = \OC::$server->getDatabaseConnection();
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
@@ -99,7 +100,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
);
}
- public function tearDown() {
+ protected function tearDown(): void {
$this->dbConn->getQueryBuilder()->delete('share')->execute();
$this->dbConn->getQueryBuilder()->delete('filecache')->execute();
$this->dbConn->getQueryBuilder()->delete('storages')->execute();
@@ -124,17 +125,39 @@ class DefaultShareProviderTest extends \Test\TestCase {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share');
- if ($shareType) $qb->setValue('share_type', $qb->expr()->literal($shareType));
- if ($sharedWith) $qb->setValue('share_with', $qb->expr()->literal($sharedWith));
- if ($sharedBy) $qb->setValue('uid_initiator', $qb->expr()->literal($sharedBy));
- if ($shareOwner) $qb->setValue('uid_owner', $qb->expr()->literal($shareOwner));
- if ($itemType) $qb->setValue('item_type', $qb->expr()->literal($itemType));
- if ($fileSource) $qb->setValue('file_source', $qb->expr()->literal($fileSource));
- if ($fileTarget) $qb->setValue('file_target', $qb->expr()->literal($fileTarget));
- if ($permissions) $qb->setValue('permissions', $qb->expr()->literal($permissions));
- if ($token) $qb->setValue('token', $qb->expr()->literal($token));
- if ($expiration) $qb->setValue('expiration', $qb->createNamedParameter($expiration, IQueryBuilder::PARAM_DATE));
- if ($parent) $qb->setValue('parent', $qb->expr()->literal($parent));
+ if ($shareType) {
+ $qb->setValue('share_type', $qb->expr()->literal($shareType));
+ }
+ if ($sharedWith) {
+ $qb->setValue('share_with', $qb->expr()->literal($sharedWith));
+ }
+ if ($sharedBy) {
+ $qb->setValue('uid_initiator', $qb->expr()->literal($sharedBy));
+ }
+ if ($shareOwner) {
+ $qb->setValue('uid_owner', $qb->expr()->literal($shareOwner));
+ }
+ if ($itemType) {
+ $qb->setValue('item_type', $qb->expr()->literal($itemType));
+ }
+ if ($fileSource) {
+ $qb->setValue('file_source', $qb->expr()->literal($fileSource));
+ }
+ if ($fileTarget) {
+ $qb->setValue('file_target', $qb->expr()->literal($fileTarget));
+ }
+ if ($permissions) {
+ $qb->setValue('permissions', $qb->expr()->literal($permissions));
+ }
+ if ($token) {
+ $qb->setValue('token', $qb->expr()->literal($token));
+ }
+ if ($expiration) {
+ $qb->setValue('expiration', $qb->createNamedParameter($expiration, IQueryBuilder::PARAM_DATE));
+ }
+ if ($parent) {
+ $qb->setValue('parent', $qb->expr()->literal($parent));
+ }
$this->assertEquals(1, $qb->execute());
return$qb->getLastInsertId();
@@ -142,10 +165,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
- /**
- * @expectedException \OCP\Share\Exceptions\ShareNotFound
- */
+
public function testGetShareByIdNotExist() {
+ $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
+
$this->provider->getShareById(1);
}
@@ -178,9 +201,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->rootFolder
->method('getUserFolder')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['shareOwner', $shareOwnerFolder],
- ]));
+ ]);
$share = $this->provider->getShareById($id);
@@ -300,9 +323,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->rootFolder
->method('getUserFolder')
- ->will($this->returnValueMap([
- ['shareOwner', $shareOwnerFolder],
- ]));
+ ->willReturnMap([
+ ['shareOwner', $shareOwnerFolder],
+ ]);
$share = $this->provider->getShareById($id);
@@ -333,13 +356,13 @@ class DefaultShareProviderTest extends \Test\TestCase {
$node = $this->createMock(Folder::class);
$node->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('user0')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user0')->willReturnSelf();
$this->rootFolder->method('getById')->willReturn([$node]);
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user0', $user0],
['user1', $user1],
- ]));
+ ]);
$this->groupManager->method('get')->with('group0')->willReturn($group0);
$share = $this->provider->getShareById($id, 'user1');
@@ -383,9 +406,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->rootFolder
->method('getUserFolder')
- ->will($this->returnValueMap([
- ['shareOwner', $shareOwnerFolder],
- ]));
+ ->willReturnMap([
+ ['shareOwner', $shareOwnerFolder],
+ ]);
$share = $this->provider->getShareById($id);
@@ -598,9 +621,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->rootFolder
->method('getUserFolder')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['shareOwner', $ownerFolder],
- ]));
+ ]);
$share = $this->createMock(IShare::class);
$share->method('getId')->willReturn($id);
@@ -646,10 +669,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$userFolder = $this->createMock(Folder::class);
$this->rootFolder
->method('getUserFolder')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['sharedBy', $userFolder],
['shareOwner', $ownerFolder],
- ]));
+ ]);
$userFolder->method('getById')
->with(100)
@@ -702,10 +725,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$userFolder = $this->createMock(Folder::class);
$this->rootFolder
->method('getUserFolder')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['sharedBy', $userFolder],
['shareOwner', $ownerFolder],
- ]));
+ ]);
$userFolder->method('getById')
->with(100)
@@ -742,7 +765,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame('/path/to/image.svg', $share->getSharedWithAvatar());
$this->assertSame(null, $share2->getSharedWithDisplayName());
$this->assertSame(null, $share2->getSharedWithAvatar());
-
}
public function testCreateLinkShare() {
@@ -759,10 +781,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$userFolder = $this->createMock(Folder::class);
$this->rootFolder
->method('getUserFolder')
- ->will($this->returnValueMap([
- ['sharedBy', $userFolder],
- ['shareOwner', $ownerFolder],
- ]));
+ ->willReturnMap([
+ ['sharedBy', $userFolder],
+ ['shareOwner', $ownerFolder],
+ ]);
$userFolder->method('getById')
->with(100)
@@ -821,7 +843,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
$share = $this->provider->getShareByToken('secrettoken');
@@ -834,10 +856,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame(null, $share->getSharedWith());
}
- /**
- * @expectedException \OCP\Share\Exceptions\ShareNotFound
- */
+
public function testGetShareByTokenNotFound() {
+ $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
+
$this->provider->getShareByToken('invalidtoken');
}
@@ -912,7 +934,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(1, $qb->execute());
$file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
$share = $this->provider->getSharedWith('sharedWith', \OCP\Share::SHARE_TYPE_USER, null, 1 , 0);
@@ -963,7 +985,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$id = $qb->getLastInsertId();
$groups = [];
- foreach(range(0, 100) as $i) {
+ foreach (range(0, 100) as $i) {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group'.$i);
$groups[] = $group;
@@ -989,7 +1011,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->groupManager->method('get')->with('sharedWith')->willReturn($group);
$file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
$share = $this->provider->getSharedWith('sharedWith', \OCP\Share::SHARE_TYPE_GROUP, null, 20 , 1);
@@ -1080,7 +1102,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->groupManager->method('get')->with('sharedWith')->willReturn($group);
$file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);
$share = $this->provider->getSharedWith('user', \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
@@ -1123,7 +1145,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn($fileId2);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with($fileId2)->willReturn([$file]);
$share = $this->provider->getSharedWith('user0', \OCP\Share::SHARE_TYPE_USER, $file, -1, 0);
@@ -1168,7 +1190,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$node = $this->createMock(Folder::class);
$node->method('getId')->willReturn($fileId2);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with($fileId2)->willReturn([$node]);
$share = $this->provider->getSharedWith('user0', \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
@@ -1219,11 +1241,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(1, $qb->execute());
$file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with($deletedFileId)->willReturn([$file]);
$groups = [];
- foreach(range(0, 100) as $i) {
+ foreach (range(0, 100) as $i) {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group'.$i);
$groups[] = $group;
@@ -1284,7 +1306,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(1, $qb->execute());
$file = $this->createMock(File::class);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
$share = $this->provider->getSharesBy('sharedBy', \OCP\Share::SHARE_TYPE_USER, null, false, 1, 0);
@@ -1334,7 +1356,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
$share = $this->provider->getSharesBy('sharedBy', \OCP\Share::SHARE_TYPE_USER, $file, false, 1, 0);
@@ -1384,7 +1406,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
$shares = $this->provider->getSharesBy('shareOwner', \OCP\Share::SHARE_TYPE_USER, null, true, -1, 0);
@@ -1430,10 +1452,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$user1->method('getUID')->willReturn('user1');
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user1', $user1],
['user2', $user2],
- ]));
+ ]);
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group');
@@ -1443,7 +1465,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with(1)->willReturn([$file]);
$share = $this->provider->getShareById($id);
@@ -1501,10 +1523,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$user1->method('getUID')->willReturn('user1');
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user1', $user1],
['user2', $user2],
- ]));
+ ]);
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group');
@@ -1514,7 +1536,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with(1)->willReturn([$file]);
$share = $this->provider->getShareById($id);
@@ -1537,11 +1559,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals('user2', $share2['share_with']);
}
- /**
- * @expectedException \OC\Share20\Exception\ProviderException
- * @expectedExceptionMessage Recipient not in receiving group
- */
+
public function testDeleteFromSelfGroupUserNotInGroup() {
+ $this->expectException(\OC\Share20\Exception\ProviderException::class);
+ $this->expectExceptionMessage('Recipient not in receiving group');
+
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->insert('share')
->values([
@@ -1561,10 +1583,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$user1->method('getUID')->willReturn('user1');
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user1', $user1],
['user2', $user2],
- ]));
+ ]);
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group');
@@ -1574,7 +1596,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with(1)->willReturn([$file]);
$share = $this->provider->getShareById($id);
@@ -1582,11 +1604,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->provider->deleteFromSelf($share, 'user2');
}
- /**
- * @expectedException \OC\Share20\Exception\ProviderException
- * @expectedExceptionMessage Group "group" does not exist
- */
+
public function testDeleteFromSelfGroupDoesNotExist() {
+ $this->expectException(\OC\Share20\Exception\ProviderException::class);
+ $this->expectExceptionMessage('Group "group" does not exist');
+
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->insert('share')
->values([
@@ -1606,17 +1628,17 @@ class DefaultShareProviderTest extends \Test\TestCase {
$user1->method('getUID')->willReturn('user1');
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user1', $user1],
['user2', $user2],
- ]));
+ ]);
$this->groupManager->method('get')->with('group')->willReturn(null);
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with(1)->willReturn([$file]);
$share = $this->provider->getShareById($id);
@@ -1646,15 +1668,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('user2');
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user1', $user1],
['user2', $user2],
- ]));
+ ]);
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with(1)->willReturn([$file]);
$share = $this->provider->getShareById($id);
@@ -1673,11 +1695,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertCount(0, $shares);
}
- /**
- * @expectedException \OC\Share20\Exception\ProviderException
- * @expectedExceptionMessage Recipient does not match
- */
+
public function testDeleteFromSelfUserNotRecipient() {
+ $this->expectException(\OC\Share20\Exception\ProviderException::class);
+ $this->expectExceptionMessage('Recipient does not match');
+
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->insert('share')
->values([
@@ -1700,15 +1722,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
$user2->method('getUID')->willReturn('user2');
$user2->method('getDisplayName')->willReturn('user2');
$user3 = $this->createMock(IUser::class);
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user1', $user1],
['user2', $user2],
- ]));
+ ]);
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with(1)->willReturn([$file]);
$share = $this->provider->getShareById($id);
@@ -1716,11 +1738,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->provider->deleteFromSelf($share, $user3);
}
- /**
- * @expectedException \OC\Share20\Exception\ProviderException
- * @expectedExceptionMessage Invalid shareType
- */
+
public function testDeleteFromSelfLink() {
+ $this->expectException(\OC\Share20\Exception\ProviderException::class);
+ $this->expectExceptionMessage('Invalid shareType');
+
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->insert('share')
->values([
@@ -1738,14 +1760,14 @@ class DefaultShareProviderTest extends \Test\TestCase {
$user1 = $this->createMock(IUser::class);
$user1->method('getUID')->willReturn('user1');
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user1', $user1],
- ]));
+ ]);
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(1);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->with(1)->willReturn([$file]);
$share = $this->provider->getShareById($id);
@@ -1758,17 +1780,17 @@ class DefaultShareProviderTest extends \Test\TestCase {
'file', 42, 'target', 31, null, null);
$users = [];
- for($i = 0; $i < 6; $i++) {
+ for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user'.$i);
$user->method('getDisplayName')->willReturn('user' . $i);
$users['user'.$i] = $user;
}
- $this->userManager->method('get')->will(
- $this->returnCallback(function($userId) use ($users) {
+ $this->userManager->method('get')->willReturnCallback(
+ function ($userId) use ($users) {
return $users[$userId];
- })
+ }
);
$file1 = $this->createMock(File::class);
@@ -1781,10 +1803,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$folder2 = $this->createMock(Folder::class);
$folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([
+ $this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
['user5', $folder2],
- ]));
+ ]);
$share = $this->provider->getShareById($id);
@@ -1816,16 +1838,16 @@ class DefaultShareProviderTest extends \Test\TestCase {
'file', 42, 'target', 31, null, null);
$users = [];
- for($i = 0; $i < 6; $i++) {
+ for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user'.$i);
$users['user'.$i] = $user;
}
- $this->userManager->method('get')->will(
- $this->returnCallback(function($userId) use ($users) {
+ $this->userManager->method('get')->willReturnCallback(
+ function ($userId) use ($users) {
return $users[$userId];
- })
+ }
);
$file1 = $this->createMock(File::class);
@@ -1838,10 +1860,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$folder2 = $this->createMock(Folder::class);
$folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([
+ $this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
['user5', $folder2],
- ]));
+ ]);
$share = $this->provider->getShareById($id);
@@ -1882,16 +1904,16 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertEquals(1, $qb->execute());
$users = [];
- for($i = 0; $i < 6; $i++) {
+ for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user'.$i);
$users['user'.$i] = $user;
}
- $this->userManager->method('get')->will(
- $this->returnCallback(function($userId) use ($users) {
+ $this->userManager->method('get')->willReturnCallback(
+ function ($userId) use ($users) {
return $users[$userId];
- })
+ }
);
$file1 = $this->createMock(File::class);
@@ -1904,10 +1926,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$folder2 = $this->createMock(Folder::class);
$folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([
+ $this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
['user5', $folder2],
- ]));
+ ]);
$share = $this->provider->getShareById($id);
@@ -1939,29 +1961,29 @@ class DefaultShareProviderTest extends \Test\TestCase {
'file', 42, 'target', 31, null, null);
$users = [];
- for($i = 0; $i < 6; $i++) {
+ for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user'.$i);
$users['user'.$i] = $user;
}
- $this->userManager->method('get')->will(
- $this->returnCallback(function($userId) use ($users) {
+ $this->userManager->method('get')->willReturnCallback(
+ function ($userId) use ($users) {
return $users[$userId];
- })
+ }
);
$groups = [];
- for($i = 0; $i < 2; $i++) {
+ for ($i = 0; $i < 2; $i++) {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group'.$i);
$groups['group'.$i] = $group;
}
- $this->groupManager->method('get')->will(
- $this->returnCallback(function($groupId) use ($groups) {
+ $this->groupManager->method('get')->willReturnCallback(
+ function ($groupId) use ($groups) {
return $groups[$groupId];
- })
+ }
);
$file1 = $this->createMock(File::class);
@@ -1974,10 +1996,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$folder2 = $this->createMock(Folder::class);
$folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([
+ $this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
['user5', $folder2],
- ]));
+ ]);
$share = $this->provider->getShareById($id);
@@ -2017,29 +2039,29 @@ class DefaultShareProviderTest extends \Test\TestCase {
'file', 42, 'mytarget2', 0, null, null, $id);
$users = [];
- for($i = 0; $i < 6; $i++) {
+ for ($i = 0; $i < 6; $i++) {
$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('user'.$i);
$users['user'.$i] = $user;
}
- $this->userManager->method('get')->will(
- $this->returnCallback(function($userId) use ($users) {
+ $this->userManager->method('get')->willReturnCallback(
+ function ($userId) use ($users) {
return $users[$userId];
- })
+ }
);
$groups = [];
- for($i = 0; $i < 2; $i++) {
+ for ($i = 0; $i < 2; $i++) {
$group = $this->createMock(IGroup::class);
$group->method('getGID')->willReturn('group'.$i);
$groups['group'.$i] = $group;
}
- $this->groupManager->method('get')->will(
- $this->returnCallback(function($groupId) use ($groups) {
+ $this->groupManager->method('get')->willReturnCallback(
+ function ($groupId) use ($groups) {
return $groups[$groupId];
- })
+ }
);
$file1 = $this->createMock(File::class);
@@ -2052,10 +2074,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$folder2 = $this->createMock(Folder::class);
$folder2->method('getById')->with(43)->willReturn([$file2]);
- $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([
+ $this->rootFolder->method('getUserFolder')->willReturnMap([
['user2', $folder1],
['user5', $folder2],
- ]));
+ ]);
$share = $this->provider->getShareById($id);
@@ -2117,15 +2139,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
$user1->method('getUID')->willReturn('user1');
$user1->method('getDisplayName')->willReturn('user1');
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user0', $user0],
['user1', $user1],
- ]));
+ ]);
$file = $this->createMock(File::class);
$file->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->willReturn([$file]);
$share = $this->provider->getShareById($id, null);
@@ -2152,15 +2174,15 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->groupManager->method('get')->with('group0')->willReturn($group0);
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['user0', $user0],
['user1', $user1],
- ]));
+ ]);
$folder = $this->createMock(Folder::class);
$folder->method('getId')->willReturn(42);
- $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('user1')->willReturnSelf();
$this->rootFolder->method('getById')->willReturn([$folder]);
$share = $this->provider->getShareById($id, 'user0');
@@ -2742,4 +2764,169 @@ class DefaultShareProviderTest extends \Test\TestCase {
$u5->delete();
$g1->delete();
}
+
+ public function testGetAllShares() {
+ $qb = $this->dbConn->getQueryBuilder();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
+ 'share_with' => $qb->expr()->literal('sharedWith1'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner1'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy1'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(42),
+ 'file_target' => $qb->expr()->literal('myTarget1'),
+ 'permissions' => $qb->expr()->literal(13),
+ ]);
+ $qb->execute();
+
+ $id1 = $qb->getLastInsertId();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
+ 'share_with' => $qb->expr()->literal('sharedWith2'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner2'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy2'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(43),
+ 'file_target' => $qb->expr()->literal('myTarget2'),
+ 'permissions' => $qb->expr()->literal(14),
+ ]);
+ $qb->execute();
+
+ $id2 = $qb->getLastInsertId();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
+ 'token' => $qb->expr()->literal('token3'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner3'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy3'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(44),
+ 'file_target' => $qb->expr()->literal('myTarget3'),
+ 'permissions' => $qb->expr()->literal(15),
+ ]);
+ $qb->execute();
+
+ $id3 = $qb->getLastInsertId();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_EMAIL),
+ 'share_with' => $qb->expr()->literal('shareOwner4'),
+ 'token' => $qb->expr()->literal('token4'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner4'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy4'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(45),
+ 'file_target' => $qb->expr()->literal('myTarget4'),
+ 'permissions' => $qb->expr()->literal(16),
+ ]);
+ $qb->execute();
+
+ $id4 = $qb->getLastInsertId();
+
+ $qb->insert('share')
+ ->values([
+ 'share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
+ 'token' => $qb->expr()->literal('token5'),
+ 'uid_owner' => $qb->expr()->literal('shareOwner5'),
+ 'uid_initiator' => $qb->expr()->literal('sharedBy5'),
+ 'item_type' => $qb->expr()->literal('file'),
+ 'file_source' => $qb->expr()->literal(46),
+ 'file_target' => $qb->expr()->literal('myTarget5'),
+ 'permissions' => $qb->expr()->literal(17),
+ ]);
+ $qb->execute();
+
+ $id5 = $qb->getLastInsertId();
+
+ $ownerPath1 = $this->createMock(File::class);
+ $shareOwner1Folder = $this->createMock(Folder::class);
+ $shareOwner1Folder->method('getById')->willReturn([$ownerPath1]);
+
+ $ownerPath2 = $this->createMock(File::class);
+ $shareOwner2Folder = $this->createMock(Folder::class);
+ $shareOwner2Folder->method('getById')->willReturn([$ownerPath2]);
+
+ $ownerPath3 = $this->createMock(File::class);
+ $shareOwner3Folder = $this->createMock(Folder::class);
+ $shareOwner3Folder->method('getById')->willReturn([$ownerPath3]);
+
+ $ownerPath4 = $this->createMock(File::class);
+ $shareOwner4Folder = $this->createMock(Folder::class);
+ $shareOwner4Folder->method('getById')->willReturn([$ownerPath4]);
+
+ $ownerPath5 = $this->createMock(File::class);
+ $shareOwner5Folder = $this->createMock(Folder::class);
+ $shareOwner5Folder->method('getById')->willReturn([$ownerPath5]);
+
+ $this->rootFolder
+ ->method('getUserFolder')
+ ->willReturnMap(
+ [
+ ['shareOwner1', $shareOwner1Folder],
+ ['shareOwner2', $shareOwner2Folder],
+ ['shareOwner3', $shareOwner3Folder],
+ ['shareOwner4', $shareOwner4Folder],
+ ['shareOwner5', $shareOwner5Folder],
+ ]
+ );
+
+ $shares = iterator_to_array($this->provider->getAllShares());
+ $this->assertEquals(4, count($shares));
+
+ $share = $shares[0];
+
+ // We fetch the node so the root folder is eventually called
+
+ $this->assertEquals($id1, $share->getId());
+ $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
+ $this->assertEquals('sharedWith1', $share->getSharedWith());
+ $this->assertEquals('sharedBy1', $share->getSharedBy());
+ $this->assertEquals('shareOwner1', $share->getShareOwner());
+ $this->assertEquals($ownerPath1, $share->getNode());
+ $this->assertEquals(13, $share->getPermissions());
+ $this->assertEquals(null, $share->getToken());
+ $this->assertEquals('myTarget1', $share->getTarget());
+
+ $share = $shares[1];
+
+ $this->assertEquals($id2, $share->getId());
+ $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType());
+ $this->assertEquals('sharedWith2', $share->getSharedWith());
+ $this->assertEquals('sharedBy2', $share->getSharedBy());
+ $this->assertEquals('shareOwner2', $share->getShareOwner());
+ $this->assertEquals($ownerPath2, $share->getNode());
+ $this->assertEquals(14, $share->getPermissions());
+ $this->assertEquals(null, $share->getToken());
+ $this->assertEquals('myTarget2', $share->getTarget());
+
+ $share = $shares[2];
+
+ $this->assertEquals($id3, $share->getId());
+ $this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType());
+ $this->assertEquals(null, $share->getSharedWith());
+ $this->assertEquals('sharedBy3', $share->getSharedBy());
+ $this->assertEquals('shareOwner3', $share->getShareOwner());
+ $this->assertEquals($ownerPath3, $share->getNode());
+ $this->assertEquals(15, $share->getPermissions());
+ $this->assertEquals('token3', $share->getToken());
+ $this->assertEquals('myTarget3', $share->getTarget());
+
+ $share = $shares[3];
+
+ $this->assertEquals($id5, $share->getId());
+ $this->assertEquals(\OCP\Share::SHARE_TYPE_LINK, $share->getShareType());
+ $this->assertEquals(null, $share->getSharedWith());
+ $this->assertEquals('sharedBy5', $share->getSharedBy());
+ $this->assertEquals('shareOwner5', $share->getShareOwner());
+ $this->assertEquals($ownerPath5, $share->getNode());
+ $this->assertEquals(17, $share->getPermissions());
+ $this->assertEquals('token5', $share->getToken());
+ $this->assertEquals('myTarget5', $share->getTarget());
+ }
}
diff --git a/tests/lib/Share20/LegacyHooksTest.php b/tests/lib/Share20/LegacyHooksTest.php
index 5fc6a447047..2b062e592ba 100644
--- a/tests/lib/Share20/LegacyHooksTest.php
+++ b/tests/lib/Share20/LegacyHooksTest.php
@@ -20,6 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace Test\Share20;
use OC\Share20\LegacyHooks;
@@ -41,7 +42,7 @@ class LegacyHooksTest extends TestCase {
/** @var Manager */
private $manager;
- public function setUp() {
+ protected function setUp(): void {
parent::setUp();
$this->eventDispatcher = new EventDispatcher();
@@ -280,10 +281,10 @@ class LegacyHooksTest extends TestCase {
->expects($this->exactly(1))
->method('preShare')
->with($expected)
- ->will($this->returnCallback(function ($data) {
+ ->willReturnCallback(function ($data) {
$data['run'] = false;
$data['error'] = 'I error';
- }));
+ });
$event = new GenericEvent($share);
$this->eventDispatcher->dispatch('OCP\Share::preShare', $event);
diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php
index 6f46d69d8df..4a7b0e9ae4b 100644
--- a/tests/lib/Share20/ManagerTest.php
+++ b/tests/lib/Share20/ManagerTest.php
@@ -18,39 +18,44 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace Test\Share20;
use OC\Files\Mount\MoveableMount;
use OC\HintException;
use OC\Share20\DefaultShareProvider;
+use OC\Share20\Exception;
+use OC\Share20\Manager;
+use OC\Share20\Share;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
+use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\Storage;
+use OCP\IConfig;
use OCP\IGroup;
+use OCP\IGroupManager;
+use OCP\IL10N;
+use OCP\ILogger;
use OCP\IServerContainer;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
+use OCP\Security\Events\ValidatePasswordPolicyEvent;
+use OCP\Security\IHasher;
+use OCP\Security\ISecureRandom;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
-use OC\Share20\Manager;
-use OC\Share20\Exception;
-
-use OC\Share20\Share;
-use OCP\IL10N;
-use OCP\ILogger;
-use OCP\IConfig;
use OCP\Share\IShareProvider;
-use OCP\Security\ISecureRandom;
-use OCP\Security\IHasher;
-use OCP\Files\Mount\IMountManager;
-use OCP\IGroupManager;
+use PHPUnit\Framework\MockObject\MockBuilder;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
@@ -64,41 +69,42 @@ class ManagerTest extends \Test\TestCase {
/** @var Manager */
protected $manager;
- /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var ILogger|MockObject */
protected $logger;
- /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IConfig|MockObject */
protected $config;
- /** @var ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var ISecureRandom|MockObject */
protected $secureRandom;
- /** @var IHasher|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IHasher|MockObject */
protected $hasher;
- /** @var IShareProvider|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IShareProvider|MockObject */
protected $defaultProvider;
- /** @var IMountManager|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IMountManager|MockObject */
protected $mountManager;
- /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IGroupManager|MockObject */
protected $groupManager;
- /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IL10N|MockObject */
protected $l;
- /** @var IFactory|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IFactory|MockObject */
protected $l10nFactory;
/** @var DummyFactory */
protected $factory;
- /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IUserManager|MockObject */
protected $userManager;
- /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */
+ /** @var IRootFolder | MockObject */
protected $rootFolder;
- /** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
+ /** @var EventDispatcherInterface | MockObject */
protected $eventDispatcher;
- /** @var IMailer|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IEventDispatcher|MockObject */
+ protected $dispatcher;
+ /** @var IMailer|MockObject */
protected $mailer;
- /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IURLGenerator|MockObject */
protected $urlGenerator;
- /** @var \OC_Defaults|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var \OC_Defaults|MockObject */
protected $defaults;
- public function setUp() {
-
+ protected function setUp(): void {
$this->logger = $this->createMock(ILogger::class);
$this->config = $this->createMock(IConfig::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
@@ -111,13 +117,14 @@ class ManagerTest extends \Test\TestCase {
$this->mailer = $this->createMock(IMailer::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->defaults = $this->createMock(\OC_Defaults::class);
+ $this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->l = $this->createMock(IL10N::class);
$this->l->method('t')
- ->will($this->returnCallback(function($text, $parameters = []) {
- return vsprintf($text, $parameters);
- }));
+ ->willReturnCallback(function ($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ });
$this->factory = new DummyFactory(\OC::$server);
@@ -136,7 +143,8 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
);
$this->defaultProvider = $this->createMock(DefaultShareProvider::class);
@@ -145,7 +153,7 @@ class ManagerTest extends \Test\TestCase {
}
/**
- * @return \PHPUnit_Framework_MockObject_MockBuilder
+ * @return MockBuilder
*/
private function createManagerMock() {
return $this->getMockBuilder('\OC\Share20\Manager')
@@ -164,14 +172,15 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
]);
}
- /**
- * @expectedException \InvalidArgumentException
- */
+
public function testDeleteNoShareId() {
+ $this->expectException(\InvalidArgumentException::class);
+
$share = $this->manager->newShare();
$this->manager->deleteShare($share);
@@ -223,7 +232,7 @@ class ManagerTest extends \Test\TestCase {
->method('dispatch')
->with(
'OCP\Share::preUnshare',
- $this->callBack(function(GenericEvent $e) use ($share) {
+ $this->callBack(function (GenericEvent $e) use ($share) {
return $e->getSubject() === $share;
})
);
@@ -231,7 +240,7 @@ class ManagerTest extends \Test\TestCase {
->method('dispatch')
->with(
'OCP\Share::postUnshare',
- $this->callBack(function(GenericEvent $e) use ($share) {
+ $this->callBack(function (GenericEvent $e) use ($share) {
return $e->getSubject() === $share &&
$e->getArgument('deletedShares') === [$share];
})
@@ -269,7 +278,7 @@ class ManagerTest extends \Test\TestCase {
->method('dispatch')
->with(
'OCP\Share::preUnshare',
- $this->callBack(function(GenericEvent $e) use ($share) {
+ $this->callBack(function (GenericEvent $e) use ($share) {
return $e->getSubject() === $share;
})
);
@@ -277,7 +286,7 @@ class ManagerTest extends \Test\TestCase {
->method('dispatch')
->with(
'OCP\Share::postUnshare',
- $this->callBack(function(GenericEvent $e) use ($share) {
+ $this->callBack(function (GenericEvent $e) use ($share) {
return $e->getSubject() === $share &&
$e->getArgument('deletedShares') === [$share];
})
@@ -324,21 +333,21 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider
->method('getChildren')
- ->will($this->returnValueMap([
+ ->willReturnMap([
[$share1, [$share2]],
[$share2, [$share3]],
[$share3, []],
- ]));
+ ]);
$this->defaultProvider
->method('delete')
- ->withConsecutive($share3, $share2, $share1);
+ ->withConsecutive([$share3], [$share2], [$share1]);
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with(
'OCP\Share::preUnshare',
- $this->callBack(function(GenericEvent $e) use ($share1) {
+ $this->callBack(function (GenericEvent $e) use ($share1) {
return $e->getSubject() === $share1;
})
);
@@ -346,7 +355,7 @@ class ManagerTest extends \Test\TestCase {
->method('dispatch')
->with(
'OCP\Share::postUnshare',
- $this->callBack(function(GenericEvent $e) use ($share1, $share2, $share3) {
+ $this->callBack(function (GenericEvent $e) use ($share1, $share2, $share3) {
return $e->getSubject() === $share1 &&
$e->getArgument('deletedShares') === [$share3, $share2, $share1];
})
@@ -381,7 +390,7 @@ class ManagerTest extends \Test\TestCase {
->method('dispatch')
->with(
'OCP\Share::postUnshareFromSelf',
- $this->callBack(function(GenericEvent $e) use ($share) {
+ $this->callBack(function (GenericEvent $e) use ($share) {
return $e->getSubject() === $share;
})
);
@@ -413,17 +422,17 @@ class ManagerTest extends \Test\TestCase {
$this->defaultProvider
->expects($this->exactly(4))
->method('getChildren')
- ->will($this->returnCallback(function($_share) use ($share, $shares) {
+ ->willReturnCallback(function ($_share) use ($share, $shares) {
if ($_share === $share) {
return $shares;
}
return [];
- }));
+ });
$this->defaultProvider
->expects($this->exactly(3))
->method('delete')
- ->withConsecutive($child1, $child2, $child3);
+ ->withConsecutive([$child1], [$child2], [$child3]);
$result = self::invokePrivate($manager, 'deleteChildren', [$share]);
$this->assertSame($shares, $result);
@@ -441,10 +450,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($share, $this->manager->getShareById('default:42'));
}
- /**
- * @expectedException \OCP\Share\Exceptions\ShareNotFound
- */
+
public function testGetExpiredShareById() {
+ $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
+
$manager = $this->createManagerMock()
->setMethods(['deleteShare'])
->getMock();
@@ -468,59 +477,61 @@ class ManagerTest extends \Test\TestCase {
$manager->getShareById('default:42');
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Passwords are enforced for link shares
- */
+
public function testVerifyPasswordNullButEnforced() {
- $this->config->method('getAppValue')->will($this->returnValueMap([
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Passwords are enforced for link shares');
+
+ $this->config->method('getAppValue')->willReturnMap([
['core', 'shareapi_enforce_links_password', 'no', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'verifyPassword', [null]);
}
public function testVerifyPasswordNull() {
- $this->config->method('getAppValue')->will($this->returnValueMap([
- ['core', 'shareapi_enforce_links_password', 'no', 'no'],
- ]));
+ $this->config->method('getAppValue')->willReturnMap([
+ ['core', 'shareapi_enforce_links_password', 'no', 'no'],
+ ]);
$result = self::invokePrivate($this->manager, 'verifyPassword', [null]);
$this->assertNull($result);
}
public function testVerifyPasswordHook() {
- $this->config->method('getAppValue')->will($this->returnValueMap([
- ['core', 'shareapi_enforce_links_password', 'no', 'no'],
- ]));
+ $this->config->method('getAppValue')->willReturnMap([
+ ['core', 'shareapi_enforce_links_password', 'no', 'no'],
+ ]);
$this->eventDispatcher->expects($this->once())->method('dispatch')
- ->willReturnCallback(function($eventName, GenericEvent $event) {
- $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
- $this->assertSame('password', $event->getSubject());
+ ->willReturnCallback(function (Event $event) {
+ $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
+ /** @var ValidatePasswordPolicyEvent $event */
+ $this->assertSame('password', $event->getPassword());
}
- );
+ );
$result = self::invokePrivate($this->manager, 'verifyPassword', ['password']);
$this->assertNull($result);
}
- /**
- * @expectedException \Exception
- * @expectedExceptionMessage password not accepted
- */
+
public function testVerifyPasswordHookFails() {
- $this->config->method('getAppValue')->will($this->returnValueMap([
- ['core', 'shareapi_enforce_links_password', 'no', 'no'],
- ]));
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('password not accepted');
+
+ $this->config->method('getAppValue')->willReturnMap([
+ ['core', 'shareapi_enforce_links_password', 'no', 'no'],
+ ]);
$this->eventDispatcher->expects($this->once())->method('dispatch')
- ->willReturnCallback(function($eventName, GenericEvent $event) {
- $this->assertSame('OCP\PasswordPolicy::validate', $eventName);
- $this->assertSame('password', $event->getSubject());
+ ->willReturnCallback(function (Event $event) {
+ $this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
+ /** @var ValidatePasswordPolicyEvent $event */
+ $this->assertSame('password', $event->getPassword());
throw new HintException('message', 'password not accepted');
}
- );
+ );
self::invokePrivate($this->manager, 'verifyPassword', ['password']);
}
@@ -685,17 +696,20 @@ class ManagerTest extends \Test\TestCase {
public function testGeneralChecks($share, $exceptionMessage, $exception) {
$thrown = null;
- $this->userManager->method('userExists')->will($this->returnValueMap([
+ $this->userManager->method('userExists')->willReturnMap([
['user0', true],
['user1', true],
- ]));
+ ]);
- $this->groupManager->method('groupExists')->will($this->returnValueMap([
+ $this->groupManager->method('groupExists')->willReturnMap([
['group0', true],
- ]));
+ ]);
$userFolder = $this->createMock(Folder::class);
$userFolder->method('getPath')->willReturn('myrootfolder');
+ $userFolder->expects($this->any())
+ ->method('getRelativePath')
+ ->willReturnArgument(0);
$this->rootFolder->method('getUserFolder')->willReturn($userFolder);
@@ -705,7 +719,7 @@ class ManagerTest extends \Test\TestCase {
} catch (\OCP\Share\Exceptions\GenericShareException $e) {
$this->assertEquals($exceptionMessage, $e->getHint());
$thrown = true;
- } catch(\InvalidArgumentException $e) {
+ } catch (\InvalidArgumentException $e) {
$this->assertEquals($exceptionMessage, $e->getMessage());
$thrown = true;
}
@@ -713,17 +727,17 @@ class ManagerTest extends \Test\TestCase {
$this->assertSame($exception, $thrown);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage You can’t share your root folder
- */
+
public function testGeneralCheckShareRoot() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('You can’t share your root folder');
+
$thrown = null;
- $this->userManager->method('userExists')->will($this->returnValueMap([
+ $this->userManager->method('userExists')->willReturnMap([
['user0', true],
['user1', true],
- ]));
+ ]);
$userFolder = $this->createMock(Folder::class);
$userFolder->method('isSubNode')->with($userFolder)->willReturn(false);
@@ -739,11 +753,11 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'generalCreateChecks', [$share]);
}
- /**
- * @expectedException \OCP\Share\Exceptions\GenericShareException
- * @expectedExceptionMessage Expiration date is in the past
- */
+
public function testvalidateExpirationDateInPast() {
+ $this->expectException(\OCP\Share\Exceptions\GenericShareException::class);
+ $this->expectExceptionMessage('Expiration date is in the past');
+
// Expire date in the past
$past = new \DateTime();
@@ -755,19 +769,19 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Expiration date is enforced
- */
+
public function testvalidateExpirationDateEnforceButNotSet() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Expiration date is enforced');
+
$share = $this->manager->newShare();
$share->setProviderId('foo')->setId('bar');
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
}
@@ -777,9 +791,9 @@ class ManagerTest extends \Test\TestCase {
$share->setProviderId('foo')->setId('bar');
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
@@ -790,11 +804,11 @@ class ManagerTest extends \Test\TestCase {
$share = $this->manager->newShare();
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_expire_date', 'no', 'yes'],
- ]));
+ ]);
$expected = new \DateTime();
$expected->setTime(0,0,0);
@@ -815,10 +829,10 @@ class ManagerTest extends \Test\TestCase {
$share->setExpirationDate($future);
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
- ]));
+ ]);
try {
self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
@@ -843,10 +857,10 @@ class ManagerTest extends \Test\TestCase {
$share->setExpirationDate($future);
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_enforce_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
- ]));
+ ]);
$hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener');
@@ -906,10 +920,10 @@ class ManagerTest extends \Test\TestCase {
$share->setExpirationDate($future);
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '3'],
- ]));
+ ]);
$hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener');
@@ -931,9 +945,9 @@ class ManagerTest extends \Test\TestCase {
$hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener');
- $hookListner->expects($this->once())->method('listener')->will($this->returnCallback(function ($data) {
+ $hookListner->expects($this->once())->method('listener')->willReturnCallback(function ($data) {
$data['expirationDate']->sub(new \DateInterval('P2D'));
- }));
+ });
$share = $this->manager->newShare();
$share->setExpirationDate($nextWeek);
@@ -944,11 +958,11 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($save, $share->getExpirationDate());
}
- /**
- * @expectedException \Exception
- * @expectedExceptionMessage Invalid date!
- */
+
public function testValidateExpirationDateHookException() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Invalid date!');
+
$nextWeek = new \DateTime();
$nextWeek->add(new \DateInterval('P7D'));
$nextWeek->setTime(0,0,0);
@@ -958,10 +972,10 @@ class ManagerTest extends \Test\TestCase {
$hookListner = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListner, 'listener');
- $hookListner->expects($this->once())->method('listener')->will($this->returnCallback(function ($data) {
+ $hookListner->expects($this->once())->method('listener')->willReturnCallback(function ($data) {
$data['accepted'] = false;
$data['message'] = 'Invalid date!';
- }));
+ });
self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
}
@@ -972,21 +986,21 @@ class ManagerTest extends \Test\TestCase {
$share->setId('42')->setProviderId('foo');
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_default_expire_date', 'no', 'yes'],
['core', 'shareapi_expire_after_n_days', '7', '6'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'validateExpirationDate', [$share]);
$this->assertEquals(null, $share->getExpirationDate());
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Sharing is only allowed with group members
- */
+
public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Sharing is only allowed with group members');
+
$share = $this->manager->newShare();
$sharedBy = $this->createMock(IUser::class);
@@ -995,23 +1009,23 @@ class ManagerTest extends \Test\TestCase {
$this->groupManager
->method('getUserGroupIds')
- ->will(
- $this->returnValueMap([
+ ->willReturnMap(
+ [
[$sharedBy, ['group1']],
[$sharedWith, ['group2']],
- ])
+ ]
);
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['sharedBy', $sharedBy],
['sharedWith', $sharedWith],
- ]));
+ ]);
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
}
@@ -1028,23 +1042,23 @@ class ManagerTest extends \Test\TestCase {
$this->groupManager
->method('getUserGroupIds')
- ->will(
- $this->returnValueMap([
+ ->willReturnMap(
+ [
[$sharedBy, ['group1', 'group3']],
[$sharedWith, ['group2', 'group3']],
- ])
+ ]
);
- $this->userManager->method('get')->will($this->returnValueMap([
+ $this->userManager->method('get')->willReturnMap([
['sharedBy', $sharedBy],
['sharedWith', $sharedWith],
- ]));
+ ]);
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
- ]));
+ ]);
$this->defaultProvider
->method('getSharesByPath')
@@ -1055,11 +1069,11 @@ class ManagerTest extends \Test\TestCase {
$this->addToAssertionCount(1);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Path is already shared with this user
- */
+
public function testUserCreateChecksIdenticalShareExists() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Path is already shared with this user');
+
$share = $this->manager->newShare();
$share2 = $this->manager->newShare();
@@ -1080,11 +1094,11 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Path is already shared with this user
- */
- public function testUserCreateChecksIdenticalPathSharedViaGroup() {
+
+ public function testUserCreateChecksIdenticalPathSharedViaGroup() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Path is already shared with this user');
+
$share = $this->manager->newShare();
$sharedWith = $this->createMock(IUser::class);
@@ -1122,7 +1136,7 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'userCreateChecks', [$share]);
}
- public function testUserCreateChecksIdenticalPathSharedViaDeletedGroup() {
+ public function testUserCreateChecksIdenticalPathSharedViaDeletedGroup() {
$share = $this->manager->newShare();
$sharedWith = $this->createMock(IUser::class);
@@ -1191,27 +1205,27 @@ class ManagerTest extends \Test\TestCase {
$this->addToAssertionCount(1);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Group sharing is now allowed
- */
+
public function testGroupCreateChecksShareWithGroupMembersGroupSharingNotAllowed() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Group sharing is now allowed');
+
$share = $this->manager->newShare();
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_allow_group_sharing', 'yes', 'no'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'groupCreateChecks', [$share]);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Sharing is only allowed within your own groups
- */
+
public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Sharing is only allowed within your own groups');
+
$share = $this->manager->newShare();
$user = $this->createMock(IUser::class);
@@ -1225,19 +1239,19 @@ class ManagerTest extends \Test\TestCase {
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'groupCreateChecks', [$share]);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Sharing is only allowed within your own groups
- */
+
public function testGroupCreateChecksShareWithGroupMembersOnlyNullGroup() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Sharing is only allowed within your own groups');
+
$share = $this->manager->newShare();
$user = $this->createMock(IUser::class);
@@ -1248,10 +1262,10 @@ class ManagerTest extends \Test\TestCase {
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
- ]));
+ ]);
$this->assertNull($this->invokePrivate($this->manager, 'groupCreateChecks', [$share]));
}
@@ -1277,20 +1291,20 @@ class ManagerTest extends \Test\TestCase {
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'groupCreateChecks', [$share]);
$this->addToAssertionCount(1);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Path is already shared with this group
- */
+
public function testGroupCreateChecksPathAlreadySharedWithSameGroup() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Path is already shared with this group');
+
$share = $this->manager->newShare();
$path = $this->createMock(Node::class);
@@ -1310,9 +1324,9 @@ class ManagerTest extends \Test\TestCase {
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'groupCreateChecks', [$share]);
}
@@ -1334,63 +1348,63 @@ class ManagerTest extends \Test\TestCase {
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_allow_group_sharing', 'yes', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'groupCreateChecks', [$share]);
$this->addToAssertionCount(1);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Link sharing is not allowed
- */
+
public function testLinkCreateChecksNoLinkSharesAllowed() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Link sharing is not allowed');
+
$share = $this->manager->newShare();
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_allow_links', 'yes', 'no'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'linkCreateChecks', [$share]);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Link shares can’t have reshare permissions
- */
+
public function testLinkCreateChecksSharePermissions() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Link shares can’t have reshare permissions');
+
$share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_SHARE);
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_allow_links', 'yes', 'yes'],
- ]));
+ ]);
self::invokePrivate($this->manager, 'linkCreateChecks', [$share]);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Public upload is not allowed
- */
+
public function testLinkCreateChecksNoPublicUpload() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Public upload is not allowed');
+
$share = $this->manager->newShare();
$share->setPermissions(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_allow_public_upload', 'yes', 'no']
- ]));
+ ]);
self::invokePrivate($this->manager, 'linkCreateChecks', [$share]);
}
@@ -1402,10 +1416,10 @@ class ManagerTest extends \Test\TestCase {
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_allow_public_upload', 'yes', 'yes']
- ]));
+ ]);
self::invokePrivate($this->manager, 'linkCreateChecks', [$share]);
$this->addToAssertionCount(1);
@@ -1418,20 +1432,20 @@ class ManagerTest extends \Test\TestCase {
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_allow_links', 'yes', 'yes'],
['core', 'shareapi_allow_public_upload', 'yes', 'no']
- ]));
+ ]);
self::invokePrivate($this->manager, 'linkCreateChecks', [$share]);
$this->addToAssertionCount(1);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Path contains files shared with you
- */
+
public function testPathCreateChecksContainsSharedMount() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Path contains files shared with you');
+
$path = $this->createMock(Folder::class);
$path->method('getPath')->willReturn('path');
@@ -1510,10 +1524,10 @@ class ManagerTest extends \Test\TestCase {
$user = $this->createMock(IUser::class);
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_exclude_groups', 'no', $excludeGroups],
['core', 'shareapi_exclude_groups_list', '', $groupList],
- ]));
+ ]);
if ($setList !== null) {
$this->config->expects($this->once())
@@ -1558,9 +1572,9 @@ class ManagerTest extends \Test\TestCase {
*/
public function testCanShare($expected, $sharingEnabled, $disabledForUser) {
$this->config->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['core', 'shareapi_enabled', 'yes', $sharingEnabled],
- ]));
+ ]);
$manager = $this->createManagerMock()
->setMethods(['sharingDisabledForUser'])
@@ -1612,10 +1626,12 @@ class ManagerTest extends \Test\TestCase {
->willReturn(true);
$manager->expects($this->once())
->method('generalCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('userCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('pathCreateChecks')
->with($path);
@@ -1624,7 +1640,7 @@ class ManagerTest extends \Test\TestCase {
->expects($this->once())
->method('create')
->with($share)
- ->will($this->returnArgument(0));
+ ->willReturnArgument(0);
$share->expects($this->once())
->method('setShareOwner')
@@ -1665,10 +1681,12 @@ class ManagerTest extends \Test\TestCase {
->willReturn(true);
$manager->expects($this->once())
->method('generalCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('groupCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('pathCreateChecks')
->with($path);
@@ -1677,7 +1695,7 @@ class ManagerTest extends \Test\TestCase {
->expects($this->once())
->method('create')
->with($share)
- ->will($this->returnArgument(0));
+ ->willReturnArgument(0);
$share->expects($this->once())
->method('setShareOwner')
@@ -1728,16 +1746,19 @@ class ManagerTest extends \Test\TestCase {
->willReturn(true);
$manager->expects($this->once())
->method('generalCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('linkCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('pathCreateChecks')
->with($path);
$manager->expects($this->once())
->method('validateExpirationDate')
- ->with($share);
+ ->with($share)
+ ->willReturn($share);
$manager->expects($this->once())
->method('verifyPassword')
->with('password');
@@ -1757,16 +1778,16 @@ class ManagerTest extends \Test\TestCase {
->expects($this->once())
->method('create')
->with($share)
- ->will($this->returnCallback(function(Share $share) {
+ ->willReturnCallback(function (Share $share) {
return $share->setId(42);
- }));
+ });
// Pre share
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with(
$this->equalTo('OCP\Share::preShare'),
- $this->callback(function(GenericEvent $e) use ($path, $date) {
+ $this->callback(function (GenericEvent $e) use ($path, $date) {
/** @var IShare $share */
$share = $e->getSubject();
@@ -1785,7 +1806,7 @@ class ManagerTest extends \Test\TestCase {
->method('dispatch')
->with(
$this->equalTo('OCP\Share::postShare'),
- $this->callback(function(GenericEvent $e) use ($path, $date) {
+ $this->callback(function (GenericEvent $e) use ($path, $date) {
/** @var IShare $share */
$share = $e->getSubject();
@@ -1846,7 +1867,8 @@ class ManagerTest extends \Test\TestCase {
->willReturn(true);
$manager->expects($this->once())
->method('generalCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->never())
->method('linkCreateChecks');
$manager->expects($this->once())
@@ -1866,16 +1888,16 @@ class ManagerTest extends \Test\TestCase {
->expects($this->once())
->method('create')
->with($share)
- ->will($this->returnCallback(function(Share $share) {
+ ->willReturnCallback(function (Share $share) {
return $share->setId(42);
- }));
+ });
// Pre share
$this->eventDispatcher->expects($this->at(0))
->method('dispatch')
->with(
$this->equalTo('OCP\Share::preShare'),
- $this->callback(function(GenericEvent $e) use ($path) {
+ $this->callback(function (GenericEvent $e) use ($path) {
/** @var IShare $share */
$share = $e->getSubject();
@@ -1894,7 +1916,7 @@ class ManagerTest extends \Test\TestCase {
->method('dispatch')
->with(
$this->equalTo('OCP\Share::postShare'),
- $this->callback(function(GenericEvent $e) use ($path) {
+ $this->callback(function (GenericEvent $e) use ($path) {
/** @var IShare $share */
$share = $e->getSubject();
@@ -1918,11 +1940,11 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals('token', $share->getToken());
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage I won't let you share
- */
+
public function testCreateShareHookError() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('I won\'t let you share');
+
$manager = $this->createManagerMock()
->setMethods([
'canShare',
@@ -1956,10 +1978,12 @@ class ManagerTest extends \Test\TestCase {
->willReturn(true);
$manager->expects($this->once())
->method('generalCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('userCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('pathCreateChecks')
->with($path);
@@ -1977,10 +2001,10 @@ class ManagerTest extends \Test\TestCase {
->with(
$this->equalTo('OCP\Share::preShare'),
$this->isInstanceOf(GenericEvent::class)
- )->will($this->returnCallback(function($name, GenericEvent $e) {
- $e->setArgument('error', 'I won\'t let you share!');
- $e->stopPropagation();
- })
+ )->willReturnCallback(function ($name, GenericEvent $e) {
+ $e->setArgument('error', 'I won\'t let you share!');
+ $e->stopPropagation();
+ }
);
$manager->createShare($share);
@@ -2034,10 +2058,12 @@ class ManagerTest extends \Test\TestCase {
->willReturn(true);
$manager->expects($this->once())
->method('generalCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('userCreateChecks')
- ->with($share);;
+ ->with($share);
+ ;
$manager->expects($this->once())
->method('pathCreateChecks')
->with($path);
@@ -2046,7 +2072,7 @@ class ManagerTest extends \Test\TestCase {
->expects($this->once())
->method('create')
->with($share)
- ->will($this->returnArgument(0));
+ ->willReturnArgument(0);
$share->expects($this->once())
->method('setShareOwner')
@@ -2129,22 +2155,22 @@ class ManagerTest extends \Test\TestCase {
*/
$this->defaultProvider
->method('getSharesBy')
- ->will($this->returnCallback(function($uid, $type, $node, $reshares, $limit, $offset) use (&$shares2) {
+ ->willReturnCallback(function ($uid, $type, $node, $reshares, $limit, $offset) use (&$shares2) {
return array_slice($shares2, $offset, $limit);
- }));
+ });
/*
* Simulate the deleteShare call.
*/
$manager->method('deleteShare')
- ->will($this->returnCallback(function($share) use (&$shares2) {
- for($i = 0; $i < count($shares2); $i++) {
+ ->willReturnCallback(function ($share) use (&$shares2) {
+ for ($i = 0; $i < count($shares2); $i++) {
if ($shares2[$i]->getId() === $share->getId()) {
array_splice($shares2, $i, 1);
break;
}
}
- }));
+ });
$res = $manager->getSharesBy('user', \OCP\Share::SHARE_TYPE_LINK, $node, true, 3, 0);
@@ -2185,7 +2211,8 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
);
$share = $this->createMock(IShare::class);
@@ -2228,7 +2255,8 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
);
$share = $this->createMock(IShare::class);
@@ -2237,13 +2265,13 @@ class ManagerTest extends \Test\TestCase {
$factory->expects($this->any())
->method('getProviderForType')
- ->will($this->returnCallback(function($shareType) use ($roomShareProvider) {
+ ->willReturnCallback(function ($shareType) use ($roomShareProvider) {
if ($shareType !== \OCP\Share::SHARE_TYPE_ROOM) {
throw new Exception\ProviderException();
}
return $roomShareProvider;
- }));
+ });
$roomShareProvider->expects($this->once())
->method('getShareByToken')
@@ -2278,7 +2306,8 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
);
$share = $this->createMock(IShare::class);
@@ -2305,11 +2334,11 @@ class ManagerTest extends \Test\TestCase {
$this->assertSame($share, $ret);
}
- /**
- * @expectedException \OCP\Share\Exceptions\ShareNotFound
- * @expectedExceptionMessage The requested share does not exist anymore
- */
+
public function testGetShareByTokenExpired() {
+ $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
+ $this->expectExceptionMessage('The requested share does not exist anymore');
+
$this->config
->expects($this->once())
->method('getAppValue')
@@ -2364,10 +2393,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertSame($share, $res);
}
- /**
- * @expectedException \OCP\Share\Exceptions\ShareNotFound
- */
+
public function testGetShareByTokenWithPublicLinksDisabled() {
+ $this->expectException(\OCP\Share\Exceptions\ShareNotFound::class);
+
$this->config
->expects($this->once())
->method('getAppValue')
@@ -2390,9 +2419,9 @@ class ManagerTest extends \Test\TestCase {
$this->config
->expects($this->at(1))
->method('getAppValue')
- ->will($this->returnValueMap([
- ['core', 'shareapi_allow_public_upload', 'yes', 'no'],
- ]));
+ ->willReturnMap([
+ ['core', 'shareapi_allow_public_upload', 'yes', 'no'],
+ ]);
$this->defaultProvider->expects($this->once())
->method('getShareByToken')
@@ -2445,11 +2474,11 @@ class ManagerTest extends \Test\TestCase {
->setPassword('passwordHash');
$this->hasher->method('verify')->with('password', 'passwordHash', '')
- ->will($this->returnCallback(function($pass, $hash, &$newHash) {
+ ->willReturnCallback(function ($pass, $hash, &$newHash) {
$newHash = 'newHash';
return true;
- }));
+ });
$this->defaultProvider->expects($this->once())
->method('update')
@@ -2460,11 +2489,11 @@ class ManagerTest extends \Test\TestCase {
$this->assertTrue($this->manager->checkPassword($share, 'password'));
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Can’t change share type
- */
+
public function testUpdateShareCantChangeShareType() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Can’t change share type');
+
$manager = $this->createManagerMock()
->setMethods([
'canShare',
@@ -2486,11 +2515,11 @@ class ManagerTest extends \Test\TestCase {
$manager->updateShare($share);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Can only update recipient on user shares
- */
+
public function testUpdateShareCantChangeRecipientForGroupShare() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Can only update recipient on user shares');
+
$manager = $this->createManagerMock()
->setMethods([
'canShare',
@@ -2514,11 +2543,11 @@ class ManagerTest extends \Test\TestCase {
$manager->updateShare($share);
}
- /**
- * @expectedException Exception
- * @expectedExceptionMessage Can’t share with the share owner
- */
+
public function testUpdateShareCantShareWithOwner() {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('Can’t share with the share owner');
+
$manager = $this->createManagerMock()
->setMethods([
'canShare',
@@ -2544,7 +2573,6 @@ class ManagerTest extends \Test\TestCase {
}
public function testUpdateShareUser() {
-
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
$manager = $this->createManagerMock()
@@ -2588,7 +2616,7 @@ class ManagerTest extends \Test\TestCase {
\OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post');
$hookListner->expects($this->never())->method('post');
- $this->rootFolder->method('getUserFolder')->with('newUser')->will($this->returnSelf());
+ $this->rootFolder->method('getUserFolder')->with('newUser')->willReturnSelf();
$this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath');
$hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock();
@@ -2883,11 +2911,11 @@ class ManagerTest extends \Test\TestCase {
$manager->updateShare($share);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Can’t enable sending the password by Talk without setting a new password
- */
+
public function testUpdateShareMailEnableSendPasswordByTalkWithNoPassword() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Can’t enable sending the password by Talk without setting a new password');
+
$manager = $this->createManagerMock()
->setMethods([
'canShare',
@@ -2955,11 +2983,11 @@ class ManagerTest extends \Test\TestCase {
$manager->updateShare($share);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Can’t enable sending the password by Talk without setting a new password
- */
+
public function testUpdateShareMailEnableSendPasswordByTalkRemovingPassword() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Can’t enable sending the password by Talk without setting a new password');
+
$manager = $this->createManagerMock()
->setMethods([
'canShare',
@@ -3027,11 +3055,11 @@ class ManagerTest extends \Test\TestCase {
$manager->updateShare($share);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Can’t enable sending the password by Talk without setting a new password
- */
+
public function testUpdateShareMailEnableSendPasswordByTalkRemovingPasswordWithEmptyString() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Can’t enable sending the password by Talk without setting a new password');
+
$manager = $this->createManagerMock()
->setMethods([
'canShare',
@@ -3099,11 +3127,11 @@ class ManagerTest extends \Test\TestCase {
$manager->updateShare($share);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Can’t enable sending the password by Talk without setting a new password
- */
+
public function testUpdateShareMailEnableSendPasswordByTalkWithPreviousPassword() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Can’t enable sending the password by Talk without setting a new password');
+
$manager = $this->createManagerMock()
->setMethods([
'canShare',
@@ -3241,11 +3269,11 @@ class ManagerTest extends \Test\TestCase {
$manager->updateShare($share);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Can’t change target of link share
- */
+
public function testMoveShareLink() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Can’t change target of link share');
+
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_LINK);
@@ -3254,11 +3282,11 @@ class ManagerTest extends \Test\TestCase {
$this->manager->moveShare($share, $recipient);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Invalid recipient
- */
+
public function testMoveShareUserNotRecipient() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Invalid recipient');
+
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_USER);
@@ -3275,17 +3303,17 @@ class ManagerTest extends \Test\TestCase {
$share->setSharedWith('recipient');
- $this->defaultProvider->method('move')->with($share, 'recipient')->will($this->returnArgument(0));
+ $this->defaultProvider->method('move')->with($share, 'recipient')->willReturnArgument(0);
$this->manager->moveShare($share, 'recipient');
$this->addToAssertionCount(1);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Invalid recipient
- */
+
public function testMoveShareGroupNotRecipient() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Invalid recipient');
+
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
@@ -3301,11 +3329,11 @@ class ManagerTest extends \Test\TestCase {
$this->manager->moveShare($share, 'recipient');
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage Group "shareWith" does not exist
- */
+
public function testMoveShareGroupNull() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('Group "shareWith" does not exist');
+
$share = $this->manager->newShare();
$share->setShareType(\OCP\Share::SHARE_TYPE_GROUP);
$share->setSharedWith('shareWith');
@@ -3333,7 +3361,7 @@ class ManagerTest extends \Test\TestCase {
$this->groupManager->method('get')->with('group')->willReturn($group);
$this->userManager->method('get')->with('recipient')->willReturn($recipient);
- $this->defaultProvider->method('move')->with($share, 'recipient')->will($this->returnArgument(0));
+ $this->defaultProvider->method('move')->with($share, 'recipient')->willReturnArgument(0);
$this->manager->moveShare($share, 'recipient');
$this->addToAssertionCount(1);
@@ -3343,7 +3371,6 @@ class ManagerTest extends \Test\TestCase {
* @dataProvider dataTestShareProviderExists
*/
public function testShareProviderExists($shareType, $expected) {
-
$factory = $this->getMockBuilder('OCP\Share\IProviderFactory')->getMock();
$factory->expects($this->any())->method('getProviderForType')
->willReturnCallback(function ($id) {
@@ -3368,7 +3395,8 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
);
$this->assertSame($expected,
$manager->shareProviderExists($shareType)
@@ -3400,7 +3428,8 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
);
$factory->setProvider($this->defaultProvider);
@@ -3463,7 +3492,8 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
);
$factory->setProvider($this->defaultProvider);
@@ -3558,7 +3588,6 @@ class ManagerTest extends \Test\TestCase {
$this->assertSame($expected['public'], $result['public']);
$this->assertSame($expected['remote'], $result['remote']);
$this->assertSame($expected['users'], $result['users']);
-
}
public function testGetAccessListWithCurrentAccess() {
@@ -3579,7 +3608,8 @@ class ManagerTest extends \Test\TestCase {
$this->eventDispatcher,
$this->mailer,
$this->urlGenerator,
- $this->defaults
+ $this->defaults,
+ $this->dispatcher
);
$factory->setProvider($this->defaultProvider);
@@ -3683,7 +3713,58 @@ class ManagerTest extends \Test\TestCase {
$this->assertSame($expected['public'], $result['public']);
$this->assertSame($expected['remote'], $result['remote']);
$this->assertSame($expected['users'], $result['users']);
+ }
+
+ public function testGetAllShares() {
+ $factory = new DummyFactory2($this->createMock(IServerContainer::class));
+ $manager = new Manager(
+ $this->logger,
+ $this->config,
+ $this->secureRandom,
+ $this->hasher,
+ $this->mountManager,
+ $this->groupManager,
+ $this->l,
+ $this->l10nFactory,
+ $factory,
+ $this->userManager,
+ $this->rootFolder,
+ $this->eventDispatcher,
+ $this->mailer,
+ $this->urlGenerator,
+ $this->defaults,
+ $this->dispatcher
+ );
+
+ $factory->setProvider($this->defaultProvider);
+ $extraProvider = $this->createMock(IShareProvider::class);
+ $factory->setSecondProvider($extraProvider);
+
+ $share1 = $this->createMock(IShare::class);
+ $share2 = $this->createMock(IShare::class);
+ $share3 = $this->createMock(IShare::class);
+ $share4 = $this->createMock(IShare::class);
+
+ $this->defaultProvider->method('getAllShares')
+ ->willReturnCallback(function () use ($share1, $share2) {
+ yield $share1;
+ yield $share2;
+ });
+ $extraProvider->method('getAllShares')
+ ->willReturnCallback(function () use ($share3, $share4) {
+ yield $share3;
+ yield $share4;
+ });
+
+ // "yield from", used in "getAllShares()", does not reset the keys, so
+ // "use_keys" has to be disabled to collect all the values while
+ // ignoring the keys returned by the generator.
+ $result = iterator_to_array($manager->getAllShares(), $use_keys = false);
+
+ $expects = [$share1, $share2, $share3, $share4];
+
+ $this->assertSame($expects, $result);
}
}
@@ -3693,7 +3774,6 @@ class DummyFactory implements IProviderFactory {
protected $provider;
public function __construct(\OCP\IServerContainer $serverContainer) {
-
}
/**
diff --git a/tests/lib/Share20/ShareHelperTest.php b/tests/lib/Share20/ShareHelperTest.php
index 69609f9f724..d2f5cd79284 100644
--- a/tests/lib/Share20/ShareHelperTest.php
+++ b/tests/lib/Share20/ShareHelperTest.php
@@ -20,6 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace Test\Share20;
use OC\Share20\ShareHelper;
@@ -36,7 +37,7 @@ class ShareHelperTest extends TestCase {
/** @var ShareHelper */
private $helper;
- public function setUp() {
+ protected function setUp(): void {
parent::setUp();
$this->manager = $this->createMock(IManager::class);
diff --git a/tests/lib/Share20/ShareTest.php b/tests/lib/Share20/ShareTest.php
index fbdf8e5c15b..f7ea479350d 100644
--- a/tests/lib/Share20/ShareTest.php
+++ b/tests/lib/Share20/ShareTest.php
@@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
+
namespace Test\Share20;
use OCP\Files\IRootFolder;
@@ -35,17 +36,17 @@ class ShareTest extends \Test\TestCase {
/** @var \OCP\Share\IShare */
protected $share;
- public function setUp() {
+ protected function setUp(): void {
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->share = new \OC\Share20\Share($this->rootFolder, $this->userManager);
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage String expected.
- */
+
public function testSetIdInvalid() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('String expected.');
+
$this->share->setId(1.2);
}
@@ -60,20 +61,20 @@ class ShareTest extends \Test\TestCase {
$this->assertEquals('foo', $this->share->getId());
}
- /**
- * @expectedException \OCP\Share\Exceptions\IllegalIDChangeException
- * @expectedExceptionMessage Not allowed to assign a new internal id to a share
- */
+
public function testSetIdOnce() {
+ $this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
+ $this->expectExceptionMessage('Not allowed to assign a new internal id to a share');
+
$this->share->setId('foo');
$this->share->setId('bar');
}
- /**
- * @expectedException \InvalidArgumentException
- * @expectedExceptionMessage String expected.
- */
+
public function testSetProviderIdInt() {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage('String expected.');
+
$this->share->setProviderId(42);
}
@@ -84,11 +85,11 @@ class ShareTest extends \Test\TestCase {
$this->assertEquals('foo:bar', $this->share->getFullId());
}
- /**
- * @expectedException \OCP\Share\Exceptions\IllegalIDChangeException
- * @expectedExceptionMessage Not allowed to assign a new provider id to a share
- */
+
public function testSetProviderIdOnce() {
+ $this->expectException(\OCP\Share\Exceptions\IllegalIDChangeException::class);
+ $this->expectExceptionMessage('Not allowed to assign a new provider id to a share');
+
$this->share->setProviderId('foo');
$this->share->setProviderId('bar');
}