Example #1
0
 public function testMoveSrcDeletable()
 {
     $fileInfoFolderATestTXT = $this->getMockBuilder('\\OCP\\Files\\FileInfo')->disableOriginalConstructor()->getMock();
     $fileInfoFolderATestTXT->expects($this->once())->method('isDeletable')->willReturn(true);
     $this->view->expects($this->once())->method('getFileInfo')->with('FolderA/test.txt')->willReturn($fileInfoFolderATestTXT);
     $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
 }
Example #2
0
 /**
  * @dataProvider dataGetPreview
  *
  * @param string $author
  * @param int $fileId
  * @param string $path
  * @param string $returnedPath
  * @param bool $isDir
  * @param bool $isMimeSup
  * @param string $source
  * @param bool $isMimeTypeIcon
  */
 public function testGetPreview($author, $fileId, $path, $returnedPath, $isDir, $isMimeSup, $source, $isMimeTypeIcon)
 {
     $controller = $this->getController(['getPreviewLink', 'getPreviewPathFromMimeType']);
     $this->infoCache->expects($this->once())->method('getInfoById')->with($author, $fileId, $path)->willReturn(['path' => $returnedPath, 'exists' => true, 'is_dir' => $isDir, 'view' => '']);
     $controller->expects($this->once())->method('getPreviewLink')->with($returnedPath, $isDir)->willReturnCallback(function ($path) {
         return '/preview' . $path;
     });
     if ($isDir) {
         $controller->expects($this->once())->method('getPreviewPathFromMimeType')->with('dir')->willReturn('/preview/dir');
     } else {
         $fileInfo = $this->getMockBuilder('OCP\\Files\\FileInfo')->disableOriginalConstructor()->getMock();
         $this->view->expects($this->once())->method('chroot')->with('/' . $author . '/files');
         $this->view->expects($this->once())->method('getFileInfo')->with($returnedPath)->willReturn($fileInfo);
         $this->preview->expects($this->once())->method('isAvailable')->with($fileInfo)->willReturn($isMimeSup);
         if (!$isMimeSup) {
             $fileInfo->expects($this->once())->method('getMimetype')->willReturn('audio/mp3');
             $controller->expects($this->once())->method('getPreviewPathFromMimeType')->with('audio/mp3')->willReturn('/preview/mpeg');
         } else {
             $this->urlGenerator->expects($this->once())->method('linkToRoute')->with('core_ajax_preview', $this->anything())->willReturnCallback(function () use($returnedPath) {
                 return '/preview' . $returnedPath;
             });
         }
     }
     $this->assertSame(['link' => '/preview' . $returnedPath, 'source' => $source, 'isMimeTypeIcon' => $isMimeTypeIcon], $this->invokePrivate($controller, 'getPreview', [$author, $fileId, $path]));
 }
Example #3
0
 public function testRecoverUserFiles()
 {
     $this->viewMock->expects($this->once())->method('getDirectoryContent')->willReturn([]);
     $this->cryptMock->expects($this->once())->method('decryptPrivateKey');
     $this->instance->recoverUsersFiles('password', 'admin');
     $this->assertTrue(true);
 }
 /**
  * @dataProvider dataShareNotificationForSharer
  * @param string $path
  */
 public function testShareNotificationForSharer($path)
 {
     $filesHooks = $this->getFilesHooks(['addNotificationsForUser']);
     $this->view->expects($this->once())->method('getPath')->willReturn($path);
     $this->settings->expects($path !== null ? $this->exactly(3) : $this->never())->method('getUserSetting')->willReturnMap([['user', 'stream', Files_Sharing::TYPE_SHARED, true], ['user', 'email', Files_Sharing::TYPE_SHARED, true], ['user', 'setting', 'batchtime', 21]]);
     $filesHooks->expects($path !== null ? $this->once() : $this->never())->method('addNotificationsForUser')->with('user', 'subject', ['/path', 'target'], 42, '/path', true, true, 21);
     $this->invokePrivate($filesHooks, 'shareNotificationForSharer', ['subject', 'target', 42, 'file']);
 }
Example #5
0
 public function testGetStorage()
 {
     $return = $this->getMockBuilder('OC\\Files\\Storage\\Storage')->disableOriginalConstructor()->getMock();
     $path = '/foo/bar.txt';
     $this->filesMock->expects($this->once())->method('getMount')->with($path)->willReturn($this->mountMock);
     $this->mountMock->expects($this->once())->method('getStorage')->willReturn($return);
     $this->assertEquals($return, $this->instance->getStorage($path));
 }
 /**
  * @dataProvider dataFindInfoById
  *
  * @param string $user
  * @param int $fileId
  * @param string $filename
  * @param string|null $path
  * @param string|null $pathTrash
  * @param string $isDirPath
  * @param bool $isDir
  * @param string $expected
  * @param array $expectedCache
  */
 public function testFindInfoById($user, $fileId, $filename, $path, $pathTrash, $isDirPath, $isDir, $expected, array $expectedCache)
 {
     $this->view->expects($this->at(0))->method('chroot')->with('/' . $user . '/files');
     if ($path === null) {
         $this->view->expects($this->at(1))->method('getPath')->with($fileId)->willThrowException(new NotFoundException());
         $this->view->expects($this->at(2))->method('chroot')->with('/' . $user . '/files_trashbin');
         if ($pathTrash === null) {
             $this->view->expects($this->at(3))->method('getPath')->with($fileId)->willThrowException(new NotFoundException());
         } else {
             $this->view->expects($this->at(3))->method('getPath')->with($fileId)->willReturn($pathTrash);
         }
     } else {
         $this->view->expects($this->at(1))->method('getPath')->with($fileId)->willReturn($path);
     }
     $this->view->expects($path === null && $pathTrash === null ? $this->never() : $this->once())->method('is_dir')->with($isDirPath)->willReturn($isDir);
     $infoCache = $this->getCache();
     $this->assertSame($expected, $this->invokePrivate($infoCache, 'findInfoById', [$user, $fileId, $filename]));
     $this->assertSame($expectedCache, $this->invokePrivate($infoCache, 'cacheId'));
 }
Example #7
0
 /**
  * @expectedException \Sabre\DAV\Exception\NotFound
  * @expectedExceptionMessage FolderA/test.txt does not exist
  */
 public function testMoveSrcNotExist()
 {
     $this->view->expects($this->once())->method('getFileInfo')->with('FolderA/test.txt')->willReturn(false);
     $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
 }