Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-09-07 16:58:26 +0300
committerOlivier Paroz <github@oparoz.com>2015-09-07 16:58:26 +0300
commit69a2cf1cf980bb0f488ee126d1c7005bbac420fd (patch)
tree94b180380bfac622f8c1940a0db906f1cc56b3d4 /tests/unit
parent739d503730f08c979fa10b46a93e5e8b6fb7aed4 (diff)
New test cases for FilesService
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/GalleryUnitTest.php19
-rw-r--r--tests/unit/service/SearchFolderServiceTest.php65
-rw-r--r--tests/unit/service/SearchMediaServiceTest.php23
3 files changed, 90 insertions, 17 deletions
diff --git a/tests/unit/GalleryUnitTest.php b/tests/unit/GalleryUnitTest.php
index 8f0545ab..6595a1f4 100644
--- a/tests/unit/GalleryUnitTest.php
+++ b/tests/unit/GalleryUnitTest.php
@@ -132,6 +132,13 @@ abstract class GalleryUnitTest extends \Test\TestCase {
return $file;
}
+ protected function mockNoMediaFile($fileId) {
+ $file = $this->mockFile($fileId);
+ $this->mockNoMediaFileMethods($file);
+
+ return $file;
+ }
+
private function mockJpgFileMethods($file) {
$filename = 'testimage.jpg';
$file->method('getContent')
@@ -171,6 +178,18 @@ abstract class GalleryUnitTest extends \Test\TestCase {
return $file;
}
+ private function mockNoMediaFileMethods($file) {
+ $filename = '.nomedia';
+ $file->method('getContent')
+ ->willReturn(file_get_contents(__DIR__ . '/../_data/' . $filename));
+ $file->method('getName')
+ ->willReturn($filename);
+ $file->method('getMimeType')
+ ->willReturn('image/jpeg');
+
+ return $file;
+ }
+
protected function mockBadFile() {
$exception = new ServiceException("Can't read file");
$file = $this->getMockBuilder('OCP\Files\File')
diff --git a/tests/unit/service/SearchFolderServiceTest.php b/tests/unit/service/SearchFolderServiceTest.php
index c0aec4c3..dc0a5b06 100644
--- a/tests/unit/service/SearchFolderServiceTest.php
+++ b/tests/unit/service/SearchFolderServiceTest.php
@@ -94,24 +94,23 @@ class SearchFolderServiceTest extends \Test\GalleryUnitTest {
public function providesSendExternalFolderData() {
return [
['shared::99999'],
- ['home::user']
+ ['home::user'] // Throws an exception
];
}
/**
* @dataProvider providesSendExternalFolderData
+ *
+ * @param $storageId
*/
public function testSendExternalFolder($storageId) {
$expectedException =
- new \OCA\Gallery\Service\ForbiddenServiceException('Album is private or unavailable');
+ new ForbiddenServiceException('Album is private or unavailable');
$path = '';
$nodeId = 94875;
$files = [];
$shared = $this->mockFolder('shared::12345', $nodeId, $files);
- $rootNodeId = 91919191;
- $rootFiles = [$shared];
- $sharedRoot = $this->mockFolder($storageId, $rootNodeId, $rootFiles);
- $this->mockGetVirtualRootFolderOfSharedFolder($sharedRoot);
+ $this->mockGetVirtualRootFolderOfSharedFolder($storageId, $shared);
$locationHasChanged = false;
$folder = [$path, $shared, $locationHasChanged];
@@ -125,7 +124,7 @@ class SearchFolderServiceTest extends \Test\GalleryUnitTest {
}
public function providesNodesData() {
- $exception = new \OCA\Gallery\Service\NotFoundServiceException('Boom');
+ $exception = new NotFoundServiceException('Boom');
return [
[0, $exception],
@@ -156,7 +155,7 @@ class SearchFolderServiceTest extends \Test\GalleryUnitTest {
public function providesRecoverFromGetNodesData() {
$caughtException = new \Exception('Nasty');
- $newException = new \OCA\Gallery\Service\NotFoundServiceException('Boom');
+ $newException = new NotFoundServiceException('Boom');
return [
[0, $caughtException, $newException],
@@ -168,7 +167,7 @@ class SearchFolderServiceTest extends \Test\GalleryUnitTest {
* @dataProvider providesRecoverFromGetNodesData
*
* @param $subDepth
- * @param $exception
+ * @param $caughtException
* @param $nodes
*/
public function testRecoverFromGetNodesError($subDepth, $caughtException, $nodes) {
@@ -202,7 +201,7 @@ class SearchFolderServiceTest extends \Test\GalleryUnitTest {
$this->assertFalse($response);
}
- public function providesIsPreviewAllowedData() {
+ public function providesIsAllowedAndAvailableWithMountedFolderData() {
return [
// Mounted, so looking at options
[true, true, true],
@@ -214,13 +213,13 @@ class SearchFolderServiceTest extends \Test\GalleryUnitTest {
}
/**
- * @dataProvider providesIsPreviewAllowedData
+ * @dataProvider providesIsAllowedAndAvailableWithMountedFolderData
*
* @param bool $mounted
* @param bool $previewsAllowedOnMountedShare
* @param bool $expectedResult
*/
- public function testIsAllowedWithMountedFolder(
+ public function testIsAllowedAndAvailableWithMountedFolder(
$mounted, $previewsAllowedOnMountedShare, $expectedResult
) {
$nodeId = 12345;
@@ -231,7 +230,40 @@ class SearchFolderServiceTest extends \Test\GalleryUnitTest {
'webdav::user@domain.com/dav', $nodeId, $files, $isReadable, $mounted, $mount
);
- $response = self::invokePrivate($this->service, 'isAllowed', [$node]);
+ $response = self::invokePrivate($this->service, 'isAllowedAndAvailable', [$node]);
+
+ $this->assertSame($expectedResult, $response);
+ }
+
+ public function providesIsAllowedAndAvailableData() {
+ return [
+ ['shared::99999', false, true],
+ ['shared::99999', true, true],
+ ['home::user', false, false],
+ ['home::user', true, true],
+ ];
+ }
+
+ /**
+ * @dataProvider providesIsAllowedAndAvailableData
+ *
+ * @param string $rootStorageId
+ * @param bool $externalSharesAllowed
+ * @param bool $expectedResult
+ */
+ public function testIsAllowedAndAvailable(
+ $rootStorageId, $externalSharesAllowed, $expectedResult
+ ) {
+ $nodeId = 12345;
+ $files = [];
+ $isReadable = true;
+ $shared = $this->mockFolder('shared::99999', $nodeId, $files, $isReadable);
+ $this->mockGetVirtualRootFolderOfSharedFolder($rootStorageId, $shared);
+
+ $features = $externalSharesAllowed ? ['external_shares'] : [];
+ self::invokePrivate($this->service, 'features', [$features]);
+
+ $response = self::invokePrivate($this->service, 'isAllowedAndAvailable', [$shared]);
$this->assertSame($expectedResult, $response);
}
@@ -304,10 +336,13 @@ class SearchFolderServiceTest extends \Test\GalleryUnitTest {
return $folder;
}
- private function mockGetVirtualRootFolderOfSharedFolder($folder) {
+ private function mockGetVirtualRootFolderOfSharedFolder($storageId, $shared) {
+ $rootNodeId = 91919191;
+ $rootFiles = [$shared];
+ $sharedRoot = $this->mockFolder($storageId, $rootNodeId, $rootFiles);
$this->environment->expects($this->once())
->method('getVirtualRootFolder')
- ->willReturn($folder);
+ ->willReturn($sharedRoot);
}
diff --git a/tests/unit/service/SearchMediaServiceTest.php b/tests/unit/service/SearchMediaServiceTest.php
index 4f7a786e..ad2c6516 100644
--- a/tests/unit/service/SearchMediaServiceTest.php
+++ b/tests/unit/service/SearchMediaServiceTest.php
@@ -84,6 +84,13 @@ class SearchMediaServiceTest extends \Test\GalleryUnitTest {
'home::user', 10101, [$folder1, $folder2], $isReadable, $mounted, $mount, $query,
$queryResult
);
+ $folder5 = $this->mockFolder(
+ 'home::user', 987234, [
+ $this->mockJpgFile(998877),
+ $this->mockJpgFile(998876),
+ $this->mockNoMediaFile(998875)
+ ], $isReadable, $mounted, $mount, '.nomedia', true
+ );
// 2 folders and 3 files, everything is reachable
$config1 = [
@@ -94,7 +101,7 @@ class SearchMediaServiceTest extends \Test\GalleryUnitTest {
$this->mockJpgFile(99999)
];
- // 2 deepfolder and 3 files. Should return the all the files
+ // 2 deepfolder and 3 files. Should return all the files
$config2 = [
$folder3,
$folder3,
@@ -110,6 +117,14 @@ class SearchMediaServiceTest extends \Test\GalleryUnitTest {
$this->mockJpgFile(88888),
$this->mockJpgFile(99999)
];
+ // 1 blacklisted folder and 3 files
+ $config4 = [
+ $folder5,
+ $this->mockJpgFile(77777),
+ $this->mockJpgFile(88888),
+ $this->mockJpgFile(99999)
+
+ ];
$topFolder1 = $this->mockFolder(
'home::user', 909090, $config1, $isReadable, $mounted, $mount, $query, $queryResult
);
@@ -119,11 +134,15 @@ class SearchMediaServiceTest extends \Test\GalleryUnitTest {
$topFolder3 = $this->mockFolder(
'home::user', 909090, $config3, $isReadable, $mounted, $mount, $query, $queryResult
);
+ $topFolder4 = $this->mockFolder(
+ 'home::user', 909090, $config4, $isReadable, $mounted, $mount, $query, $queryResult
+ );
return [
[$topFolder1, 9],
[$topFolder2, 9],
- [$topFolder3, 6]
+ [$topFolder3, 6],
+ [$topFolder4, 3]
];
}