From c268ad15972e728dea0465f7332067a63c5bd678 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Thu, 9 Jun 2016 18:29:13 +0200 Subject: Add PHP unit test --- .../tests/Controllers/ShareControllerTest.php | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'apps/files_sharing') 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); + } + } -- cgit v1.2.3