Beispiel #1
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]));
 }
 /**
  * @dataProvider dataFormat
  *
  * @param string $user
  * @param string $parameter
  * @param bool $isDir
  * @param array $info
  * @param bool $allowHtml
  * @param bool $verbose
  * @param string $expected
  */
 public function testFormat($user, $parameter, $isDir, array $info, $allowHtml, $verbose, $expected)
 {
     /** @var \OCP\Activity\IEvent|\PHPUnit_Framework_MockObject_MockObject $event */
     $event = $this->getMockBuilder('OCP\\Activity\\IEvent')->disableOriginalConstructor()->getMock();
     if (!empty($info)) {
         $event->expects($this->once())->method('getObjectType')->willReturn('files');
         $event->expects($this->once())->method('getObjectName')->willReturn($parameter);
         $event->expects($this->once())->method('getObjectId')->willReturn(42);
     }
     $this->urlGenerator->expects($allowHtml ? $this->once() : $this->never())->method('linkTo')->with('files', 'index.php', $this->anything())->willReturnCallback(function ($app, $file, $parameters) {
         $paramList = [];
         foreach ($parameters as $key => $value) {
             $paramList[] = $key . '=' . urlencode($value);
         }
         return $app . '/' . $file . '?' . implode('&', $paramList);
     });
     $formatter = $this->getFormatter(['fixLegacyFilename'], $user);
     $formatter->expects($this->once())->method('fixLegacyFilename')->willReturnArgument(0);
     if (!empty($info)) {
         $this->infoCache->expects($this->once())->method('getInfoById')->with($user, 42, $parameter)->willReturn($info);
     } else {
         $this->infoCache->expects($this->once())->method('getInfoByPath')->with($user, $parameter)->willReturn(['path' => $parameter, 'is_dir' => $isDir, 'exists' => true, 'view' => '']);
     }
     $this->assertSame($expected, $formatter->format($event, $parameter, $allowHtml, $verbose));
 }