diff options
author | Olivier Paroz <github@oparoz.com> | 2016-06-12 15:21:43 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2016-06-12 15:21:43 +0300 |
commit | 4eace9b6a9becd28dcf230b08117d84a46ebec2d (patch) | |
tree | 4979e56cbe0a2f8d73735844477e96bff8b1d247 /tests | |
parent | f8438cc5feea03bcfabb268a6a04fbfc3a18ceb8 (diff) |
Rename getResourceFromId to GetFile
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/GalleryUnitTest.php | 29 | ||||
-rw-r--r-- | tests/unit/controller/FilesApiControllerTest.php | 2 | ||||
-rw-r--r-- | tests/unit/controller/FilesControllerTest.php | 4 | ||||
-rw-r--r-- | tests/unit/controller/PreviewControllerTest.php | 12 | ||||
-rw-r--r-- | tests/unit/service/DownloadServiceTest.php | 2 | ||||
-rw-r--r-- | tests/unit/service/SearchMediaServiceTest.php | 36 |
6 files changed, 57 insertions, 28 deletions
diff --git a/tests/unit/GalleryUnitTest.php b/tests/unit/GalleryUnitTest.php index eb2ae110..a87b9ae4 100644 --- a/tests/unit/GalleryUnitTest.php +++ b/tests/unit/GalleryUnitTest.php @@ -48,7 +48,7 @@ abstract class GalleryUnitTest extends \Test\TestCase { } /** - * Mocks Object->getResourceFromId + * Mocks Object->getFile * * Needs to pass a mock of a File or Folder * @@ -56,15 +56,15 @@ abstract class GalleryUnitTest extends \Test\TestCase { * @param int $fileId * @param File|Folder $answer */ - protected function mockGetResourceFromId($mockedObject, $fileId, $answer) { + protected function mockGetFile($mockedObject, $fileId, $answer) { $mockedObject->expects($this->once()) - ->method('getResourceFromId') + ->method('getFile') ->with($this->equalTo($fileId)) ->willReturn($answer); } /** - * Mocks Object->getResourceFromId with a bad Id + * Mocks Object->getFile with a bad Id * * Needs to pass a mock of a File or Folder * @@ -72,9 +72,9 @@ abstract class GalleryUnitTest extends \Test\TestCase { * @param int $fileId * @param \Exception $exception */ - protected function mockGetResourceFromIdWithBadFile($mockedObject, $fileId, $exception) { + protected function mockGetFileWithBadFile($mockedObject, $fileId, $exception) { $mockedObject->expects($this->once()) - ->method('getResourceFromId') + ->method('getFile') ->with($this->equalTo($fileId)) ->willThrowException($exception); } @@ -284,7 +284,7 @@ abstract class GalleryUnitTest extends \Test\TestCase { $folder->method('getEtag') ->willReturn($etag); $folder->method('getSize') - ->willReturn($size); + ->willReturn($size); $folder->method('getPath') ->willReturn($path); $folder->method('getFreeSpace') @@ -325,19 +325,22 @@ abstract class GalleryUnitTest extends \Test\TestCase { protected function mockGetFileNodeFromVirtualRoot($location, $file) { $this->environment->expects($this->any()) ->method('getNodeFromVirtualRoot') - ->with( - $location - ) + ->with($location) ->willReturn($file); } protected function mockGetPathFromVirtualRoot($node, $path) { $this->environment->expects($this->any()) ->method('getPathFromVirtualRoot') - ->with( - $node - ) + ->with($node) ->willReturn($path); } + protected function mockGetResourceFromId($nodeId, $node) { + $this->environment->expects($this->any()) + ->method('getResourceFromId') + ->with($nodeId) + ->willReturn($node); + } + } diff --git a/tests/unit/controller/FilesApiControllerTest.php b/tests/unit/controller/FilesApiControllerTest.php index c4a7a00c..8ed97de2 100644 --- a/tests/unit/controller/FilesApiControllerTest.php +++ b/tests/unit/controller/FilesApiControllerTest.php @@ -46,7 +46,7 @@ class FilesApiControllerTest extends FilesControllerTest { $status = Http::STATUS_NOT_FOUND; $exception = new NotFoundServiceException('Not found'); - $this->mockGetResourceFromIdWithBadFile($this->downloadService, $fileId, $exception); + $this->mockGetFileWithBadFile($this->downloadService, $fileId, $exception); $redirectUrl = '/index.php/app/error'; $this->mockUrlToErrorPage($status, $redirectUrl); diff --git a/tests/unit/controller/FilesControllerTest.php b/tests/unit/controller/FilesControllerTest.php index 7faeb95f..63a4eb6e 100644 --- a/tests/unit/controller/FilesControllerTest.php +++ b/tests/unit/controller/FilesControllerTest.php @@ -144,7 +144,7 @@ class FilesControllerTest extends \Test\GalleryUnitTest { $status = Http::STATUS_NOT_FOUND; $exception = new NotFoundServiceException('Not found'); - $this->mockGetResourceFromIdWithBadFile($this->downloadService, $fileId, $exception); + $this->mockGetFileWithBadFile($this->downloadService, $fileId, $exception); $redirectUrl = '/index.php/app/error'; $this->mockUrlToErrorPage($status, $redirectUrl); @@ -331,7 +331,7 @@ class FilesControllerTest extends \Test\GalleryUnitTest { * @return array */ private function mockGetDownload($fileId, $file, $filename) { - $this->mockGetResourceFromId($this->downloadService, $fileId, $file); + $this->mockGetFile($this->downloadService, $fileId, $file); $download = $this->mockDownloadData($file, $filename); diff --git a/tests/unit/controller/PreviewControllerTest.php b/tests/unit/controller/PreviewControllerTest.php index bc347265..d716e780 100644 --- a/tests/unit/controller/PreviewControllerTest.php +++ b/tests/unit/controller/PreviewControllerTest.php @@ -118,7 +118,7 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { $thumbnailId = 1234; $file = $this->mockJpgFile($thumbnailId); - $this->mockGetResourceFromId($this->previewService, $thumbnailId, $file); + $this->mockGetFile($this->previewService, $thumbnailId, $file); $this->controller->getThumbnails($thumbnailId, $square, $scale); } @@ -251,7 +251,7 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { $height = 768; $exception = new NotFoundServiceException('Not found'); - $this->mockGetResourceFromIdWithBadFile($this->previewService, $fileId, $exception); + $this->mockGetFileWithBadFile($this->previewService, $fileId, $exception); $errorResponse = $this->jsonErrorMessage(Http::STATUS_NOT_FOUND); @@ -296,7 +296,7 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { $fileId, $file, $width, $height, $keepAspect = true, $animatedPreview = true, $base64Encode = false, $previewRequired = true ) { - $this->mockGetResourceFromId($this->previewService, $fileId, $file); + $this->mockGetFile($this->previewService, $fileId, $file); $this->mockIsPreviewRequired($file, $animatedPreview, $previewRequired); $previewData = $this->mockPreviewData($file, $previewRequired); @@ -329,7 +329,7 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { $fileId, $file, $width, $height, $keepAspect = true, $animatedPreview = true, $base64Encode = false ) { - $this->mockGetResourceFromId($this->previewService, $fileId, $file); + $this->mockGetFile($this->previewService, $fileId, $file); $this->mockIsPreviewRequired($file, $animatedPreview, true); @@ -353,7 +353,7 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { $fileId, $file, $width, $height, $keepAspect = true, $animatedPreview = true, $base64Encode = false ) { - $this->mockGetResourceFromId($this->previewService, $fileId, $file); + $this->mockGetFile($this->previewService, $fileId, $file); $this->mockIsPreviewRequired($file, $animatedPreview, true); @@ -368,7 +368,7 @@ class PreviewControllerTest extends \Test\GalleryUnitTest { */ private function mockGetDataWithBrokenSetup($fileId, $animatedPreview) { $file = $this->mockJpgFile($fileId); - $this->mockGetResourceFromId($this->previewService, $fileId, $file); + $this->mockGetFile($this->previewService, $fileId, $file); $this->mockIsPreviewRequiredThrowsException($file, $animatedPreview); diff --git a/tests/unit/service/DownloadServiceTest.php b/tests/unit/service/DownloadServiceTest.php index d2c21178..8fadfe69 100644 --- a/tests/unit/service/DownloadServiceTest.php +++ b/tests/unit/service/DownloadServiceTest.php @@ -73,7 +73,7 @@ class DownloadServiceTest extends \Test\GalleryUnitTest { * @expectedException \OCA\Gallery\Service\NotFoundServiceException */ public function testDownloadNonExistentFile() { - $file = $this->mockBadFile(12345); + $file = $this->mockBadFile(); $this->service->downloadFile($file); } diff --git a/tests/unit/service/SearchMediaServiceTest.php b/tests/unit/service/SearchMediaServiceTest.php index b6a2a082..91eb642c 100644 --- a/tests/unit/service/SearchMediaServiceTest.php +++ b/tests/unit/service/SearchMediaServiceTest.php @@ -487,17 +487,43 @@ class SearchMediaServiceTest extends \Test\GalleryUnitTest { $this->assertSame($result, $response); } + public function testGetFile() { + $fileId = 99999; + $storageId = 'home::user'; + $file = $this->mockJpgFile($fileId, $storageId); + + $this->mockGetResourceFromId($fileId, $file); + + $response = $this->service->getFile($fileId); + + $this->assertSame($file, $response); + } + + /** + * @expectedException \OCA\Gallery\Service\NotFoundServiceException + */ + public function testGetFileWithBadMediaType() { + $fileId = 99999; + $storageId = 'home::user'; + $file = $this->mockFile($fileId, $storageId); + + $this->mockGetResourceFromId($fileId, $file); + + $this->service->getFile($fileId); + } + /** * @expectedException \OCA\Gallery\Service\NotFoundServiceException */ - public function testGetResourceFromIdWithUnreadableFile() { + public function testGetFileWithFolderId() { $fileId = 99999; $storageId = 'home::user'; - $isReadable = false; - $file = $this->mockFile($fileId, $storageId, $isReadable); - $this->mockGetResourceFromId($this->environment, $fileId, $file); + $file = $this->mockJpgFile($fileId, $storageId); + $folder = $this->mockFolder($storageId, $fileId, [$file]); + + $this->mockGetResourceFromId($fileId, $folder); - $this->service->getResourceFromId($fileId); + $this->service->getFile($fileId); } /** |