diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-27 15:27:18 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-27 15:27:18 +0100 |
commit | 3a7cf40aaa678bea1df143d2982d603b7a334eec (patch) | |
tree | 63c1e3ad7f7f401d14411a4d44c523632906afc9 /apps/files_sharing/tests/Controller | |
parent | 0568b012672d650c6b5a49e72c4028dde5463c60 (diff) | |
download | nextcloud-server-3a7cf40aaa678bea1df143d2982d603b7a334eec.tar.gz nextcloud-server-3a7cf40aaa678bea1df143d2982d603b7a334eec.zip |
Mode to modern phpunit
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_sharing/tests/Controller')
6 files changed, 108 insertions, 106 deletions
diff --git a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php index d2237acbd7f..5296a1ad0c3 100644 --- a/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ExternalShareControllerTest.php @@ -43,7 +43,7 @@ class ExternalShareControllerTest extends \Test\TestCase { /** @var IClientService */ private $clientService; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->request = $this->getMockBuilder('\\OCP\\IRequest') ->disableOriginalConstructor()->getMock(); diff --git a/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php b/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php index cbe3872bb67..834796bf431 100644 --- a/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php +++ b/apps/files_sharing/tests/Controller/PublicPreviewControllerTest.php @@ -54,7 +54,7 @@ class PublicPreviewControllerTest extends TestCase { /** @var PublicPreviewController */ private $controller; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->previewManager = $this->createMock(IPreview::class); diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 7a50a752044..ae7fc54599c 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -164,11 +164,11 @@ class ShareAPIControllerTest extends TestCase { return \OC::$server->getShareManager()->newShare(); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Wrong share ID, share doesn't exist - */ + public function testDeleteShareShareNotFound() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Wrong share ID, share doesn\'t exist'); + $this->shareManager ->expects($this->exactly(3)) ->method('getShareById') @@ -212,11 +212,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Could not delete share - */ + public function testDeleteShareLocked() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Could not delete share'); + $node = $this->getMockBuilder(File::class)->getMock(); $share = $this->newShare(); @@ -401,10 +401,11 @@ class ShareAPIControllerTest extends TestCase { /** * You cannot remove a share if you're not * in the group the share is shared with - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Wrong share ID, share doesn't exist */ public function testDeleteSharedWithGroupIDontBelongTo() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Wrong share ID, share doesn\'t exist'); + $node = $this->getMockBuilder(File::class)->getMock(); $share = $this->newShare(); @@ -767,11 +768,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($result, $ocs->getShare($share->getId())->getData()[0]); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Wrong share ID, share doesn't exist - */ + public function testGetShareInvalidNode() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Wrong share ID, share doesn\'t exist'); + $share = \OC::$server->getShareManager()->newShare(); $share->setSharedBy('initiator') ->setSharedWith('recipient') @@ -1533,19 +1534,19 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected, $this->invokePrivate($this->ocs, 'canAccessShare', [$share])); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Please specify a file or folder path - */ + public function testCreateShareNoPath() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Please specify a file or folder path'); + $this->ocs->createShare(); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Wrong path, file/folder doesn't exist - */ + public function testCreateShareInvalidPath() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Wrong path, file/folder doesn\'t exist'); + $userFolder = $this->getMockBuilder(Folder::class)->getMock(); $this->rootFolder->expects($this->once()) ->method('getUserFolder') @@ -1560,11 +1561,11 @@ class ShareAPIControllerTest extends TestCase { $this->ocs->createShare('invalid-path'); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage invalid permissions - */ + public function testCreateShareInvalidPermissions() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('invalid permissions'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); @@ -1587,11 +1588,11 @@ class ShareAPIControllerTest extends TestCase { $this->ocs->createShare('valid-path', 32); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Please specify a valid user - */ + public function testCreateShareUserNoShareWith() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Please specify a valid user'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); @@ -1619,11 +1620,11 @@ class ShareAPIControllerTest extends TestCase { $this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Please specify a valid user - */ + public function testCreateShareUserNoValidShareWith() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Please specify a valid user'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); @@ -1719,11 +1720,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Please specify a valid group - */ + public function testCreateShareGroupNoValidShareWith() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Please specify a valid group'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); $this->shareManager->method('createShare')->will($this->returnArgument(0)); @@ -1828,11 +1829,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Group sharing is disabled by the administrator - */ + public function testCreateShareGroupNotAllowed() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Group sharing is disabled by the administrator'); + $share = $this->newShare(); $this->shareManager->method('newShare')->willReturn($share); @@ -1862,11 +1863,11 @@ class ShareAPIControllerTest extends TestCase { $this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_GROUP, 'invalidGroup'); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Public link sharing is disabled by the administrator - */ + public function testCreateShareLinkNoLinksAllowed() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Public link sharing is disabled by the administrator'); + $this->request ->method('getParam') ->will($this->returnValueMap([ @@ -1888,11 +1889,11 @@ class ShareAPIControllerTest extends TestCase { $this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSForbiddenException - * @expectedExceptionMessage Public upload disabled by the administrator - */ + public function testCreateShareLinkNoPublicUpload() { + $this->expectException(\OCP\AppFramework\OCS\OCSForbiddenException::class); + $this->expectExceptionMessage('Public upload disabled by the administrator'); + $path = $this->getMockBuilder(Folder::class)->getMock(); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') @@ -1908,11 +1909,11 @@ class ShareAPIControllerTest extends TestCase { $this->ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_LINK, null, 'true'); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Public upload is only possible for publicly shared folders - */ + public function testCreateShareLinkPublicUploadFile() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Public upload is only possible for publicly shared folders'); + $path = $this->getMockBuilder(File::class)->getMock(); $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') @@ -2034,11 +2035,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSForbiddenException - * @expectedExceptionMessage Sharing valid-path sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled - */ + public function testCreateShareLinkSendPasswordByTalkWithTalkDisabled() { + $this->expectException(\OCP\AppFramework\OCS\OCSForbiddenException::class); + $this->expectExceptionMessage('Sharing valid-path sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled'); + $ocs = $this->mockFormatShare(); $path = $this->getMockBuilder(Folder::class)->getMock(); @@ -2109,11 +2110,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Invalid date, date format must be YYYY-MM-DD - */ + public function testCreateShareInvalidExpireDate() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Invalid date, date format must be YYYY-MM-DD'); + $ocs = $this->mockFormatShare(); $path = $this->getMockBuilder(Folder::class)->getMock(); @@ -2210,11 +2211,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSForbiddenException - * @expectedExceptionMessage Sharing valid-path failed because the back end does not support room shares - */ + public function testCreateShareRoomHelperNotAvailable() { + $this->expectException(\OCP\AppFramework\OCS\OCSForbiddenException::class); + $this->expectExceptionMessage('Sharing valid-path failed because the back end does not support room shares'); + $ocs = $this->mockFormatShare(); $share = $this->newShare(); @@ -2251,11 +2252,11 @@ class ShareAPIControllerTest extends TestCase { $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_ROOM, 'recipientRoom'); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Exception thrown by the helper - */ + public function testCreateShareRoomHelperThrowException() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Exception thrown by the helper'); + $ocs = $this->mockFormatShare(); $share = $this->newShare(); @@ -2369,11 +2370,11 @@ class ShareAPIControllerTest extends TestCase { $ocs->createShare('valid-path', \OCP\Constants::PERMISSION_ALL, \OCP\Share::SHARE_TYPE_USER, 'validUser'); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSNotFoundException - * @expectedExceptionMessage Wrong share ID, share doesn't exist - */ + public function testUpdateShareCantAccess() { + $this->expectException(\OCP\AppFramework\OCS\OCSNotFoundException::class); + $this->expectExceptionMessage('Wrong share ID, share doesn\'t exist'); + $node = $this->getMockBuilder(Folder::class)->getMock(); $share = $this->newShare(); $share->setNode($node); @@ -2396,11 +2397,11 @@ class ShareAPIControllerTest extends TestCase { $this->ocs->updateShare(42); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException - * @expectedExceptionMessage Wrong or no update parameter given - */ + public function testUpdateNoParametersLink() { + $this->expectException(\OCP\AppFramework\OCS\OCSBadRequestException::class); + $this->expectExceptionMessage('Wrong or no update parameter given'); + $node = $this->getMockBuilder(Folder::class)->getMock(); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -2417,11 +2418,11 @@ class ShareAPIControllerTest extends TestCase { $this->ocs->updateShare(42); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException - * @expectedExceptionMessage Wrong or no update parameter given - */ + public function testUpdateNoParametersOther() { + $this->expectException(\OCP\AppFramework\OCS\OCSBadRequestException::class); + $this->expectExceptionMessage('Wrong or no update parameter given'); + $node = $this->getMockBuilder(Folder::class)->getMock(); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -2606,11 +2607,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException - * @expectedExceptionMessage Invalid date. Format must be YYYY-MM-DD - */ + public function testUpdateLinkShareInvalidDate() { + $this->expectException(\OCP\AppFramework\OCS\OCSBadRequestException::class); + $this->expectExceptionMessage('Invalid date. Format must be YYYY-MM-DD'); + $ocs = $this->mockFormatShare(); $folder = $this->getMockBuilder(Folder::class)->getMock(); @@ -2645,10 +2646,11 @@ class ShareAPIControllerTest extends TestCase { /** * @dataProvider publicUploadParamsProvider - * @expectedException \OCP\AppFramework\OCS\OCSForbiddenException - * @expectedExceptionMessage Public upload disabled by the administrator */ public function testUpdateLinkSharePublicUploadNotAllowed($permissions, $publicUpload, $expireDate, $password) { + $this->expectException(\OCP\AppFramework\OCS\OCSForbiddenException::class); + $this->expectExceptionMessage('Public upload disabled by the administrator'); + $ocs = $this->mockFormatShare(); $folder = $this->getMockBuilder(Folder::class)->getMock(); @@ -2665,11 +2667,11 @@ class ShareAPIControllerTest extends TestCase { $ocs->updateShare(42, $permissions, $password, null, $publicUpload, $expireDate); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException - * @expectedExceptionMessage Public upload is only possible for publicly shared folders - */ + public function testUpdateLinkSharePublicUploadOnFile() { + $this->expectException(\OCP\AppFramework\OCS\OCSBadRequestException::class); + $this->expectExceptionMessage('Public upload is only possible for publicly shared folders'); + $ocs = $this->mockFormatShare(); $file = $this->getMockBuilder(File::class)->getMock(); @@ -2778,11 +2780,11 @@ class ShareAPIControllerTest extends TestCase { $this->assertEquals($expected->getData(), $result->getData()); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSForbiddenException - * @expectedExceptionMessage Sharing sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled - */ + public function testUpdateLinkShareSendPasswordByTalkWithTalkDisabledDoesNotChangeOther() { + $this->expectException(\OCP\AppFramework\OCS\OCSForbiddenException::class); + $this->expectExceptionMessage('Sharing sending the password by Nextcloud Talk failed because Nextcloud Talk is not enabled'); + $ocs = $this->mockFormatShare(); $date = new \DateTime('2000-01-01'); diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php index ec6fc9a598d..55981f00238 100644 --- a/apps/files_sharing/tests/Controller/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php @@ -532,10 +532,10 @@ class ShareControllerTest extends \Test\TestCase { self::assertEquals($expectedResponse, $response); } - /** - * @expectedException \OCP\Files\NotFoundException - */ + public function testShowShareInvalid() { + $this->expectException(\OCP\Files\NotFoundException::class); + $this->shareController->setToken('token'); $owner = $this->getMockBuilder(IUser::class)->getMock(); diff --git a/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php b/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php index b8d87d5cd68..f2feb6e7fcc 100644 --- a/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareInfoControllerTest.php @@ -45,7 +45,7 @@ class ShareInfoControllerTest extends TestCase { private $shareManager; - public function setUp(): void { + protected function setUp(): void { parent::setUp(); $this->shareManager = $this->createMock(ShareManager::class); diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php index 20790fc0bfa..99f86525913 100644 --- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php @@ -397,11 +397,11 @@ class ShareesAPIControllerTest extends TestCase { $this->assertSame($expected, $this->invokePrivate($this->sharees, 'isRemoteSharingAllowed', [$itemType])); } - /** - * @expectedException \OCP\AppFramework\OCS\OCSBadRequestException - * @expectedExceptionMessage Missing itemType - */ + public function testSearchNoItemType() { + $this->expectException(\OCP\AppFramework\OCS\OCSBadRequestException::class); + $this->expectExceptionMessage('Missing itemType'); + $this->sharees->search('', null, 1, 10, [], false); } |