diff options
Diffstat (limited to 'tests/lib/Share20')
-rw-r--r-- | tests/lib/Share20/DefaultShareProviderTest.php | 48 | ||||
-rw-r--r-- | tests/lib/Share20/LegacyHooksTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Share20/ManagerTest.php | 260 | ||||
-rw-r--r-- | tests/lib/Share20/ShareHelperTest.php | 2 | ||||
-rw-r--r-- | tests/lib/Share20/ShareTest.php | 34 |
5 files changed, 173 insertions, 173 deletions
diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 0f0e77c3207..ff3cafbdf7c 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -73,7 +73,7 @@ class DefaultShareProviderTest extends \Test\TestCase { /** @var \PHPUnit_Framework_MockObject_MockObject|IURLGenerator */ protected $urlGenerator; - public function setUp(): void { + protected function setUp(): void { $this->dbConn = \OC::$server->getDatabaseConnection(); $this->userManager = $this->createMock(IUserManager::class); $this->groupManager = $this->createMock(IGroupManager::class); @@ -100,7 +100,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ); } - public function tearDown(): void { + protected function tearDown(): void { $this->dbConn->getQueryBuilder()->delete('share')->execute(); $this->dbConn->getQueryBuilder()->delete('filecache')->execute(); $this->dbConn->getQueryBuilder()->delete('storages')->execute(); @@ -143,10 +143,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); } @@ -835,10 +835,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'); } @@ -1538,11 +1538,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([ @@ -1583,11 +1583,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([ @@ -1674,11 +1674,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([ @@ -1717,11 +1717,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([ diff --git a/tests/lib/Share20/LegacyHooksTest.php b/tests/lib/Share20/LegacyHooksTest.php index d761d011794..14fe32323c1 100644 --- a/tests/lib/Share20/LegacyHooksTest.php +++ b/tests/lib/Share20/LegacyHooksTest.php @@ -42,7 +42,7 @@ class LegacyHooksTest extends TestCase { /** @var Manager */ private $manager; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->eventDispatcher = new EventDispatcher(); diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index a7e2ef7d604..c4cc335dd5e 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -101,7 +101,7 @@ class ManagerTest extends \Test\TestCase { /** @var \OC_Defaults|MockObject */ protected $defaults; - public function setUp(): void { + protected function setUp(): void { $this->logger = $this->createMock(ILogger::class); $this->config = $this->createMock(IConfig::class); @@ -172,10 +172,10 @@ class ManagerTest extends \Test\TestCase { ]); } - /** - * @expectedException \InvalidArgumentException - */ + public function testDeleteNoShareId() { + $this->expectException(\InvalidArgumentException::class); + $share = $this->manager->newShare(); $this->manager->deleteShare($share); @@ -445,10 +445,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(); @@ -472,11 +472,11 @@ class ManagerTest extends \Test\TestCase { $manager->getShareById('default:42'); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Passwords are enforced for link shares - */ + public function testVerifyPasswordNullButEnforced() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Passwords are enforced for link shares'); + $this->config->method('getAppValue')->will($this->returnValueMap([ ['core', 'shareapi_enforce_links_password', 'no', 'yes'], ])); @@ -510,11 +510,11 @@ class ManagerTest extends \Test\TestCase { $this->assertNull($result); } - /** - * @expectedException \Exception - * @expectedExceptionMessage password not accepted - */ + public function testVerifyPasswordHookFails() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('password not accepted'); + $this->config->method('getAppValue')->will($this->returnValueMap([ ['core', 'shareapi_enforce_links_password', 'no', 'no'], ])); @@ -719,11 +719,11 @@ 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([ @@ -745,11 +745,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(); @@ -761,11 +761,11 @@ 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'); @@ -950,11 +950,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); @@ -988,11 +988,11 @@ class ManagerTest extends \Test\TestCase { $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); @@ -1061,11 +1061,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(); @@ -1086,11 +1086,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() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Path is already shared with this user'); + $share = $this->manager->newShare(); $sharedWith = $this->createMock(IUser::class); @@ -1197,11 +1197,11 @@ 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 @@ -1213,11 +1213,11 @@ class ManagerTest extends \Test\TestCase { 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); @@ -1239,11 +1239,11 @@ class ManagerTest extends \Test\TestCase { 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); @@ -1292,11 +1292,11 @@ class ManagerTest extends \Test\TestCase { $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); @@ -1348,11 +1348,11 @@ class ManagerTest extends \Test\TestCase { $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 @@ -1364,11 +1364,11 @@ class ManagerTest extends \Test\TestCase { 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); @@ -1382,11 +1382,11 @@ class ManagerTest extends \Test\TestCase { 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); @@ -1433,11 +1433,11 @@ class ManagerTest extends \Test\TestCase { $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'); @@ -1924,11 +1924,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', @@ -2311,11 +2311,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') @@ -2370,10 +2370,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') @@ -2466,11 +2466,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', @@ -2492,11 +2492,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', @@ -2520,11 +2520,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', @@ -2889,11 +2889,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', @@ -2961,11 +2961,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', @@ -3033,11 +3033,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', @@ -3105,11 +3105,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', @@ -3247,11 +3247,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); @@ -3260,11 +3260,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); @@ -3287,11 +3287,11 @@ class ManagerTest extends \Test\TestCase { $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); @@ -3307,11 +3307,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'); diff --git a/tests/lib/Share20/ShareHelperTest.php b/tests/lib/Share20/ShareHelperTest.php index 2562f16e2a4..d2f5cd79284 100644 --- a/tests/lib/Share20/ShareHelperTest.php +++ b/tests/lib/Share20/ShareHelperTest.php @@ -37,7 +37,7 @@ class ShareHelperTest extends TestCase { /** @var ShareHelper */ private $helper; - public function setUp(): void { + 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 45975d5996c..f7ea479350d 100644 --- a/tests/lib/Share20/ShareTest.php +++ b/tests/lib/Share20/ShareTest.php @@ -36,17 +36,17 @@ class ShareTest extends \Test\TestCase { /** @var \OCP\Share\IShare */ protected $share; - public function setUp(): void { + 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); } @@ -61,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); } @@ -85,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'); } |