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-08-24 16:07:58 +0300
committerOlivier Paroz <github@oparoz.com>2015-08-24 16:07:58 +0300
commita374898ddb513a1912579b2ceedf77b46e074f30 (patch)
tree09b01afda3e6f98b186c3114a5d798ef237a03a6 /tests/unit
parentf03eb6949070659ebd64b3f304ca2fa35c4f25c1 (diff)
Some additional files service test
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/service/FilesServiceTest.php8
-rw-r--r--tests/unit/service/SearchFolderServiceTest.php76
-rw-r--r--tests/unit/service/SearchMediaServiceTest.php13
3 files changed, 95 insertions, 2 deletions
diff --git a/tests/unit/service/FilesServiceTest.php b/tests/unit/service/FilesServiceTest.php
index d615dd54..18bbe6c7 100644
--- a/tests/unit/service/FilesServiceTest.php
+++ b/tests/unit/service/FilesServiceTest.php
@@ -31,7 +31,9 @@ abstract class FilesServiceTest extends ServiceTest {
*
* @return object|\PHPUnit_Framework_MockObject_MockObject
*/
- protected function mockFile($fileId, $storageId = 'home::user', $isReadable = true) {
+ protected function mockFile($fileId, $storageId = 'home::user', $isReadable = true, $path = ''
+ ) {
+ $filename = 'testimage.jpg';
$storage = $this->mockGetStorage($storageId);
$file = $this->getMockBuilder('OCP\Files\File')
->disableOriginalConstructor()
@@ -41,7 +43,7 @@ abstract class FilesServiceTest extends ServiceTest {
$file->method('getType')
->willReturn('file');
$file->method('getContent')
- ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
+ ->willReturn(file_get_contents(\OC::$SERVERROOT . '/tests/data/' . $filename));
$file->method('getName')
->willReturn('testimage.jpg');
$file->method('getMimeType')
@@ -50,6 +52,8 @@ abstract class FilesServiceTest extends ServiceTest {
->willReturn($storage);
$file->method('isReadable')
->willReturn($isReadable);
+ $file->method('getPath')
+ ->willReturn($path);
return $file;
}
diff --git a/tests/unit/service/SearchFolderServiceTest.php b/tests/unit/service/SearchFolderServiceTest.php
index c60e6493..26ba6c5b 100644
--- a/tests/unit/service/SearchFolderServiceTest.php
+++ b/tests/unit/service/SearchFolderServiceTest.php
@@ -172,6 +172,64 @@ class SearchFolderServiceTest extends FilesServiceTest {
$this->assertSame($expectedResult, $response);
}
+ public function providesLocationChangeData() {
+ return [
+ [0, false],
+ [1, true],
+ ];
+ }
+
+ /**
+ * @dataProvider providesLocationChangeData
+ *
+ * @param int $depth
+ * @param bool $expectedResult
+ */
+ public function testHasLocationChanged($depth, $expectedResult) {
+ $response = self::invokePrivate($this->service, 'hasLocationChanged', [$depth]);
+
+ $this->assertSame($expectedResult, $response);
+ }
+
+ public function providesValidateLocationData() {
+ return [
+ ['folder1', 0, 'folder1'],
+ ['completely/bogus/set/of/folders/I/give/up', 4, ''],
+ ];
+ }
+
+ /**
+ * @dataProvider providesValidateLocationData
+ *
+ * @param string $location
+ * @param int $depth
+ * @param bool $expectedResult
+ */
+ public function testValidateLocation($location, $depth, $expectedResult) {
+ $response = self::invokePrivate($this->service, 'validateLocation', [$location, $depth]);
+
+ $this->assertSame($expectedResult, $response);
+ }
+
+ public function testFindFolderWithFileLocation() {
+ $location = 'folder/file1.jpg';
+ $fileId = 99999;
+ $file = $this->mockFile($fileId);
+ $folder = $this->mockGetFolder('home::user', 10101, [$file]);
+ $file->method('getParent')
+ ->willReturn($folder);
+
+ $this->mockGetFileNodeFromVirtualRoot($location, $file);
+ $this->mockgetPathFromVirtualRoot($folder, $location);
+
+ $locationHasChanged = false;
+ $expectedResult = [$location, $folder, $locationHasChanged];
+
+ $response = self::invokePrivate($this->service, 'findFolder', [$location]);
+
+ $this->assertSame($expectedResult, $response);
+ }
+
private function mockBrokenDirectoryListing() {
$folder = $this->getMockBuilder('OCP\Files\Folder')
->disableOriginalConstructor()
@@ -203,4 +261,22 @@ class SearchFolderServiceTest extends FilesServiceTest {
return $mountPoint;
}
+ private function mockGetFileNodeFromVirtualRoot($location, $file) {
+ $this->environment->expects($this->any())
+ ->method('getNodeFromVirtualRoot')
+ ->with(
+ $location
+ )
+ ->willReturn($file);
+ }
+
+ private function mockgetPathFromVirtualRoot($node, $path) {
+ $this->environment->expects($this->any())
+ ->method('getPathFromVirtualRoot')
+ ->with(
+ $node
+ )
+ ->willReturn($path);
+ }
+
}
diff --git a/tests/unit/service/SearchMediaServiceTest.php b/tests/unit/service/SearchMediaServiceTest.php
index c5b8db11..2beff115 100644
--- a/tests/unit/service/SearchMediaServiceTest.php
+++ b/tests/unit/service/SearchMediaServiceTest.php
@@ -146,4 +146,17 @@ class SearchMediaServiceTest extends FilesServiceTest {
$this->assertSame($result, sizeof($response));
}
+ /**
+ * @expectedException \OCA\Gallery\Service\NotFoundServiceException
+ */
+ public function testGetResourceFromIdWithUnreadableFile() {
+ $fileId = 99999;
+ $storageId = 'home::user';
+ $isReadable = false;
+ $file = $this->mockFile($fileId, $storageId, $isReadable);
+ $this->mockGetResourceFromId($fileId, $file);
+
+ $this->service->getResourceFromId($fileId);
+ }
+
}