/** * @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])); }
public function testGetThumbnail() { $this->preview->expects($this->once())->method('createPreview')->with('files/known.jpg', 10, 10, true)->willReturn(new Image(\OC::$SERVERROOT . '/tests/data/testimage.jpg')); $ret = $this->apiController->getThumbnail(10, 10, 'known.jpg'); $this->assertEquals(Http::STATUS_OK, $ret->getStatus()); }