diff options
author | Lukas Reschke <lukas@owncloud.com> | 2016-06-09 18:29:13 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2016-06-09 18:29:13 +0200 |
commit | c268ad15972e728dea0465f7332067a63c5bd678 (patch) | |
tree | 18793f5e11c30751b6d34c20255b3f575de77cc2 /apps/files_sharing | |
parent | 0b00a06a0daabc50d3fc7f64d31b793ef8afb272 (diff) | |
download | nextcloud-server-c268ad15972e728dea0465f7332067a63c5bd678.tar.gz nextcloud-server-c268ad15972e728dea0465f7332067a63c5bd678.zip |
Add PHP unit test
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/tests/Controllers/ShareControllerTest.php | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/apps/files_sharing/tests/Controllers/ShareControllerTest.php b/apps/files_sharing/tests/Controllers/ShareControllerTest.php index b1c6daaf64a..0c35449fb1a 100644 --- a/apps/files_sharing/tests/Controllers/ShareControllerTest.php +++ b/apps/files_sharing/tests/Controllers/ShareControllerTest.php @@ -32,6 +32,7 @@ namespace OCA\Files_Sharing\Tests\Controllers; use OC\Files\Filesystem; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Files_Sharing\Controllers\ShareController; +use OCP\AppFramework\Http\DataResponse; use OCP\Share\Exceptions\ShareNotFound; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\RedirectResponse; @@ -432,10 +433,13 @@ class ShareControllerTest extends \Test\TestCase { $this->shareController->showShare('token'); } - public function testDownloadShare() { $share = $this->getMock('\OCP\Share\IShare'); $share->method('getPassword')->willReturn('password'); + $share + ->expects($this->once()) + ->method('getPermissions') + ->willReturn(\OCP\Constants::PERMISSION_READ); $this->shareManager ->expects($this->once()) @@ -454,4 +458,24 @@ class ShareControllerTest extends \Test\TestCase { $this->assertEquals($expectedResponse, $response); } + public function testDownloadShareWithCreateOnlyShare() { + $share = $this->getMock('\OCP\Share\IShare'); + $share->method('getPassword')->willReturn('password'); + $share + ->expects($this->once()) + ->method('getPermissions') + ->willReturn(\OCP\Constants::PERMISSION_CREATE); + + $this->shareManager + ->expects($this->once()) + ->method('getShareByToken') + ->with('validtoken') + ->willReturn($share); + + // Test with a password protected share and no authentication + $response = $this->shareController->downloadShare('validtoken'); + $expectedResponse = new DataResponse('Share is read-only'); + $this->assertEquals($expectedResponse, $response); + } + } |