diff options
author | Joas Schilling <coding@schilljs.com> | 2016-09-06 14:18:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-06 14:18:57 +0200 |
commit | 6a6af86a1ca14e8b803d7cd8653733842e21d25f (patch) | |
tree | 37af6b38deb4ead471847261355dc9ef72287231 /tests/lib | |
parent | 45a84f362333e8055227ea800bf67a8ea431f3d5 (diff) | |
parent | c609e291bd5dce6976defc0537cdf48a3cc3528b (diff) | |
download | nextcloud-server-6a6af86a1ca14e8b803d7cd8653733842e21d25f.tar.gz nextcloud-server-6a6af86a1ca14e8b803d7cd8653733842e21d25f.zip |
Merge pull request #1242 from nextcloud/bump_phpunit
Bump phpunit
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/Authentication/Token/DefaultTokenMapperTest.php | 9 | ||||
-rw-r--r-- | tests/lib/Authentication/Token/DefaultTokenProviderTest.php | 19 | ||||
-rw-r--r-- | tests/lib/Authentication/TwoFactorAuth/ManagerTest.php | 10 | ||||
-rw-r--r-- | tests/lib/AvatarTest.php | 30 | ||||
-rw-r--r-- | tests/lib/Share20/DefaultShareProviderTest.php | 229 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 196 |
6 files changed, 258 insertions, 235 deletions
diff --git a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php index 6b73cab5ed0..d71d9468477 100644 --- a/tests/lib/Authentication/Token/DefaultTokenMapperTest.php +++ b/tests/lib/Authentication/Token/DefaultTokenMapperTest.php @@ -27,6 +27,7 @@ use OC\Authentication\Token\DefaultToken; use OC\Authentication\Token\DefaultTokenMapper; use OC\Authentication\Token\IToken; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IUser; use Test\TestCase; /** @@ -150,7 +151,7 @@ class DefaultTokenMapperTest extends TestCase { } public function testGetTokenByUser() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getUID') ->will($this->returnValue('user1')); @@ -159,7 +160,7 @@ class DefaultTokenMapperTest extends TestCase { } public function testGetTokenByUserNotFound() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->expects($this->once()) ->method('getUID') ->will($this->returnValue('user1000')); @@ -168,7 +169,7 @@ class DefaultTokenMapperTest extends TestCase { } public function testDeleteById() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $qb = $this->dbConnection->getQueryBuilder(); $qb->select('id') ->from('authtoken') @@ -184,7 +185,7 @@ class DefaultTokenMapperTest extends TestCase { } public function testDeleteByIdWrongUser() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $id = 33; $user->expects($this->once()) ->method('getUID') diff --git a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php index 28a59529dec..7f90cf051f4 100644 --- a/tests/lib/Authentication/Token/DefaultTokenProviderTest.php +++ b/tests/lib/Authentication/Token/DefaultTokenProviderTest.php @@ -26,6 +26,11 @@ use OC\Authentication\Token\DefaultToken; use OC\Authentication\Token\DefaultTokenProvider; use OC\Authentication\Token\IToken; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\IConfig; +use OCP\ILogger; +use OCP\IUser; +use OCP\Security\ICrypto; use Test\TestCase; class DefaultTokenProviderTest extends TestCase { @@ -45,10 +50,10 @@ class DefaultTokenProviderTest extends TestCase { $this->mapper = $this->getMockBuilder('\OC\Authentication\Token\DefaultTokenMapper') ->disableOriginalConstructor() ->getMock(); - $this->crypto = $this->getMock('\OCP\Security\ICrypto'); - $this->config = $this->getMock('\OCP\IConfig'); - $this->logger = $this->getMock('\OCP\ILogger'); - $this->timeFactory = $this->getMock('\OCP\AppFramework\Utility\ITimeFactory'); + $this->crypto = $this->createMock(ICrypto::class); + $this->config = $this->createMock(IConfig::class); + $this->logger = $this->createMock(ILogger::class); + $this->timeFactory = $this->createMock(ITimeFactory::class); $this->time = 1313131; $this->timeFactory->expects($this->any()) ->method('getTime') @@ -118,7 +123,7 @@ class DefaultTokenProviderTest extends TestCase { } public function testGetTokenByUser() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->mapper->expects($this->once()) ->method('getTokenByUser') ->with($user) @@ -212,7 +217,7 @@ class DefaultTokenProviderTest extends TestCase { * @expectedException \OC\Authentication\Exceptions\InvalidTokenException */ public function testSetPasswordInvalidToken() { - $token = $this->getMock('\OC\Authentication\Token\IToken'); + $token = $this->createMock(IToken::class); $tokenId = 'token123'; $password = '123456'; @@ -229,7 +234,7 @@ class DefaultTokenProviderTest extends TestCase { public function testInvaildateTokenById() { $id = 123; - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->mapper->expects($this->once()) ->method('deleteById') diff --git a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php index 83a74f2f253..b3fd28a30ad 100644 --- a/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/ManagerTest.php @@ -59,19 +59,19 @@ class ManagerTest extends TestCase { protected function setUp() { parent::setUp(); - $this->user = $this->getMockBuilder('\OCP\IUser')->getMock(); + $this->user = $this->createMock(IUser::class); $this->appManager = $this->getMockBuilder('\OC\App\AppManager') ->disableOriginalConstructor() ->getMock(); - $this->session = $this->getMockBuilder('\OCP\ISession')->getMock(); - $this->config = $this->getMockBuilder('\OCP\IConfig')->getMock(); + $this->session = $this->createMock(ISession::class); + $this->config = $this->createMock(IConfig::class); $this->manager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager') ->setConstructorArgs([$this->appManager, $this->session, $this->config]) ->setMethods(['loadTwoFactorApp']) // Do not actually load the apps ->getMock(); - $this->fakeProvider = $this->getMockBuilder('\OCP\Authentication\TwoFactorAuth\IProvider')->getMock(); + $this->fakeProvider = $this->createMock(IProvider::class); $this->fakeProvider->expects($this->any()) ->method('getId') ->will($this->returnValue('email')); @@ -268,7 +268,7 @@ class ManagerTest extends TestCase { } public function testNeedsSecondFactor() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->session->expects($this->once()) ->method('exists') ->with('two_factor_auth_uid') diff --git a/tests/lib/AvatarTest.php b/tests/lib/AvatarTest.php index f515f0d013f..7f012c895fd 100644 --- a/tests/lib/AvatarTest.php +++ b/tests/lib/AvatarTest.php @@ -8,7 +8,11 @@ namespace Test; +use OCP\Files\File; use OCP\Files\Folder; +use OCP\IConfig; +use OCP\IL10N; +use OCP\ILogger; class AvatarTest extends \Test\TestCase { /** @var Folder | \PHPUnit_Framework_MockObject_MockObject */ @@ -26,18 +30,18 @@ class AvatarTest extends \Test\TestCase { public function setUp() { parent::setUp(); - $this->folder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $this->folder = $this->createMock(Folder::class); /** @var \OCP\IL10N | \PHPUnit_Framework_MockObject_MockObject $l */ - $l = $this->getMockBuilder('OCP\IL10N')->getMock(); + $l = $this->createMock(IL10N::class); $l->method('t')->will($this->returnArgument(0)); $this->user = $this->getMockBuilder('OC\User\User')->disableOriginalConstructor()->getMock(); - $this->config = $this->getMockBuilder('OCP\IConfig')->getMock(); + $this->config = $this->createMock(IConfig::class); $this->avatar = new \OC\Avatar( $this->folder, $l, $this->user, - $this->getMockBuilder('\OCP\ILogger')->getMock(), + $this->createMock(ILogger::class), $this->config ); } @@ -55,7 +59,7 @@ class AvatarTest extends \Test\TestCase { $expected = new \OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); - $file = $this->getMockBuilder('OCP\Files\File')->getMock(); + $file = $this->createMock(File::class); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('get')->with('avatar.128.jpg')->willReturn($file); @@ -70,7 +74,7 @@ class AvatarTest extends \Test\TestCase { $expected = new \OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); - $file = $this->getMockBuilder('OCP\Files\File')->getMock(); + $file = $this->createMock(File::class); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('get')->with('avatar.jpg')->willReturn($file); @@ -88,7 +92,7 @@ class AvatarTest extends \Test\TestCase { $expected2 = new \OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); $expected2->resize(32); - $file = $this->getMockBuilder('OCP\Files\File')->getMock(); + $file = $this->createMock(File::class); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('get') @@ -102,7 +106,7 @@ class AvatarTest extends \Test\TestCase { } )); - $newFile = $this->getMockBuilder('OCP\Files\File')->getMock(); + $newFile = $this->createMock(File::class); $newFile->expects($this->once()) ->method('putContent') ->with($expected2->data()); @@ -140,22 +144,22 @@ class AvatarTest extends \Test\TestCase { } public function testSetAvatar() { - $avatarFileJPG = $this->getMockBuilder('OCP\Files\File')->getMock(); + $avatarFileJPG = $this->createMock(File::class); $avatarFileJPG->method('getName') ->willReturn('avatar.jpg'); $avatarFileJPG->expects($this->once())->method('delete'); - $avatarFilePNG = $this->getMockBuilder('OCP\Files\File')->getMock(); + $avatarFilePNG = $this->createMock(File::class); $avatarFilePNG->method('getName') ->willReturn('avatar.png'); $avatarFilePNG->expects($this->once())->method('delete'); - $resizedAvatarFile = $this->getMockBuilder('OCP\Files\File')->getMock(); + $resizedAvatarFile = $this->createMock(File::class); $resizedAvatarFile->method('getName') ->willReturn('avatar.32.jpg'); $resizedAvatarFile->expects($this->once())->method('delete'); - $nonAvatarFile = $this->getMockBuilder('OCP\Files\File')->getMock(); + $nonAvatarFile = $this->createMock(File::class); $nonAvatarFile->method('getName') ->willReturn('avatarX'); $nonAvatarFile->expects($this->never())->method('delete'); @@ -163,7 +167,7 @@ class AvatarTest extends \Test\TestCase { $this->folder->method('getDirectoryListing') ->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile, $nonAvatarFile]); - $newFile = $this->getMockBuilder('OCP\Files\File')->getMock(); + $newFile = $this->createMock(File::class); $this->folder->expects($this->once()) ->method('newFile') ->with('avatar.png') diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 6ef00721a70..ae9ad47b9ae 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -22,11 +22,16 @@ namespace Test\Share20; use OC\Share20\Exception\ProviderException; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Files\File; +use OCP\Files\Folder; use OCP\IDBConnection; +use OCP\IGroup; +use OCP\IUser; use OCP\IUserManager; use OCP\IGroupManager; use OCP\Files\IRootFolder; use OC\Share20\DefaultShareProvider; +use OCP\Share\IShare; /** * Class DefaultShareProviderTest @@ -53,9 +58,9 @@ class DefaultShareProviderTest extends \Test\TestCase { public function setUp() { $this->dbConn = \OC::$server->getDatabaseConnection(); - $this->userManager = $this->getMock('OCP\IUserManager'); - $this->groupManager = $this->getMock('OCP\IGroupManager'); - $this->rootFolder = $this->getMock('OCP\Files\IRootFolder'); + $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->rootFolder = $this->createMock(IRootFolder::class); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); @@ -136,13 +141,13 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $sharedBy = $this->getMock('OCP\IUser'); + $sharedBy = $this->createMock(IUser::class); $sharedBy->method('getUID')->willReturn('sharedBy'); - $shareOwner = $this->getMock('OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $ownerPath = $this->getMock('\OCP\Files\File'); - $shareOwnerFolder = $this->getMock('\OCP\Files\Folder'); + $ownerPath = $this->createMock(File::class); + $shareOwnerFolder = $this->createMock(Folder::class); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder @@ -218,9 +223,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $ownerPath = $this->getMock('\OCP\Files\File'); + $ownerPath = $this->createMock(File::class); - $shareOwnerFolder = $this->getMock('\OCP\Files\Folder'); + $shareOwnerFolder = $this->createMock(Folder::class); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder @@ -263,8 +268,8 @@ class DefaultShareProviderTest extends \Test\TestCase { // Get the id $id = $qb->getLastInsertId(); - $ownerPath = $this->getMock('\OCP\Files\Folder'); - $shareOwnerFolder = $this->getMock('\OCP\Files\Folder'); + $ownerPath = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(Folder::class); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder @@ -291,15 +296,15 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user0', 'user0', 'file', 42, 'myTarget', 31, null, null); $this->addShareToDB(2, 'user1', 'user0', 'user0', 'file', 42, 'userTarget', 0, null, null, $id); - $user0 = $this->getMock('OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $group0 = $this->getMock('OCP\IGroup'); + $group0 = $this->createMock(IGroup::class); $group0->method('inGroup')->with($user1)->willReturn(true); - $node = $this->getMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $node->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('user0')->will($this->returnSelf()); @@ -345,8 +350,8 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $ownerPath = $this->getMock('\OCP\Files\Folder'); - $shareOwnerFolder = $this->getMock('\OCP\Files\Folder'); + $ownerPath = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(Folder::class); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder @@ -385,7 +390,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $share = $this->getMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getId')->willReturn($id); $provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider') @@ -473,7 +478,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $share = $this->getMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getId')->willReturn($id); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); @@ -548,8 +553,8 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $qb->execute(); - $ownerPath = $this->getMock('\OCP\Files\Folder'); - $ownerFolder = $this->getMock('\OCP\Files\Folder'); + $ownerPath = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(Folder::class); $ownerFolder->method('getById')->willReturn([$ownerPath]); $this->rootFolder @@ -558,7 +563,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['shareOwner', $ownerFolder], ])); - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getId')->willReturn($id); $children = $this->provider->getChildren($share); @@ -591,15 +596,15 @@ class DefaultShareProviderTest extends \Test\TestCase { public function testCreateUserShare() { $share = new \OC\Share20\Share($this->rootFolder, $this->userManager); - $shareOwner = $this->getMock('OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->WillReturn('shareOwner'); - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->getMock('OCP\Files\Folder'); - $userFolder = $this->getMock('OCP\Files\Folder'); + $ownerFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(Folder::class); $this->rootFolder ->method('getUserFolder') ->will($this->returnValueMap([ @@ -639,15 +644,15 @@ class DefaultShareProviderTest extends \Test\TestCase { public function testCreateGroupShare() { $share = new \OC\Share20\Share($this->rootFolder, $this->userManager); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $path = $this->getMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->getMock('OCP\Files\Folder'); - $userFolder = $this->getMock('OCP\Files\Folder'); + $ownerFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(Folder::class); $this->rootFolder ->method('getUserFolder') ->will($this->returnValueMap([ @@ -687,15 +692,15 @@ class DefaultShareProviderTest extends \Test\TestCase { public function testCreateLinkShare() { $share = new \OC\Share20\Share($this->rootFolder, $this->userManager); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $path = $this->getMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->getMock('OCP\Files\Folder'); - $userFolder = $this->getMock('OCP\Files\Folder'); + $ownerFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(Folder::class); $this->rootFolder ->method('getUserFolder') ->will($this->returnValueMap([ @@ -755,7 +760,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $qb->execute(); $id = $qb->getLastInsertId(); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -806,7 +811,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -853,20 +858,20 @@ class DefaultShareProviderTest extends \Test\TestCase { $groups = []; foreach(range(0, 100) as $i) { - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'.$i); $groups[] = $group; } - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('sharedWith'); $groups[] = $group; - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('sharedWith'); - $owner = $this->getMock('\OCP\IUser'); + $owner = $this->createMock(IUser::class); $owner->method('getUID')->willReturn('shareOwner'); - $initiator = $this->getMock('\OCP\IUser'); + $initiator = $this->createMock(IUser::class); $initiator->method('getUID')->willReturn('sharedBy'); $this->userManager->method('get')->willReturnMap([ @@ -877,7 +882,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->groupManager->method('getUserGroups')->with($user)->willReturn($groups); $this->groupManager->method('get')->with('sharedWith')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -944,15 +949,15 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('sharedWith'); $groups = [$group]; - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'); - $owner = $this->getMock('\OCP\IUser'); + $owner = $this->createMock(IUser::class); $owner->method('getUID')->willReturn('shareOwner'); - $initiator = $this->getMock('\OCP\IUser'); + $initiator = $this->createMock(IUser::class); $initiator->method('getUID')->willReturn('sharedBy'); $this->userManager->method('get')->willReturnMap([ @@ -963,7 +968,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->groupManager->method('getUserGroups')->with($user)->willReturn($groups); $this->groupManager->method('get')->with('sharedWith')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -986,9 +991,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_USER, 'user0', 'user1', 'user1', 'file', 43, 'myTarget', 31, null, null, null); - $user0 = $this->getMock('\OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); $this->userManager->method('get')->willReturnMap([ @@ -996,7 +1001,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['user1', $user1], ]); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(43); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(43)->willReturn([$file]); @@ -1019,9 +1024,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1', 'file', 43, 'myTarget', 31, null, null, null); - $user0 = $this->getMock('\OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); $this->userManager->method('get')->willReturnMap([ @@ -1029,13 +1034,13 @@ class DefaultShareProviderTest extends \Test\TestCase { ['user1', $user1], ]); - $group0 = $this->getMock('\OCP\IGroup'); + $group0 = $this->createMock(IGroup::class); $group0->method('getGID')->willReturn('group0'); $this->groupManager->method('get')->with('group0')->willReturn($group0); $this->groupManager->method('getUserGroups')->with($user0)->willReturn([$group0]); - $node = $this->getMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $node->method('getId')->willReturn(43); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(43)->willReturn([$node]); @@ -1083,7 +1088,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -1131,7 +1136,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -1180,7 +1185,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $qb->execute()); $id2 = $qb->getLastInsertId(); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -1223,21 +1228,21 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'); $group->method('inGroup')->with($user2)->willReturn(true); $this->groupManager->method('get')->with('group')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1294,21 +1299,21 @@ class DefaultShareProviderTest extends \Test\TestCase { ])->execute(); $this->assertEquals(1, $stmt); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'); $group->method('inGroup')->with($user2)->willReturn(true); $this->groupManager->method('get')->with('group')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1354,21 +1359,21 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'); $group->method('inGroup')->with($user2)->willReturn(false); $this->groupManager->method('get')->with('group')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1395,16 +1400,16 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1446,17 +1451,17 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); - $user3 = $this->getMock('\OCP\IUser'); + $user3 = $this->createMock(IUser::class); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1487,13 +1492,13 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ])); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1510,7 +1515,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1521,14 +1526,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1559,7 +1564,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1570,14 +1575,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1608,7 +1613,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1619,14 +1624,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1657,7 +1662,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1670,7 +1675,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $groups = []; for($i = 0; $i < 2; $i++) { - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'.$i); $groups['group'.$i] = $group; } @@ -1681,14 +1686,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1726,7 +1731,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1739,7 +1744,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $groups = []; for($i = 0; $i < 2; $i++) { - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'.$i); $groups['group'.$i] = $group; } @@ -1750,14 +1755,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1809,9 +1814,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_USER, 'user0', 'user1', 'user1', 'file', 42, 'mytaret', 31, null, null); - $user0 = $this->getMock('\OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); $this->userManager->method('get')->will($this->returnValueMap([ @@ -1819,7 +1824,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['user1', $user1], ])); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1838,12 +1843,12 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1', 'file', 42, 'mytaret', 31, null, null); - $user0 = $this->getMock('\OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $group0 = $this->getMock('\OCP\IGroup'); + $group0 = $this->createMock(IGroup::class); $group0->method('getGID')->willReturn('group0'); $group0->method('inGroup')->with($user0)->willReturn(true); @@ -1854,7 +1859,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['user1', $user1], ])); - $folder = $this->getMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $folder->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 689e47d8c52..16ad1b07f89 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -20,8 +20,16 @@ */ namespace Test\Share20; +use OC\Files\Mount\MoveableMount; use OC\HintException; +use OCP\Files\File; +use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountPoint; +use OCP\Files\Node; +use OCP\Files\Storage; +use OCP\IGroup; +use OCP\IUser; use OCP\IUserManager; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IProviderFactory; @@ -78,17 +86,17 @@ class ManagerTest extends \Test\TestCase { public function setUp() { - $this->logger = $this->getMock('\OCP\ILogger'); - $this->config = $this->getMock('\OCP\IConfig'); - $this->secureRandom = $this->getMock('\OCP\Security\ISecureRandom'); - $this->hasher = $this->getMock('\OCP\Security\IHasher'); - $this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager'); - $this->groupManager = $this->getMock('\OCP\IGroupManager'); - $this->userManager = $this->getMock('\OCP\IUserManager'); - $this->rootFolder = $this->getMock('\OCP\Files\IRootFolder'); - $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher'); - - $this->l = $this->getMock('\OCP\IL10N'); + $this->logger = $this->createMock(ILogger::class); + $this->config = $this->createMock(IConfig::class); + $this->secureRandom = $this->createMock(ISecureRandom::class); + $this->hasher = $this->createMock(IHasher::class); + $this->mountManager = $this->createMock(IMountManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->eventDispatcher = $this->createMock(EventDispatcher::class); + + $this->l = $this->createMock(IL10N::class); $this->l->method('t') ->will($this->returnCallback(function($text, $parameters = []) { return vsprintf($text, $parameters); @@ -149,10 +157,10 @@ class ManagerTest extends \Test\TestCase { } public function dataTestDelete() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('sharedWithUser'); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('sharedWithGroup'); return [ @@ -171,7 +179,7 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['getShareById', 'deleteChildren']) ->getMock(); - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(1); $share = $this->manager->newShare(); @@ -328,7 +336,7 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['getShareById']) ->getMock(); - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(1); $share1 = $this->manager->newShare(); @@ -451,14 +459,14 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['deleteShare']) ->getMock(); - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child1 = $this->getMock('\OCP\Share\IShare'); + $child1 = $this->createMock(IShare::class); $child1->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child2 = $this->getMock('\OCP\Share\IShare'); + $child2 = $this->createMock(IShare::class); $child2->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child3 = $this->getMock('\OCP\Share\IShare'); + $child3 = $this->createMock(IShare::class); $child3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $shares = [ @@ -487,7 +495,7 @@ class ManagerTest extends \Test\TestCase { } public function testGetShareById() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $this->defaultProvider ->expects($this->once()) @@ -584,7 +592,7 @@ class ManagerTest extends \Test\TestCase { public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner, $permissions, $expireDate = null, $password = null) { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn($type); $share->method('getSharedWith')->willReturn($sharedWith); @@ -603,8 +611,8 @@ class ManagerTest extends \Test\TestCase { $user2 = 'user1'; $group0 = 'group0'; - $file = $this->getMock('\OCP\Files\File'); - $node = $this->getMock('\OCP\Files\Node'); + $file = $this->createMock(File::class); + $node = $this->createMock(Node::class); $data = [ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true], @@ -633,7 +641,7 @@ class ManagerTest extends \Test\TestCase { [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $node, null, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true], ]; - $nonShareAble = $this->getMock('\OCP\Files\Folder'); + $nonShareAble = $this->createMock(Folder::class); $nonShareAble->method('isShareable')->willReturn(false); $nonShareAble->method('getPath')->willReturn('path'); @@ -641,7 +649,7 @@ class ManagerTest extends \Test\TestCase { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share path', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share path', true]; - $limitedPermssions = $this->getMock('\OCP\Files\File'); + $limitedPermssions = $this->createMock(File::class); $limitedPermssions->method('isShareable')->willReturn(true); $limitedPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ); $limitedPermssions->method('getPath')->willReturn('path'); @@ -650,14 +658,14 @@ class ManagerTest extends \Test\TestCase { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'A share requires permissions', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null), 'A share requires permissions', true]; - $mount = $this->getMock('OC\Files\Mount\MoveableMount'); + $mount = $this->createMock(MoveableMount::class); $limitedPermssions->method('getMountPoint')->willReturn($mount); $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of path', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true]; - $nonMoveableMountPermssions = $this->getMock('\OCP\Files\Folder'); + $nonMoveableMountPermssions = $this->createMock(Folder::class); $nonMoveableMountPermssions->method('isShareable')->willReturn(true); $nonMoveableMountPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ); $nonMoveableMountPermssions->method('getPath')->willReturn('path'); @@ -665,7 +673,7 @@ class ManagerTest extends \Test\TestCase { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false]; - $rootFolder = $this->getMock('\OCP\Files\Folder'); + $rootFolder = $this->createMock(Folder::class); $rootFolder->method('isShareable')->willReturn(true); $rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); $rootFolder->method('getPath')->willReturn('myrootfolder'); @@ -674,7 +682,7 @@ class ManagerTest extends \Test\TestCase { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You can\'t share your root folder', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You can\'t share your root folder', true]; - $allPermssions = $this->getMock('\OCP\Files\Folder'); + $allPermssions = $this->createMock(Folder::class); $allPermssions->method('isShareable')->willReturn(true); $allPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); @@ -706,7 +714,7 @@ class ManagerTest extends \Test\TestCase { ['group0', true], ])); - $userFolder = $this->getMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $userFolder->method('getPath')->willReturn('myrootfolder'); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); @@ -737,7 +745,7 @@ class ManagerTest extends \Test\TestCase { ['user1', true], ])); - $userFolder = $this->getMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $userFolder->method('isSubNode')->with($userFolder)->willReturn(false); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); @@ -1000,8 +1008,8 @@ class ManagerTest extends \Test\TestCase { public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() { $share = $this->manager->newShare(); - $sharedBy = $this->getMock('\OCP\IUser'); - $sharedWith = $this->getMock('\OCP\IUser'); + $sharedBy = $this->createMock(IUser::class); + $sharedWith = $this->createMock(IUser::class); $share->setSharedBy('sharedBy')->setSharedWith('sharedWith'); $this->groupManager @@ -1030,11 +1038,11 @@ class ManagerTest extends \Test\TestCase { public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() { $share = $this->manager->newShare(); - $sharedBy = $this->getMock('\OCP\IUser'); - $sharedWith = $this->getMock('\OCP\IUser'); + $sharedBy = $this->createMock(IUser::class); + $sharedWith = $this->createMock(IUser::class); $share->setSharedBy('sharedBy')->setSharedWith('sharedWith'); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $this->groupManager @@ -1073,8 +1081,8 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share2 = $this->manager->newShare(); - $sharedWith = $this->getMock('\OCP\IUser'); - $path = $this->getMock('\OCP\Files\Node'); + $sharedWith = $this->createMock(IUser::class); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith')->setNode($path) ->setProviderId('foo')->setId('bar'); @@ -1097,12 +1105,12 @@ class ManagerTest extends \Test\TestCase { public function testUserCreateChecksIdenticalPathSharedViaGroup() { $share = $this->manager->newShare(); - $sharedWith = $this->getMock('\OCP\IUser'); + $sharedWith = $this->createMock(IUser::class); $sharedWith->method('getUID')->willReturn('sharedWith'); $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) @@ -1117,7 +1125,7 @@ class ManagerTest extends \Test\TestCase { ->setId('baz') ->setSharedWith('group'); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('inGroup') ->with($sharedWith) ->willReturn(true); @@ -1134,8 +1142,8 @@ class ManagerTest extends \Test\TestCase { public function testUserCreateChecksIdenticalPathNotSharedWithUser() { $share = $this->manager->newShare(); - $sharedWith = $this->getMock('\OCP\IUser'); - $path = $this->getMock('\OCP\Files\Node'); + $sharedWith = $this->createMock(IUser::class); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) ->setShareOwner('shareOwner') @@ -1150,7 +1158,7 @@ class ManagerTest extends \Test\TestCase { ->setProviderId('foo') ->setId('baz'); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('inGroup') ->with($sharedWith) ->willReturn(false); @@ -1190,8 +1198,8 @@ class ManagerTest extends \Test\TestCase { public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() { $share = $this->manager->newShare(); - $user = $this->getMock('\OCP\IUser'); - $group = $this->getMock('\OCP\IGroup'); + $user = $this->createMock(IUser::class); + $group = $this->createMock(IGroup::class); $share->setSharedBy('user')->setSharedWith('group'); $group->method('inGroup')->with($user)->willReturn(false); @@ -1212,8 +1220,8 @@ class ManagerTest extends \Test\TestCase { public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() { $share = $this->manager->newShare(); - $user = $this->getMock('\OCP\IUser'); - $group = $this->getMock('\OCP\IGroup'); + $user = $this->createMock(IUser::class); + $group = $this->createMock(IGroup::class); $share->setSharedBy('user')->setSharedWith('group'); $this->userManager->method('get')->with('user')->willReturn($user); @@ -1221,7 +1229,7 @@ class ManagerTest extends \Test\TestCase { $group->method('inGroup')->with($user)->willReturn(true); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $this->defaultProvider->method('getSharesByPath') @@ -1245,7 +1253,7 @@ class ManagerTest extends \Test\TestCase { public function testGroupCreateChecksPathAlreadySharedWithSameGroup() { $share = $this->manager->newShare(); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) ->setProviderId('foo') @@ -1274,7 +1282,7 @@ class ManagerTest extends \Test\TestCase { $share->setSharedWith('sharedWith'); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $share2 = $this->manager->newShare(); @@ -1381,11 +1389,11 @@ class ManagerTest extends \Test\TestCase { * @expectedExceptionMessage Path contains files shared with you */ public function testPathCreateChecksContainsSharedMount() { - $path = $this->getMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getPath')->willReturn('path'); - $mount = $this->getMock('\OCP\Files\Mount\IMountPoint'); - $storage = $this->getMock('\OCP\Files\Storage'); + $mount = $this->createMock(IMountPoint::class); + $storage = $this->createMock(Storage::class); $mount->method('getStorage')->willReturn($storage); $storage->method('instanceOfStorage')->with('\OCA\Files_Sharing\ISharedStorage')->willReturn(true); @@ -1395,11 +1403,11 @@ class ManagerTest extends \Test\TestCase { } public function testPathCreateChecksContainsNoSharedMount() { - $path = $this->getMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getPath')->willReturn('path'); - $mount = $this->getMock('\OCP\Files\Mount\IMountPoint'); - $storage = $this->getMock('\OCP\Files\Storage'); + $mount = $this->createMock(IMountPoint::class); + $storage = $this->createMock(Storage::class); $mount->method('getStorage')->willReturn($storage); $storage->method('instanceOfStorage')->with('\OCA\Files_Sharing\ISharedStorage')->willReturn(false); @@ -1409,7 +1417,7 @@ class ManagerTest extends \Test\TestCase { } public function testPathCreateChecksContainsNoFolder() { - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $this->invokePrivate($this->manager, 'pathCreateChecks', [$path]); } @@ -1454,7 +1462,7 @@ class ManagerTest extends \Test\TestCase { * @param bool $expected */ public function testIsSharingDisabledForUser($excludeGroups, $groupList, $setList, $groupIds, $expected) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->config->method('getAppValue') ->will($this->returnValueMap([ @@ -1535,11 +1543,11 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); - $path = $this->getMock('\OCP\Files\File'); + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -1588,11 +1596,11 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); - $path = $this->getMock('\OCP\Files\File'); + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -1649,11 +1657,11 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); - $path = $this->getMock('\OCP\Files\File'); + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getId')->willReturn(1); @@ -1775,11 +1783,11 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); - $path = $this->getMock('\OCP\Files\File'); + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -1831,28 +1839,28 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); + $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->with('OCA\Files_Sharing\External\Storage') ->willReturn(true); - $storage2 = $this->getMock('\OCP\Files\Storage'); + $storage2 = $this->createMock(Storage::class); $storage2->method('instanceOfStorage') ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->expects($this->never())->method('getOwner'); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); - $parent = $this->getMock('\OCP\Files\Folder'); + $parent = $this->createMock(Folder::class); $parent->method('getStorage')->willReturn($storage); - $parentParent = $this->getMock('\OCP\Files\Folder'); + $parentParent = $this->createMock(Folder::class); $parentParent->method('getStorage')->willReturn($storage2); $parentParent->method('getOwner')->willReturn($shareOwner); @@ -1901,7 +1909,7 @@ class ManagerTest extends \Test\TestCase { public function testGetSharesBy() { $share = $this->manager->newShare(); - $node = $this->getMock('OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $this->defaultProvider->expects($this->once()) ->method('getSharesBy') @@ -1962,7 +1970,7 @@ class ManagerTest extends \Test\TestCase { $shares2[] = clone $shares[$i]; } - $node = $this->getMock('OCP\Files\File'); + $node = $this->createMock(File::class); /* * Simulate the getSharesBy call. @@ -2002,7 +2010,7 @@ class ManagerTest extends \Test\TestCase { } public function testGetShareByToken() { - $factory = $this->getMock('\OCP\Share\IProviderFactory'); + $factory = $this->createMock(IProviderFactory::class); $manager = new Manager( $this->logger, @@ -2018,7 +2026,7 @@ class ManagerTest extends \Test\TestCase { $this->eventDispatcher ); - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $factory->expects($this->once()) ->method('getProviderForType') @@ -2035,7 +2043,7 @@ class ManagerTest extends \Test\TestCase { } public function testGetShareByTokenWithException() { - $factory = $this->getMock('\OCP\Share\IProviderFactory'); + $factory = $this->createMock(IProviderFactory::class); $manager = new Manager( $this->logger, @@ -2051,7 +2059,7 @@ class ManagerTest extends \Test\TestCase { $this->eventDispatcher ); - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $factory->expects($this->at(0)) ->method('getProviderForType') @@ -2137,13 +2145,13 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordNoLinkShare() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $this->assertFalse($this->manager->checkPassword($share, 'password')); } public function testCheckPasswordNoPassword() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $this->assertFalse($this->manager->checkPassword($share, 'password')); @@ -2152,7 +2160,7 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordInvalidPassword() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getPassword')->willReturn('password'); @@ -2162,7 +2170,7 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordValidPassword() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getPassword')->willReturn('passwordHash'); @@ -2294,7 +2302,7 @@ class ManagerTest extends \Test\TestCase { ->setSharedWith('origUser') ->setPermissions(1); - $node = $this->getMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(100); $node->method('getPath')->willReturn('/newUser/files/myPath'); @@ -2357,7 +2365,7 @@ class ManagerTest extends \Test\TestCase { $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $node = $this->getMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $share = $this->manager->newShare(); $share->setProviderId('foo') @@ -2453,7 +2461,7 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setShareType(\OCP\Share::SHARE_TYPE_LINK); - $recipient = $this->getMock('\OCP\IUser'); + $recipient = $this->createMock(IUser::class); $this->manager->moveShare($share, $recipient); } @@ -2492,10 +2500,10 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP); - $sharedWith = $this->getMock('\OCP\IGroup'); + $sharedWith = $this->createMock(IGroup::class); $share->setSharedWith('shareWith'); - $recipient = $this->getMock('\OCP\IUser'); + $recipient = $this->createMock(IUser::class); $sharedWith->method('inGroup')->with($recipient)->willReturn(false); $this->groupManager->method('get')->with('shareWith')->willReturn($sharedWith); @@ -2510,10 +2518,10 @@ class ManagerTest extends \Test\TestCase { ->setId('42') ->setProviderId('foo'); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $share->setSharedWith('group'); - $recipient = $this->getMock('\OCP\IUser'); + $recipient = $this->createMock(IUser::class); $group->method('inGroup')->with($recipient)->willReturn(true); $this->groupManager->method('get')->with('group')->willReturn($group); |